Module handler

Module handler 

Source
Expand description

WebSocket message handler for OKX.

The handler runs in a dedicated Tokio task as the I/O boundary between the client orchestrator and the network layer. It exclusively owns the WebSocketClient and processes commands from the client via an unbounded channel, serializing them to JSON and sending via the WebSocket. Raw messages are received from the network, deserialized, and transformed into NautilusWsMessage events which are emitted back to the client.

Key responsibilities:

  • Command processing: Receives HandlerCommand from client, executes WebSocket operations.
  • Message transformation: Parses raw venue messages into Nautilus domain events.
  • Pending state tracking: Owns AHashMap for matching requests/responses (single-threaded).
  • Retry logic: Retries transient WebSocket send failures using RetryManager.
  • Error event emission: Emits OrderRejected, OrderCancelRejected when retries exhausted.

Enums§

HandlerCommand
Commands sent from the outer client to the inner message handler.
PendingOrderParams

Functions§

is_post_only_rejection
Returns true when an OKX error payload represents a post-only rejection.