Skip to main content

Module dispatch

Module dispatch 

Source
Expand description

WebSocket execution dispatch for the Hyperliquid execution client.

Implements the two-tier execution dispatch contract from docs/developer_guide/adapters.md (lines 1232-1296):

  1. The execution client registers an OrderIdentity in WsDispatchState when it submits an order, and refreshes the cached venue order id when a modify is sent so the WebSocket consumer can detect cancel-replace.
  2. Incoming [OrderStatusReport] and [FillReport] messages are routed through dispatch_order_status_report and dispatch_fill_report. For tracked orders these build typed [OrderEventAny] events and emit them via [ExecutionEventEmitter::send_order_event]. For untracked / external orders the dispatch falls back to forwarding the raw report.

The dispatch state lives in an Arc<WsDispatchState> shared between the main client task (which registers identities at submission time) and the spawned WebSocket consumer task.

§GH-3827 cancel-replace handling

Hyperliquid implements modify as a cancel-and-replace: the venue emits an ACCEPTED(new_voi) together with a CANCELED(old_voi) under the same client_order_id. The dispatch detects the replacement leg by comparing report.venue_order_id to the last cached value, promotes it to an OrderUpdated event, and suppresses the stale cancel so strategies never observe a spurious termination.

The pending-modify marker (keyed on client_order_id) is set by modify_order only after a successful HTTP round-trip and cleared on the matching ACCEPTED. It lets dispatch skip an early CANCELED(old_voi) that arrives before the replacement ACCEPTED(new_voi) on the WebSocket. The documented transport-timeout + WS-race window still applies: if the modify HTTP call fails but the venue actually accepted it, no marker is set, so a cancel-before-accept race in that window would surface as OrderCanceled. This matches the Python behaviour we are porting and is the simplest correct answer; verifying the venue-side outcome before emitting would require speculative waiting that drops latency without improving correctness.

Structs§

BoundedDedup
Bounded FIFO deduplication set.
OrderIdentity
Identity metadata captured when an order is submitted through this client.
WsDispatchState
Per-client dispatch state shared between order submission and the WebSocket consumer task.

Enums§

DispatchOutcome
Outcome of a single dispatch call.

Constants§

DEDUP_CAPACITY

Functions§

dispatch_fill_report
Dispatches a [FillReport] using the two-tier routing contract.
dispatch_order_status_report
Dispatches an [OrderStatusReport] using the two-tier routing contract.