nautechsystems/nautilus_trader · error · anyhow::Error
failed to connect Binance Futures public WebSocket
Error message
failed to connect Binance Futures public WebSocket: {e} What it means
During BinanceFuturesDataClient::connect, the secondary public WebSocket client failed to connect after the market WebSocket already connected successfully. The whole connect() call fails, so both streams must be healthy for the client to initialize.
Solutions
- Verify connectivity to the Binance Futures public WebSocket endpoint specifically
- Inspect the logged `Binance Futures public WebSocket connection failed: {e:?}` line for the root cause
- Retry the connect with backoff; the market socket already connected so a full reconnect is needed on failure
- Check that any proxy configuration applies to both WebSocket clients
Defensive patterns
Strategy: retry
Validate before calling
// both endpoints must be reachable
for host in ["fstream.binance.com:443", "fstream.binance.com:443/ws"] {
assert!(std::net::TcpStream::connect(host).is_ok(), "endpoint unreachable: {host}");
} Try / catch
match client.connect().await {
Err(e) if e.to_string().contains("public WebSocket") => {
// market socket succeeded but public failed: full reconnect needed
schedule_reconnect_with_backoff(e);
}
Err(e) => return Err(e),
Ok(()) => {},
} Prevention
- Firewall-test both WebSocket endpoints, not just one
- Apply proxy env vars consistently to all WS clients
- Treat connect() as all-or-nothing: always fully reconnect on partial failure
When it happens
Trigger: Calling connect() on the Binance Futures data client when self.ws_public_client.connect() returns Err — the same network-level failures as the market socket, but on the public data endpoint.
Common situations: Firewall allowing one endpoint but blocking the other; geo-restriction on the public endpoint; transient public-endpoint outage right after the market socket succeeded.
Understand the failure class
Background: ECONNREFUSED and "connection refused" / "could not connect to server" errors: what they mean and how to fix them — this error's family across 44 libraries.
Related errors
- failed to connect Binance Futures market WebSocket
- failed to connect Binance Futures private WebSocket
- failed to connect Binance Spot public JSON WebSocket
- failed to connect Binance Spot SBE WebSocket
- Failed to connect Spot public JSON WS
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/fefeab91476dae6e.
Report an issue: GitHub.
Appendix: source
Thrown at crates/adapters/binance/src/futures/data.rs:1580
&self.ws_public_client,
&self.data_sender,
self.clock,
false,
)
.await?;
let session_result = async {
log::info!("Connecting to Binance Futures market WebSocket...");
self.ws_client.connect().await.map_err(|e| {
log::error!("Binance Futures market WebSocket connection failed: {e:?}");
anyhow::anyhow!("failed to connect Binance Futures market WebSocket: {e}")
})?;
log::info!("Binance Futures market WebSocket connected");
log::info!("Connecting to Binance Futures public WebSocket...");
self.ws_public_client.connect().await.map_err(|e| {
log::error!("Binance Futures public WebSocket connection failed: {e:?}");
anyhow::anyhow!("failed to connect Binance Futures public WebSocket: {e}")
})?;
log::info!("Binance Futures public WebSocket connected");
let stream = self.ws_client.stream();
let sender = self.data_sender.clone();
let insts = self.instruments.clone();
let ws_insts = self.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 force_order_refs = self.force_order_refs.clone();
let ticker_refs = self.ticker_refs.clone();
let force_order_all_market_refs = self.force_order_all_market_refs.clone();
let force_order_all_market_stream_active =
self.force_order_all_market_stream_active.clone();
let book_epoch = self.book_epoch.clone();
let http = self.http_client.clone();
let clock = self.clock;View on GitHub (pinned to 18893faf8b)