nautechsystems/nautilus_trader · error

No session token for cricket stream

Error message

No session token for cricket stream

What it means

Same pattern as the race stream: setting up the optional cricket stream requires re-fetching the session token, and session_token() returned None. The cricket stream cannot authenticate without it, so connect aborts with this error.

Solutions

  1. Confirm a valid session token exists before cricket stream setup
  2. Reduce latency between login and cricket stream setup; re-authenticate if the session expires
  3. Prevent concurrent disconnect/token-clear during connect
  4. Retry the full connect to obtain a fresh session token
Defensive patterns

Strategy: retry

Validate before calling

// only enable cricket stream when a session token is present
if enable_cricket_stream && client.session_token().await.is_none() {
    // re-authenticate before connect
}

Try / catch

match client.connect().await {
    Err(e) if e.to_string().contains("No session token for cricket stream") => {
        log::warn!("cricket stream auth token missing; re-authenticating");
        tokio::time::sleep(Duration::from_secs(1)).await;
        client.connect().await
    }
    other => other,
}

Prevention

When it happens

Trigger: connect() -> inside the cricket-stream setup branch, self.http_client.session_token().await returns None; ok_or_else raises this error. Occurs when the session token expired or was cleared after the main stream was established but before cricket stream setup.

Common situations: Slow instrument loading/long connect sequence letting the Betfair session expire; concurrent disconnect; cricket stream enabled in config with an unstable session.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/a6e1581091a6bdf6. Report an issue: GitHub.

Appendix: source

Thrown at crates/adapters/betfair/src/data.rs:909

                        if let Some(control) = &self.race_socket_control {
                            control.deregister();
                        }
                        self.race_stream_client = None;
                    }
                }
            }

            if self.config.subscribe_cricket_data {
                let cricket_config = BetfairStreamConfig {
                    host: BETFAIR_RACE_STREAM_HOST.to_string(),
                    ..self.stream_config.clone()
                };

                let cricket_session = self
                    .http_client
                    .session_token()
                    .await
                    .ok_or_else(|| anyhow::anyhow!("No session token for cricket stream"))?;

                let cricket_handler = Self::create_stream_handler(
                    self.data_sender.clone(),
                    Arc::clone(&self.instruments),
                    self.currency,
                    self.provider.min_notional(),
                    reconnect_tx.clone(),
                    self.clock,
                );

                let (cricket_fatal_tx, mut cricket_fatal_rx) =
                    tokio::sync::mpsc::unbounded_channel();

                let state_sink = self
                    .cricket_socket_control
                    .as_ref()
                    .map(|control| control.sink());

View on GitHub (pinned to 18893faf8b)