Skip to main content

Module websocket

Module websocket 

Source
Expand description

WebSocket client implementation for the dYdX v4 API.

This module provides real-time streaming connectivity to dYdX WebSocket endpoints, supporting:

  • Market data streaming: Trades, order books, candles (bars), and market updates (oracle prices).
  • Private data streaming: Subaccount updates, orders, fills, and positions.
  • Channel subscription management: Subscribe and unsubscribe to public and private channels.
  • Automatic reconnection: Reconnection with state restoration and resubscription.
  • Message classification: Deserializes raw WebSocket JSON into venue-specific types.

§Architecture

The WebSocket client follows a two-layer architecture:

  • Outer client (client::DydxWebSocketClient): Orchestrates connection lifecycle, manages subscriptions, and maintains state accessible to Python via Arc<DashMap>.
  • Inner handler (handler::FeedHandler): Runs in a dedicated Tokio task as the I/O boundary, deserializing raw WebSocket messages into venue-specific types.

Communication between layers uses lock-free channels:

  • Commands flow from client to handler via mpsc channel.
  • Venue-specific messages flow from handler to client via mpsc channel.

§References

Re-exports§

pub use client::DydxWebSocketClient;
pub use dispatch::DydxWsDispatchState;
pub use dispatch::OrderIdentity;
pub use dispatch::fill_report_to_order_filled;
pub use enums::DydxWsChannel;
pub use enums::DydxWsMessage;
pub use enums::DydxWsMessageType;
pub use enums::DydxWsOperation;
pub use enums::DydxWsOutputMessage;
pub use error::DydxWebSocketError;
pub use error::DydxWsError;
pub use error::DydxWsResult;

Modules§

client
WebSocket client for dYdX v4 API.
dispatch
WebSocket message dispatch for the dYdX execution client.
enums
Enums for dYdX WebSocket operations, channels, and message types.
error
Error types for dYdX WebSocket operations.
handler
Message handler for dYdX WebSocket streams.
messages
WebSocket message types for dYdX public and private channels.
parse
Parsing utilities for dYdX WebSocket messages.