{"record":{"id":"bd9f95f46a2c15ce","repo":"nautechsystems/nautilus_trader","slug":"failed-to-connect-binance-spot-public-json-websock","errorCode":null,"errorMessage":"failed to connect Binance Spot public JSON WebSocket: {e}","messagePattern":"failed to connect Binance Spot public JSON WebSocket: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/spot/data.rs","lineNumber":1581,"sourceCode":"                                        &command_spawner,\n                                    );\n                                }\n                                () = cancel.cancelled() => {\n                                    log::debug!(\"Spot SBE WebSocket stream task cancelled\");\n                                    break;\n                                }\n                            }\n                        }\n                    };\n                    self.session_tasks\n                        .spawn(future)\n                        .context(\"failed to register Binance Spot SBE stream task\")?;\n                }\n                SpotWsClient::JsonPublic(ws_client) => {\n                    log::info!(\"Connecting to Binance Spot public JSON WebSocket...\");\n                    ws_client.connect().await.map_err(|e| {\n                        log::error!(\"Binance Spot public JSON WebSocket connection failed: {e:?}\");\n                        anyhow::anyhow!(\"failed to connect Binance Spot public JSON WebSocket: {e}\")\n                    })?;\n                    log::info!(\"Binance Spot public JSON 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":1563,"sourceCodeEnd":1599,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/binance/src/spot/data.rs#L1563-L1599","documentation":"The Binance Spot data client failed to establish the public JSON WebSocket connection during connect(). The underlying error is logged with debug detail and wrapped in an anyhow error, aborting the connect() session so no market data can stream.","triggerScenarios":"Calling connect() when SpotWsClient is the JsonPublic variant and ws_client.connect() fails — network failure, TLS error, endpoint rejecting connection, or invalid stream URL.","commonSituations":"Firewall or corporate proxy blocking wss://stream.binance.com:9443; Binance geo-restriction responses; DNS misconfiguration; Binance maintenance; wrong environment URL (testnet vs prod).","solutions":["Verify the WebSocket endpoint is reachable from your host (DNS + TCP + TLS).","Check the debug log 'Binance Spot public JSON WebSocket connection failed: {e:?}' for the concrete cause.","If geo-blocked (HTTP 451), deploy in a supported region.","Retry with exponential backoff for transient Binance-side drops.","Confirm the adapter is configured for the intended environment (prod vs testnet URL)."],"exampleFix":"// before\nlet client = BinanceSpotDataClient::new_json_public(config);\nclient.connect().await?;\n// after\nif let Err(e) = client.connect().await {\n    log::error!(\"spot JSON WS connect failed: {e:#}\");\n    if e.to_string().contains(\"failed to connect Binance Spot public JSON WebSocket\") {\n        tokio::time::sleep(Duration::from_secs(2)).await;\n        client.connect().await?;\n    } else {\n        return Err(e);\n    }\n}","handlingStrategy":"retry","validationCode":"// pre-connect reachability probe\nlet host = \"stream.binance.com\";\ntokio::net::TcpStream::connect((host, 9443)).await.expect(\"Binance JSON WS endpoint unreachable\");","typeGuard":"fn is_json_ws_connect_error(err: &anyhow::Error) -> bool {\n    err.to_string().contains(\"failed to connect Binance Spot public JSON WebSocket\")\n}","tryCatchPattern":"if let Err(e) = client.connect().await {\n    if is_json_ws_connect_error(&e) {\n        tokio::time::sleep(Duration::from_secs(5)).await;\n        client.connect().await?;\n    } else { return Err(e); }\n}","preventionTips":["Verify endpoint reachability before building the data client.","Distinguish transient (retryable) from permanent (config/geo) connect failures.","Log the underlying {e:?} detail to diagnose TLS vs DNS vs HTTP rejection.","Add automatic reconnect supervision to the data client."],"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"}