Expand description
Parsing utilities that convert Hyperliquid payloads into Nautilus domain models.
§Conditional Order Support
This module implements conditional order support for Hyperliquid.
§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).
Constants§
- DEFAULT_
MARKET_ SLIPPAGE_ BPS - Default slippage buffer in basis points for MARKET orders.
- OUTCOME_
SIDE_ NO - No-side label on Nautilus outcome symbols.
- OUTCOME_
SIDE_ YES - Yes-side label on Nautilus outcome symbols.
- OUTCOME_
SYMBOL_ SUFFIX - Suffix shared by every Nautilus outcome symbol, mirroring
-PERP/-SPOT.
Functions§
- bar_
type_ to_ interval - Converts a Nautilus
BarTypeto a Hyperliquid bar interval. - cache_
alias_ for_ symbol - Returns the secondary cache-alias key for a Nautilus instrument symbol.
- clamp_
price_ to_ precision - Clamp a price to the instrument’s decimal precision, rounding in the direction that preserves the slippage buffer.
- client_
order_ id_ to_ cancel_ request_ with_ asset - Converts a client order ID to a Hyperliquid cancel request using a pre-resolved asset index.
- derive_
limit_ from_ trigger - Derives a limit price from a trigger price with a configurable
slippage buffer in basis points, widening the limit so BUY satisfies
limit_px >= trigger_pxand SELL satisfieslimit_px <= trigger_px. - derive_
market_ order_ price - Derives a market order limit price from a quote with a configurable slippage buffer in basis points, rounded to 5 significant figures and clamped to the instrument’s price precision.
- 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.
- extract_
inner_ error - Extracts per-item error from a successful Hyperliquid exchange response.
- extract_
inner_ errors - Extracts per-item errors from a successful batch response.
- format_
outcome_ nautilus_ symbol - Formats an
(outcome_index, side)pair into the Nautilus outcome symbol form{outcome_index}-{YES|NO}-OUTCOME. - 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.
- make_
fill_ trade_ id - Creates a deterministic [
TradeId] from fill fields common to both WS and HTTP responses. - 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.
- order_
to_ hyperliquid_ request_ with_ asset_ and_ cloid - Converts a Nautilus order to Hyperliquid request with an explicit CLOID.
- outcome_
token_ from_ nautilus_ symbol - Returns the
+<encoding>token form for the side token referenced by a Nautilus outcome symbol, orNoneif the symbol is not an outcome. - parse_
account_ balances_ and_ margins - Parses Hyperliquid clearinghouse state into Nautilus account balances and margins.
- parse_
combined_ account_ balances_ and_ margins - Merges perp clearinghouse balances with spot balances into a unified set.
- parse_
order_ status_ with_ trigger - Extracts order status from WebSocket order data.
- parse_
outcome_ nautilus_ symbol - Parses a Nautilus outcome instrument symbol of the form
{outcome_index}-{YES|NO}-OUTCOMEinto(outcome_index, side)where side is0for Yes and1for No. - parse_
outcome_ symbol - Parses an outcome (HIP-4) spot coin or token symbol into an asset ID.
- parse_
spot_ account_ balances - Parses Hyperliquid spot clearinghouse state into Nautilus account balances.
- parse_
trigger_ order_ type - Parses trigger order type from Hyperliquid order data.
- parse_
trigger_ order_ type_ label - Parses trigger semantics from a REST
orderTypelabel. - 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.