{"record":{"id":"e4df5eceb521759f","repo":"nautechsystems/nautilus_trader","slug":"ws-user-data-subscription-timed-out","errorCode":null,"errorMessage":"WS user data subscription timed out","messagePattern":"WS user data subscription timed out","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/spot/execution.rs","lineNumber":2006,"sourceCode":"    setup_errors: &mut tokio::sync::mpsc::UnboundedReceiver<String>,\n    timeout_message: &'static str,\n) -> anyhow::Result<()> {\n    tokio::pin!(success);\n\n    let result = tokio::time::timeout(timeout, async {\n        tokio::select! {\n            () = &mut success => Ok(()),\n            err = setup_errors.recv() => {\n                anyhow::bail!(\n                    \"{}\",\n                    err.unwrap_or_else(|| \"WS setup error channel closed\".to_string()),\n                )\n            }\n        }\n    })\n    .await;\n\n    result.map_err(|_| anyhow::anyhow!(timeout_message))?\n}\n\n#[expect(clippy::too_many_arguments)]\nfn dispatch_ws_trading_message(\n    msg: BinanceSpotWsTradingMessage,\n    emitter: &ExecutionEventEmitter,\n    http_client: &BinanceSpotHttpClient,\n    account_id: AccountId,\n    treat_expired_as_canceled: bool,\n    clock: &'static AtomicTime,\n    dispatch_state: &WsDispatchState,\n    ws_authenticated: &tokio::sync::Notify,\n    ws_user_data_subscribed: &tokio::sync::Notify,\n    ws_setup_error_tx: &tokio::sync::mpsc::UnboundedSender<String>,\n    seen_trade_ids: &std::sync::Arc<Mutex<FifoCache<(Ustr, i64), 10_000>>>,\n) {\n    match msg {\n        BinanceSpotWsTradingMessage::OrderAccepted {","sourceCodeStart":1988,"sourceCodeEnd":2024,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/a4b06ed870971b5671d12754ea138a3ab99b1dec/crates/adapters/binance/src/spot/execution.rs#L1988-L2024","documentation":"In Binance Spot WS trading setup, after `subscribe_user_data()` the adapter waits up to `ws_trading_setup_timeout_ms` (default 10,000 ms) for the subscription confirmation (the `ws_user_data_subscribed` Notify). If neither confirmation nor a setup error (e.g. `UserDataSubscriptionRejected`) arrives in time, the timeout error is replaced with 'WS user data subscription timed out' and adapter connection fails before the WS client is registered.","triggerScenarios":"Authenticating the WS trading session successfully, but the user-data stream subscription confirmation never arrives within the configured window — stalled WS connection, high latency to Binance, slow user-data stream provisioning, or `ws_trading_setup_timeout_ms` set too low for the round trip.","commonSituations":"Same contexts as the auth timeout: remote/cross-region hosting, congested networks, Binance maintenance or high load, lowered timeout config; also listen-key/user-data stream provisioning lagging on Binance's side.","solutions":["Increase `ws_trading_setup_timeout_ms` (e.g. 30_000) so the subscription confirmation has time to arrive","Retry the connect; user-data stream provisioning lag is usually transient","Verify network path/proxy to Binance WS endpoints and reduce latency","If it consistently fails while authentication succeeds, check for Binance user-data-stream incidents and any account restrictions"],"exampleFix":"# before\nconfig = BinanceExecClientConfig(\n    api_key=os.environ[\"BINANCE_API_KEY\"],\n    api_secret=os.environ[\"BINANCE_API_SECRET\"],\n    use_ws_trading=True,  # subscription confirmation must arrive within 10s\n)\n\n# after\nconfig = BinanceExecClientConfig(\n    api_key=os.environ[\"BINANCE_API_KEY\"],\n    api_secret=os.environ[\"BINANCE_API_SECRET\"],\n    use_ws_trading=True,\n    ws_trading_setup_timeout_ms=30_000,\n)","handlingStrategy":"retry","validationCode":"# Python: budget the setup timeout generously when WS trading is enabled\nconfig = BinanceExecClientConfig(\n    api_key=..., api_secret=..., use_ws_trading=True,\n    ws_trading_setup_timeout_ms=30_000,  # covers slow user-data stream provisioning\n)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Raise ws_trading_setup_timeout_ms on high-latency or remote hosts instead of retrying forever at 10s","Retry the connect once or twice — user-data subscription lag is often transient on Binance's side","Keep the WS session healthy (stable network, no aggressive proxies) so subscription confirmations arrive promptly","Alert on connect failures that persist while authentication succeeds — that pattern isolates the problem to the user-data stream step"],"tags":["binance-spot","websocket","timeout","user-data-stream","subscription","connection-setup","nautilustrader"],"backgroundTag":"websocket-connection-timeout","analyzedSha":"a4b06ed870971b5671d12754ea138a3ab99b1dec","analyzedAt":"2026-08-16T22:54:50.089Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}