{"record":{"id":"f65212bc8c1408d6","repo":"nautechsystems/nautilus_trader","slug":"failed-to-connect-binance-spot-sbe-websocket-e","errorCode":null,"errorMessage":"failed to connect Binance Spot SBE WebSocket: {e}","messagePattern":"failed to connect Binance Spot SBE WebSocket: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/spot/data.rs","lineNumber":1526,"sourceCode":"            &self.http_client,\n            &self.config.instrument_provider,\n            self.config.us,\n            &self.instruments,\n            &self.status_cache,\n            &self.ws_client,\n            &self.data_sender,\n            self.clock,\n            false,\n        )\n        .await?;\n\n        let session_result = async {\n            match &mut self.ws_client {\n                SpotWsClient::Sbe(ws_client) => {\n                    log::info!(\"Connecting to Binance Spot SBE WebSocket...\");\n                    ws_client.connect().await.map_err(|e| {\n                        log::error!(\"Binance Spot SBE WebSocket connection failed: {e:?}\");\n                        anyhow::anyhow!(\"failed to connect Binance Spot SBE WebSocket: {e}\")\n                    })?;\n                    log::info!(\"Binance Spot SBE WebSocket connected\");\n\n                    let stream = ws_client.stream();\n                    let sender = self.data_sender.clone();\n                    let insts = self.instruments.clone();\n                    let ws_insts = ws_client.instruments_cache();\n                    let buffers = self.book_buffers.clone();\n                    let book_subs = self.book_subscriptions.clone();\n                    let l1_book_subs = self.l1_book_subscriptions.clone();\n                    let book_epoch = self.book_epoch.clone();\n                    let http = self.http_client.clone();\n                    let clock = self.clock;\n                    let cancel = self.cancellation_token.clone();\n                    let command_spawner = self\n                        .command_tasks\n                        .spawner()\n                        .context(\"Binance Spot command task admission is closed\")?;","sourceCodeStart":1508,"sourceCodeEnd":1544,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/binance/src/spot/data.rs#L1508-L1544","documentation":"The Binance Spot data client failed to establish the SBE (Simple Binary Encoding) WebSocket connection during connect(). The underlying WebSocket error is logged with debug formatting and wrapped in an anyhow error that aborts the async connection session, so the data client cannot start streaming market data.","triggerScenarios":"Calling BinanceSpotDataClient::connect() when SpotWsClient is the Sbe variant and ws_client.connect() fails — typically network unreachable, DNS failure, TLS handshake failure, or the Binance wss endpoint rejecting/closing the connection.","commonSituations":"No internet or firewall/proxy blocking wss://stream.binance.com:9443; Binance geo-blocking (e.g. US IPs hitting 451); wrong URL configured; transient Binance outage; missing keepalive causing early disconnect during handshake.","solutions":["Check network reachability of the Binance WebSocket endpoint (curl the REST base / DNS resolve) and fix firewall/proxy rules.","Inspect the log line 'Binance Spot SBE WebSocket connection failed: {e:?}' for the root cause (TLS, timeout, HTTP 451/403).","Confirm you are not in a geo-restricted region or use an appropriately located deployment.","Retry with backoff; Binance occasionally drops connections during maintenance windows.","Verify adapter config (SBE vs JSON mode, URL) matches your environment."],"exampleFix":"// before\nclient.connect().await?;\n// after\nmatch client.connect().await {\n    Ok(()) => log::info!(\"connected\"),\n    Err(e) if e.to_string().contains(\"failed to connect Binance Spot SBE WebSocket\") => {\n        log::warn!(\"transient WS failure, retrying: {e}\");\n        tokio::time::sleep(Duration::from_secs(5)).await;\n        client.connect().await?;\n    }\n    Err(e) => return Err(e),\n}","handlingStrategy":"retry","validationCode":"// pre-connect reachability probe\nlet host = \"stream.binance.com\";\ntokio::net::TcpStream::connect((host, 9443)).await.expect(\"Binance WS endpoint unreachable\");","typeGuard":"fn is_ws_connect_error(err: &anyhow::Error) -> bool {\n    err.to_string().contains(\"failed to connect Binance Spot\")\n}","tryCatchPattern":"match client.connect().await {\n    Ok(()) => {},\n    Err(e) if is_ws_connect_error(&e) => retry_with_backoff(|| client.connect(), 3, Duration::from_secs(2)).await?,\n    Err(e) => return Err(e),\n}","preventionTips":["Probe network/TLS reachability of the Binance endpoint at startup.","Deploy outside geo-restricted regions or handle HTTP 451 explicitly.","Implement reconnect-with-backoff around connect().","Monitor Binance maintenance announcements."],"tags":["network","websocket","binance","connection"],"backgroundTag":"connection-refused","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}