Repository: nautechsystems/nautilus_trader
File: crates/adapters/dydx/src/websocket/client.rs (Rust)

Code before:
/// Public channels work without any credentials. Private channels (subaccounts) only
/// need the wallet address included in the subscription message.
///
/// The [`DydxCredential`] stored in this client is used for:
/// - Providing the wallet address for private channel subscriptions
/// - Transaction signing (when placing orders via the validator node)
///
/// It is **NOT** used for WebSocket message signing or authentication.
///
/// # Architecture
///
/// This client follows a two-layer architecture:
/// - **Outer client** (this struct): Orchestrates connection and maintains Python-accessible state
/// - **Inner handler**: Owns WebSocketClient exclusively and processes messages in a dedicated task
///
/// Communication uses lock-free channels:
/// - Commands flow from client → handler via `handler_cmd_tx`
/// - Parsed events flow from handler → client via `out_rx`
#[derive(Debug)]
#[cfg_attr(
    feature = "python",
    pyo3::pyclass(module = "nautilus_trader.core.nautilus_pyo3.dydx")
)]
pub struct DydxWebSocketClient {
    /// The WebSocket connection URL.
    pub(crate) url: String,
    /// Optional credential for private channels (only wallet address is used).
    credential: Option<Arc<DydxCredential>>,
    /// Whether authentication is required for this client.
    requires_auth: bool,
    /// Authentication tracker for WebSocket connections.
    #[allow(dead_code)]
    auth_tracker: AuthTracker,
    /// Subscription state tracker for managing channel subscriptions.
    #[allow(dead_code)]
    subscriptions: SubscriptionState,
    /// Shared connection state (lock-free atomic).
    pub(crate) connection_mode: Arc<ArcSwap<AtomicU8>>,
    /// Manual disconnect signal.
    signal: Arc<AtomicBool>,
    /// Cached instruments for parsing market data (Python-accessible).
    instruments_cache: Arc<DashMap<Ustr, InstrumentAny>>,
    /// Optional account ID for account message parsing.
    account_id: Option<AccountId>,
    /// Optional heartbeat interval in seconds.
    heartbeat: Option<u64>,
    /// Command channel sender to handler.
    handler_cmd_tx: Arc<tokio::sync::mpsc::UnboundedSender<HandlerCommand>>,
    /// Receiver for parsed Nautilus messages from handler.
    out_rx: Option<tokio::sync::mpsc::UnboundedReceiver<NautilusWsMessage>>,
    /// Background handler task handle.

Review comment (suggestion):
This shouldn't need to become `pub(crate)`, needs an accessor like some of the other adapters are using now.

Code after:
/// Public channels work without any credentials. Private channels (subaccounts) only
/// need the wallet address included in the subscription message.
///
/// The [`DydxCredential`] stored in this client is used for:
/// - Providing the wallet address for private channel subscriptions
/// - Transaction signing (when placing orders via the validator node)
///
/// It is **NOT** used for WebSocket message signing or authentication.
///
/// # Architecture
///
/// This client follows a two-layer architecture:
/// - **Outer client** (this struct): Orchestrates connection and maintains Python-accessible state
/// - **Inner handler**: Owns WebSocketClient exclusively and processes messages in a dedicated task
///
/// Communication uses lock-free channels:
/// - Commands flow from client → handler via `handler_cmd_tx`
/// - Parsed events flow from handler → client via `out_rx`
#[derive(Debug)]
#[cfg_attr(
    feature = "python",
    pyo3::pyclass(module = "nautilus_trader.core.nautilus_pyo3.dydx")
)]
pub struct DydxWebSocketClient {
    /// The WebSocket connection URL.
    url: String,
    /// Optional credential for private channels (only wallet address is used).
    credential: Option<Arc<DydxCredential>>,
    /// Whether authentication is required for this client.
    requires_auth: bool,
    /// Authentication tracker for WebSocket connections.
    #[allow(dead_code)]
    auth_tracker: AuthTracker,
    /// Subscription state tracker for managing channel subscriptions.
    #[allow(dead_code)]
    subscriptions: SubscriptionState,
    /// Shared connection state (lock-free atomic).
    connection_mode: Arc<ArcSwap<AtomicU8>>,
    /// Manual disconnect signal.
    signal: Arc<AtomicBool>,
    /// Cached instruments for parsing market data (Python-accessible).
    instruments_cache: Arc<DashMap<Ustr, InstrumentAny>>,
    /// Optional account ID for account message parsing.
    account_id: Option<AccountId>,
    /// Optional heartbeat interval in seconds.
    heartbeat: Option<u64>,
    /// Command channel sender to handler.
    handler_cmd_tx: Arc<tokio::sync::mpsc::UnboundedSender<HandlerCommand>>,
    /// Receiver for parsed Nautilus messages from handler.
    out_rx: Option<tokio::sync::mpsc::UnboundedReceiver<NautilusWsMessage>>,
    /// Background handler task handle.