PENDING_ROUTING
│
▼ Routing decision (< 5ms)
ROUTED (INTERNAL / HYPERLIQUID)
│
├─ Market order ──► FILLING ──► FILLED
│
└─ Limit order ──► OPEN (waiting for price)
│
├─ Price touched ──► FILLING ──► FILLED
└─ User cancelled ──► CANCELLED
User submits order
├─ Symbol validation (is contract listed?)
├─ Leverage range check (≤ maxLeverage from HL meta)
├─ Size precision check (szDecimals from HL meta)
├─ Minimum size check
└─ Available balance check (sufficient margin?)
Notional = size × HL mark_price
Notional ≤ threshold → INTERNAL
Notional > threshold → HYPERLIQUID
Force-HL condition checks (exposure / latency / volatility / manual override)
Fill at HL mark price / best bid-ask
Freeze user margin (isolated: frozen_margin; cross: cross_margin_used)
Create position (position_source = INTERNAL)
Create platform mirror counterparty position (internal ledger)
Write to fills table
Push WebSocket fill notification
↓
L6 net exposure updated in real-time (check hedge thresholds)
Pre-estimate margin; temporarily freeze
Send open order to HL
Await HL fill receipt (fill_price, filled_size, fee)
Replace entry_price with fill_price (fill price correction)
Recompute margin; release or deduct delta
Create position (position_source = HYPERLIQUID)
Write to fills table (includes hl_fill_price field)
Push WebSocket fill notification
User initiates close (full / partial)
│
├─ INTERNAL position ──► L3 internal close
│ ├─ Fill at HL mark price / best bid-ask
│ ├─ Compute realized PnL
│ ├─ Release margin
│ └─ position.status = CLOSED
│
└─ HYPERLIQUID position ──► L4 send close order to HL
├─ Await HL receipt (close_price)
├─ Compute realized PnL using close_price
├─ Release margin
└─ position.status = CLOSED
L7 real-time mark_price push
Platform scans all TP/SL orders
Price touches TP/SL level → trigger close
Execution path same as above (INTERNAL / HYPERLIQUID handled separately)
User places limit order
│
▼
Routing decision (INTERNAL / HYPERLIQUID)
│
├─ INTERNAL ──► Added to internal pending queue (OPEN)
│ L7 real-time price touches limit → immediate fill → FILLED
│ User cancels → remove from queue; release margin → CANCELLED
│
└─ HYPERLIQUID ──► Submit limit order to HL
HL fills → receipt pushed → FILLED
User cancels → send cancel to HL → CANCELLED