nautechsystems/nautilus_trader · error · anyhow::Error

failed to connect Binance Spot public JSON WebSocket: {e}

Error message

failed to connect Binance Spot public JSON WebSocket: {e}

What it means

The Binance Spot public JSON market data WebSocket (used for trades, book, and other public streams) failed to connect; the underlying cause is preserved in {e} and logged in Debug form. Because this stream is public, failures are almost always network/DNS/firewall/proxy related rather than authentication.

Source

Thrown at crates/adapters/binance/src/spot/data.rs:1576

                                    &book_epoch,
                                    &http,
                                    clock,
                                );
                            }
                            () = cancel.cancelled() => {
                                log::debug!("Spot SBE WebSocket stream task cancelled");
                                break;
                            }
                        }
                    }
                });
                self.tasks.push(handle);
            }
            SpotWsClient::JsonPublic(ws_client) => {
                log::info!("Connecting to Binance Spot public JSON WebSocket...");
                ws_client.connect().await.map_err(|e| {
                    log::error!("Binance Spot public JSON WebSocket connection failed: {e:?}");
                    anyhow::anyhow!("failed to connect Binance Spot public JSON WebSocket: {e}")
                })?;
                log::info!("Binance Spot public JSON WebSocket connected");

                let stream = ws_client.stream();
                let sender = self.data_sender.clone();
                let insts = self.instruments.clone();
                let ws_insts = ws_client.instruments_cache();
                let buffers = self.book_buffers.clone();
                let book_subs = self.book_subscriptions.clone();
                let l1_book_subs = self.l1_book_subscriptions.clone();
                let book_epoch = self.book_epoch.clone();
                let http = self.http_client.clone();
                let clock = self.clock;
                let cancel = self.cancellation_token.clone();

                let handle = get_runtime().spawn(async move {
                    pin_mut!(stream);

View on GitHub (pinned to a4b06ed870)

Solutions

  1. Read {e} to classify: timeouts/DNS point to network, HTTP status codes point to blocking or configuration
  2. Test raw reachability of the Binance Spot WebSocket endpoint from the same host (e.g. a manual WebSocket handshake)
  3. Configure proxy_url if egress requires a proxy
  4. Retry on transient failures; the connect happens during client start, so restart or trigger reconnection after fixing the network
Defensive patterns

Strategy: retry

Validate before calling

# Pre-flight network check to the Spot public stream before node start
import socket, urllib.parse
host = urllib.parse.urlparse("wss://stream.binance.com:9443").hostname
socket.getaddrinfo(host, 9443)  # raises if DNS/egress is blocked

Try / catch

Retry connect with exponential backoff and jitter; classify {e} first — DNS/timeout means infrastructure (fix egress/proxy and retry), HTTP-level blocks may require a proxy or a different network path rather than retrying.

Prevention

When it happens

Trigger: connect() on the Spot public JSON stream fails: DNS resolution failure, firewall or regional blocking of the Binance streaming endpoint, TLS interception breaking the upgrade, proxy misconfiguration, or invalid endpoint configuration.

Common situations: Running in a region where binance.com endpoints are restricted; containerized or corporate egress requiring a proxy that is not configured; transient network outage at startup.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@a4b06ed870 (2026-08-16). Data as JSON: /api/errors/bd9f95f46a2c15ce. Report an issue: GitHub.