{"record":{"id":"5be93e5bc1d6166a","repo":"nautechsystems/nautilus_trader","slug":"reason","errorCode":null,"errorMessage":"{reason}","messagePattern":"\\{reason\\}","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/spot/execution.rs","lineNumber":571,"sourceCode":"\n    fn abort_pending_tasks(&self) {\n        crate::common::execution::abort_pending_tasks(&self.pending_tasks);\n    }\n\n    async fn ws_setup_failure(\n        &mut self,\n        mut ws_trading: BinanceSpotWsTradingClient,\n        reason: String,\n    ) -> anyhow::Error {\n        ws_trading.mark_user_data_inactive();\n        log::error!(\"{reason}; Binance Spot private user data is required for execution\");\n\n        if let Some(handle) = self.ws_trading_handle.take() {\n            handle.abort();\n        }\n        ws_trading.disconnect().await;\n        self.ws_trading_client = Some(ws_trading);\n        anyhow::anyhow!(reason)\n    }\n\n    async fn connect_us_user_data(&mut self) -> anyhow::Result<()> {\n        let (api_key, api_secret) = self\n            .us_credentials\n            .clone()\n            .context(\"Binance US user data credentials are unavailable\")?;\n        let listen_key = self\n            .http_client\n            .inner()\n            .create_listen_key()\n            .await\n            .context(\"failed to create Binance US listen key\")?\n            .listen_key;\n        let url = get_spot_user_stream_url(self.config.base_url_ws.as_deref(), &listen_key);\n        let mut ws_user_data = BinanceSpotWsTradingClient::new(\n            Some(url),\n            api_key,","sourceCodeStart":553,"sourceCodeEnd":589,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/a4b06ed870971b5671d12754ea138a3ab99b1dec/crates/adapters/binance/src/spot/execution.rs#L553-L589","documentation":"This is the shared failure exit for a Spot WS trading session whose private user data stream could not be established: it marks user data inactive, aborts the session handle, disconnects, and returns the wrapped reason — typically 'WS session logon failed: …', 'WS user data subscribe failed: …', or 'Failed to connect WS trading API: …' (see the call sites around spot/execution.rs:876-910).","triggerScenarios":"Connecting with use_ws_trading=true when session.logon fails (bad API key/secret, signature or timestamp errors, key lacking WebSocket API access) or when the subsequent userDataStream.subscribe fails.","commonSituations":"API keys restricted to REST-only; wrong secret or clock skew breaking the logon signature; networks or proxies blocking the WS trading endpoint; first run after enabling use_ws_trading.","solutions":["Verify the API key/secret pair and that the key permits WebSocket API access","Sync the system clock (NTP) — timestamp skew breaks the logon signature","Check network/proxy reachability of the Binance WS trading endpoint","Disable use_ws_trading to fall back to HTTP REST plus the listen-key user data stream"],"exampleFix":"# before\nconfig = BinanceExecClientConfig(use_ws_trading=True)  # logon fails\n\n# after: REST trading + listen-key user data stream\nconfig = BinanceExecClientConfig(use_ws_trading=False)","handlingStrategy":"retry","validationCode":"# pre-flight before enabling WS trading\n# 1. key/secret valid and WebSocket API access enabled for the key\n# 2. host clock NTP-synced (logon signature is timestamp-sensitive)\n# 3. ws-api.binance.com reachable (curl/proxy check)\n# otherwise start with:\nconfig = BinanceExecClientConfig(use_ws_trading=False)","typeGuard":null,"tryCatchPattern":"match connect().await {\n    Err(e) if e.to_string().contains(\"WS session logon failed\")\n        || e.to_string().contains(\"WS user data subscribe failed\")\n        || e.to_string().contains(\"Failed to connect WS trading API\") =>\n    {\n        // fix credentials/clock/network, then retry connect;\n        // meanwhile run with use_ws_trading=false over REST\n    }\n    other => other?,\n}","preventionTips":["Pre-verify keys against a REST signed endpoint to isolate credential problems","Keep the host NTP-synced; skew breaks the session.logon signature","Have a use_ws_trading=false config ready to trade over REST if WS cannot connect"],"tags":["binance","spot","websocket","authentication","user-data-stream","connection"],"backgroundTag":"websocket-auth-failed","analyzedSha":"a4b06ed870971b5671d12754ea138a3ab99b1dec","analyzedAt":"2026-08-16T22:54:50.089Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}