nautilus_dydx/websocket/mod.rs
1// -------------------------------------------------------------------------------------------------
2// Copyright (C) 2015-2025 Nautech Systems Pty Ltd. All rights reserved.
3// https://nautechsystems.io
4//
5// Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6// You may not use this file except in compliance with the License.
7// You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16//! WebSocket client implementation for the dYdX v4 API.
17//!
18//! This module provides real-time streaming connectivity to dYdX WebSocket endpoints,
19//! supporting:
20//!
21//! - **Market data streaming**: Trades, order books, candles (bars), and market updates (oracle prices).
22//! - **Private data streaming**: Subaccount updates, orders, fills, and positions.
23//! - **Channel subscription management**: Subscribe and unsubscribe to public and private channels.
24//! - **Automatic reconnection**: Reconnection with state restoration and resubscription.
25//! - **Message parsing**: Fast conversion of WebSocket messages to Nautilus domain objects.
26//!
27//! # Architecture
28//!
29//! The WebSocket client follows a two-layer architecture:
30//!
31//! - **Outer client** ([`client::DydxWebSocketClient`]): Orchestrates connection lifecycle, manages
32//! subscriptions, and maintains state accessible to Python via `Arc<DashMap>`.
33//! - **Inner handler** ([`handler::FeedHandler`]): Runs in a dedicated Tokio task as the I/O boundary,
34//! processing commands and parsing raw WebSocket messages into Nautilus types.
35//!
36//! Communication between layers uses lock-free channels:
37//! - Commands flow from client to handler via `mpsc` channel.
38//! - Parsed domain events flow from handler to client via `mpsc` channel.
39//!
40//! # References
41//!
42//! - dYdX v4 WebSocket API: <https://docs.dydx.trade/developers/indexer/websockets>
43
44pub mod client;
45pub mod enums;
46pub mod error;
47pub mod handler;
48pub mod messages;
49pub mod parse;
50pub mod types;
51
52// Re-exports
53pub use client::DydxWebSocketClient;
54pub use enums::{DydxWsChannel, DydxWsOperation};
55pub use error::{DydxWebSocketError, DydxWsError, DydxWsResult};
56pub use messages::{DydxWsMessage, NautilusWsMessage};