nautechsystems/nautilus_trader · error · anyhow::Error

failed to connect Binance Spot SBE WebSocket: {e}

Error message

failed to connect Binance Spot SBE WebSocket: {e}

What it means

The Binance Spot SBE (Simple Binary Encoding) market data WebSocket failed to connect. Unlike the Futures variant, this error preserves the underlying cause in {e} and also logs it in Debug form, so the message itself tells you whether it is authentication, network, or endpoint related.

Source

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

        Self::refresh_instrument_catalogue(
            &self.http_client,
            &self.config.instrument_provider,
            self.config.us,
            &self.instruments,
            &self.status_cache,
            &self.ws_client,
            &self.data_sender,
            self.clock,
            false,
        )
        .await?;

        match &mut self.ws_client {
            SpotWsClient::Sbe(ws_client) => {
                log::info!("Connecting to Binance Spot SBE WebSocket...");
                ws_client.connect().await.map_err(|e| {
                    log::error!("Binance Spot SBE WebSocket connection failed: {e:?}");
                    anyhow::anyhow!("failed to connect Binance Spot SBE WebSocket: {e}")
                })?;
                log::info!("Binance Spot SBE 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} in the message: 401/403-style errors mean credential problems, timeouts mean network reachability
  2. Verify the Ed25519 keypair works by performing a signed REST request with the same key
  3. Check egress and proxy settings toward the Binance Spot SBE WebSocket endpoint
  4. If SBE is unavailable for your account/region, fall back to spot_market_data_mode = Json
Defensive patterns

Strategy: retry

Validate before calling

# Pre-flight: a signed REST call with the Ed25519 key validates credentials
# before the SBE WS connect is attempted
resp = requests.get(
    "https://api.binance.com/api/v3/account",
    headers={"X-MBX-APIKEY": api_key},
    params=signed_params(ed25519_key),
    timeout=10,
)
resp.raise_for_status()

Try / catch

On connect failure, inspect {e} from the message: credential errors (401/403) should fail fast with an operator alert; network timeouts can retry with exponential backoff. Persistent SBE unavailability can fall back to spot_market_data_mode = Json.

Prevention

When it happens

Trigger: connect() on the Spot SBE market data stream errors: invalid or wrong-type API credentials (SBE requires the Ed25519 keypair), rejected authentication, unreachable/blocked SBE WebSocket endpoint, TLS or proxy problems, or a Binance-side outage of the SBE service.

Common situations: Using an HMAC key instead of Ed25519 for SBE; expired or deleted API key; egress firewall blocking the SBE endpoint; proxy misconfiguration; SBE access unavailable for the account or region.

Related errors


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