{"record":{"id":"00a7569718cfb4b2","repo":"nautechsystems/nautilus_trader","slug":"failed-to-connect-binance-futures-market-websocket","errorCode":null,"errorMessage":"failed to connect Binance Futures market WebSocket: {e}","messagePattern":"failed to connect Binance Futures market WebSocket: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/futures/data.rs","lineNumber":1573,"sourceCode":"\n        Self::refresh_instrument_catalog(\n            &self.http_client,\n            &self.config.instrument_provider,\n            &self.instruments,\n            &self.status_cache,\n            &self.ws_client,\n            &self.ws_public_client,\n            &self.data_sender,\n            self.clock,\n            false,\n        )\n        .await?;\n\n        let session_result = async {\n            log::info!(\"Connecting to Binance Futures market WebSocket...\");\n            self.ws_client.connect().await.map_err(|e| {\n                log::error!(\"Binance Futures market WebSocket connection failed: {e:?}\");\n                anyhow::anyhow!(\"failed to connect Binance Futures market WebSocket: {e}\")\n            })?;\n            log::info!(\"Binance Futures market WebSocket connected\");\n\n            log::info!(\"Connecting to Binance Futures public WebSocket...\");\n            self.ws_public_client.connect().await.map_err(|e| {\n                log::error!(\"Binance Futures public WebSocket connection failed: {e:?}\");\n                anyhow::anyhow!(\"failed to connect Binance Futures public WebSocket: {e}\")\n            })?;\n            log::info!(\"Binance Futures public WebSocket connected\");\n\n            let stream = self.ws_client.stream();\n            let sender = self.data_sender.clone();\n            let insts = self.instruments.clone();\n            let ws_insts = self.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 force_order_refs = self.force_order_refs.clone();","sourceCodeStart":1555,"sourceCodeEnd":1591,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/binance/src/futures/data.rs#L1555-L1591","documentation":"During BinanceFuturesDataClient::connect, the primary market data WebSocket failed to establish a connection. The underlying WebSocket client error is logged with debug formatting and surfaced as an anyhow error, aborting the whole async connect block (the public WebSocket is never attempted).","triggerScenarios":"Calling connect() on the Binance Futures data client when self.ws_client.connect() returns Err — DNS failure, TCP/TLS failure to Binance endpoints, proxy blocking, or endpoint outage.","commonSituations":"Running in an environment without internet egress or behind a corporate proxy/firewall; wrong DNS; Binance geo-blocking (e.g. US IPs to binance.com); transient Binance API downtime.","solutions":["Check network egress to the Binance Futures WebSocket host (port 443 reachable) and fix proxy/firewall settings","Read the logged `Binance Futures market WebSocket connection failed: {e:?}` line for the root cause","Retry with backoff — transient outages and TLS handoff failures resolve themselves","Verify the configured base URL / testnet flag points at the correct reachable endpoint"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// before connecting, verify the endpoint is reachable\nassert!(std::net::TcpStream::connect(\"fstream.binance.com:443\").is_ok(), \"Binance Futures WS endpoint unreachable\");","typeGuard":null,"tryCatchPattern":"loop {\n    match client.connect().await {\n        Ok(()) => break,\n        Err(e) if e.to_string().contains(\"failed to connect Binance Futures market WebSocket\") => {\n            log::warn!(\"WS connect failed: {e}; retrying in 5s\");\n            tokio::time::sleep(Duration::from_secs(5)).await;\n        }\n        Err(e) => return Err(e),\n    }\n}","preventionTips":["Verify network egress and proxy settings allow wss to Binance endpoints","Use the correct endpoint for your region (binance.com vs binance.us / testnet)","Add reconnect-with-backoff around the data client lifecycle","Monitor Binance status pages during outages"],"tags":["network","websocket","connection","binance-futures"],"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"}