Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Order Wrapper to provide simple order interfaces for developers #110

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

perplover
Copy link
Contributor

Order Wrapper Implementation

Overview

This PR introduces a new Order wrapper class that simplifies the interaction with Hyperliquid's exchange model. It makes it easy to use declarative interfaces to do market/limit/stop/bracket/tpsl orders

Files Changed

  • order.py: New wrapper class implementation
  • tests/test_order.py: Comprehensive test suite
  • examples/order_examples.py: Usage examples and patterns

Example Usage

Full example added to examples/order_examples

from order import Order, OrderSide, TimeInForce

# Setup exchange connection
_, _, exchange = example_utils.setup(constants.TESTNET_API_URL, skip_ws=True)

# Create order wrapper
order = Order(exchange)

# Example 1: Simple Market Orders
print("\n=== Market Order Examples ===")

# Market buy 0.1 ETH
result = order.market_order(asset="ETH", side=OrderSide.BUY, quantity=0.1, slippage=0.01)  # 1% max slippage
print(f"Market Buy Result: {result}")

# Market sell $1000 worth of BTC
result = order.market_order_notional(asset="BTC", side=OrderSide.SELL, notional_amount=1000)  # USD amount
print(f"Market Sell (Notional) Result: {result}")

# Example 2: Limit Orders
print("\n=== Limit Order Examples ===")

# Limit buy 0.1 ETH at $1800
result = order.limit_order(
    asset="ETH", side=OrderSide.BUY, quantity=0.1, price=1800, tif=TimeInForce.GTC  # Good till cancelled
)
print(f"Limit Buy Result: {result}")

# Post-only limit sell $2000 worth of ETH at $1900
result = order.limit_order_notional(
    asset="ETH",
    side=OrderSide.SELL,
    notional_amount=2000,
    price=1900,
    tif=TimeInForce.ALO,  # Add liquidity only (post-only)
)
print(f"Post-only Limit Sell Result: {result}")

Testing

All new functionality is covered by unit tests. Run the test suite with:

poetry run pytest tests/test_order.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant