Expand description
Parsing utilities that convert Hyperliquid payloads into Nautilus domain models.
§Conditional Order Support
This module implements comprehensive conditional order support for Hyperliquid, following patterns established in the OKX, Bybit, and BitMEX adapters.
§Supported Order Types
§Standard Orders
- Market: Implemented as IOC (Immediate-or-Cancel) limit orders.
- Limit: Standard limit orders with GTC/IOC/ALO time-in-force.
§Conditional/Trigger Orders
- StopMarket: Protective stop that triggers at specified price and executes at market.
- StopLimit: Protective stop that triggers at specified price and executes at limit.
- MarketIfTouched: Profit-taking/entry order that triggers and executes at market.
- LimitIfTouched: Profit-taking/entry order that triggers and executes at limit.
§Order Semantics
§Stop Orders (StopMarket/StopLimit)
- Used for protective stops and risk management.
- Mapped to Hyperliquid’s trigger orders with
tpsl: Sl. - Trigger when price reaches the stop level.
- Execute immediately (market) or at limit price.
§If Touched Orders (MarketIfTouched/LimitIfTouched)
- Used for profit-taking or entry orders.
- Mapped to Hyperliquid’s trigger orders with
tpsl: Tp. - Trigger when price reaches the target level.
- Execute immediately (market) or at limit price.
§Trigger Price Logic
The tpsl field (Take Profit / Stop Loss) is determined by:
- Order Type: Stop orders → SL, If Touched orders → TP
- Price Relationship (if available):
- For BUY orders: trigger above market → SL, below → TP
- For SELL orders: trigger below market → SL, above → TP
§Trigger Type Support
Hyperliquid uses mark price for all trigger evaluations (TP/SL orders).
Functions§
- bar_
type_ to_ interval - Converts a Nautilus
BarTypeto a Hyperliquid bar interval. - client_
order_ id_ to_ cancel_ request_ with_ asset - Converts a client order ID to a Hyperliquid cancel request using a pre-resolved asset index.
- deserialize_
decimal_ from_ str - Deserializes a
Decimalfrom a JSON string. - deserialize_
optional_ decimal_ from_ str - Deserializes an optional
Decimalfrom a string-only field. - deserialize_
vec_ decimal_ from_ str - Deserializes a
Vec<Decimal>from a JSON array of strings. - ensure_
min_ notional - Ensure the notional value meets minimum requirements.
- extract_
error_ message - Extracts error message from a Hyperliquid exchange response.
- format_
trailing_ stop_ info - Converts WebSocket trailing stop data to description string.
- is_
conditional_ order_ data - Determines if an order is a conditional/trigger order based on order data.
- is_
response_ successful - Checks if a Hyperliquid exchange response indicates success.
- millis_
to_ nanos - Converts millisecond timestamp to [
UnixNanos]. - normalize_
order - Complete normalization for an order including price, quantity, and notional validation
- normalize_
price - Normalize price to the specified number of decimal places.
- normalize_
quantity - Normalize quantity to the specified number of decimal places.
- order_
to_ hyperliquid_ request_ with_ asset - Converts a Nautilus order to Hyperliquid request using a pre-resolved asset index.
- parse_
account_ balances_ and_ margins - Parses Hyperliquid clearinghouse state into Nautilus account balances and margins.
- parse_
order_ status_ with_ trigger - Extracts order status from WebSocket order data.
- parse_
trigger_ order_ type - Parses trigger order type from Hyperliquid order data.
- parse_
trigger_ price - Parses trigger price from string to Decimal.
- round_
down_ to_ step - Round quantity down to the nearest valid step size.
- round_
down_ to_ tick - Round price down to the nearest valid tick size.
- round_
to_ sig_ figs - Round a decimal to at most N significant figures. Hyperliquid requires prices to have at most 5 significant figures.
- serialize_
decimal_ as_ str - Serializes a
Decimalas a string (lossless, no scientific notation). - serialize_
optional_ decimal_ as_ str - Serializes an optional
Decimalas a string. - serialize_
vec_ decimal_ as_ str - Serializes a
Vec<Decimal>as an array of strings. - time_
in_ force_ to_ hyperliquid_ tif - Converts a Nautilus
TimeInForceto Hyperliquid TIF. - validate_
conditional_ order_ params - Validates conditional order parameters from WebSocket data.