nautechsystems/nautilus_trader · error · anyhow::Error

Tardis Machine `base_url` must be provided or set in the '{T

Error message

Tardis Machine `base_url` must be provided or set in the '{TARDIS_MACHINE_WS_URL}' environment variable

What it means

The Tardis adapter needs the Tardis Machine WebSocket URL to stream data. `resolve_ws_base_url` resolves it from the explicit `url` argument first, then from the `TARDIS_MACHINE_WS_URL` environment variable. If neither is present there is no connection target, so the library fails fast with this error instead of attempting a connection to an undefined host.

Source

Thrown at crates/adapters/tardis/src/common/urls.rs:33

//! Tardis base URL constants and environment-aware resolution.

use super::consts::TARDIS_MACHINE_WS_URL;

/// Default Tardis REST API base URL.
pub const TARDIS_HTTP_BASE_URL: &str = "https://api.tardis.dev/v1";

/// Resolves the Tardis Machine WebSocket base URL from an explicit value or the
/// `TARDIS_MACHINE_WS_URL` environment variable.
///
/// # Errors
///
/// Returns an error if neither `url` nor the environment variable is set.
pub fn resolve_ws_base_url(url: Option<&str>) -> anyhow::Result<String> {
    url.map(ToString::to_string)
        .or_else(|| std::env::var(TARDIS_MACHINE_WS_URL).ok())
        .ok_or_else(|| {
            anyhow::anyhow!(
                "Tardis Machine `base_url` must be provided or \
                 set in the '{TARDIS_MACHINE_WS_URL}' environment variable"
            )
        })
}

#[cfg(test)]
mod tests {
    use rstest::rstest;

    use super::*;

    #[rstest]
    fn test_resolve_ws_base_url_with_explicit_value() {
        let result = resolve_ws_base_url(Some("ws://localhost:8001")).unwrap();
        assert_eq!(result, "ws://localhost:8001");
    }

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Pass the Tardis Machine URL explicitly, e.g. `resolve_ws_base_url(Some("ws://localhost:8000"))` or set `base_url` in the client config.
  2. Export the environment variable before running: `export TARDIS_MACHINE_WS_URL=ws://localhost:8000`.
  3. If running under Docker/CI, ensure the env var is forwarded (e.g. `docker run -e TARDIS_MACHINE_WS_URL=...`).
  4. Confirm a Tardis Machine instance is actually reachable at the URL you supply.

Example fix

// before
let url = resolve_ws_base_url(None)?;
// after
let url = resolve_ws_base_url(Some("ws://localhost:8000"))?;
// or: export TARDIS_MACHINE_WS_URL=ws://localhost:8000 before running
Defensive patterns

Strategy: validation

Validate before calling

import os

def ensure_tardis_url(base_url: str | None) -> str:
    url = base_url or os.environ.get("TARDIS_MACHINE_WS_URL")
    if not url:
        raise ValueError("Tardis Machine URL must be provided or TARDIS_MACHINE_WS_URL set")
    return url

Type guard

def has_tardis_url(base_url: str | None) -> bool:
    return bool(base_url or os.environ.get("TARDIS_MACHINE_WS_URL"))

Prevention

When it happens

Trigger: Calling `connect` or `new` on the Tardis data client (or any path calling `resolve_ws_base_url`) without passing a `base_url`/`url` argument and without `TARDIS_MACHINE_WS_URL` set in the process environment.

Common situations: Running in a container or CI job where the env var was not forwarded; forgetting the config field when instantiating the client programmatically; a version change that removed a previously hardcoded default URL so an explicit value is now required.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


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