nautechsystems/nautilus_trader · error

No session token for race stream

Error message

No session token for race stream

What it means

When setting up the optional Betfair race stream, the client needs the current session token again to authenticate that stream. session_token() returned None at that point, so this error is raised. It means the race stream cannot be opened without valid stream authentication.

Solutions

  1. Verify the main login session token exists before enabling the race stream (check http_client.session_token() prior to connect completing)
  2. Shorten the time between login and stream setup (reduce provider.load_all latency) to avoid session expiry mid-connect
  3. Ensure no concurrent disconnect/token-clear runs during connect
  4. Re-authenticate (retry connect) if the session expired
Defensive patterns

Strategy: retry

Validate before calling

// only enable race stream when a session token is present
if enable_race_stream && client.session_token().await.is_none() {
    // re-authenticate before attempting connect with race stream enabled
}

Try / catch

match client.connect().await {
    Err(e) if e.to_string().contains("No session token for race stream") => {
        log::warn!("race 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 race-stream setup branch, self.http_client.session_token().await returns None even though the main connect flow previously required a token; ok_or_else raises this error. Implies the token was cleared/expired or never stored between main stream setup and race stream setup.

Common situations: Session expired mid-connect (long-running instrument load before race stream setup); concurrent disconnect clearing the token; Betfair login returned a token for the main stream but state got reset; enabling race stream config without stable session handling.

Related errors


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

Appendix: source

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

        self.stream_client = Some(stream_client);
        self.stream_shutdowns
            .lock()
            .push(BetfairStreamShutdown::Exchange(Arc::clone(
                self.stream_client.as_ref().expect("stream client assigned"),
            )));

        let session_result = async {
            if self.config.subscribe_race_data {
                let race_config = BetfairStreamConfig {
                    host: BETFAIR_RACE_STREAM_HOST.to_string(),
                    ..self.stream_config.clone()
                };

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

                let race_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 (race_fatal_tx, mut race_fatal_rx) = tokio::sync::mpsc::unbounded_channel();

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

                match BetfairRaceStreamClient::connect_decoded(

View on GitHub (pinned to 18893faf8b)