nautechsystems/nautilus_trader · error

Invalid Betfair credentials: app key is missing

Error message

Invalid Betfair credentials: app key is missing

What it means

Raised by the Betfair credential resolver when the application key is absent: CredentialError::MissingAppKey mapped to this message. Betfair requires an app key for API access, so config resolution fails without it.

Solutions

  1. Set app_key in the config credentials section or export the corresponding env var
  2. Request/obtain an application key from your Betfair account if you don't have one
  3. Verify the env var name matches what the adapter expects

Example fix

// before
[credentials]
username = "me"
password = "..."
// after
[credentials]
username = "me"
password = "..."
app_key = "..."  # or export env var
Defensive patterns

Strategy: validation

Validate before calling

// Before constructing config
if username.is_some() && app_key.is_none() {
    panic!("app key is missing — request one from Betfair or set the env var");
}

Try / catch

if let Err(e) = build_config() {
    if e.to_string().contains("app key is missing") {
        eprintln!("Set Betfair application key in config or environment");
    }
    return Err(e);
}

Prevention

When it happens

Trigger: Username/password provided (possibly from env) but app_key missing in both config and environment.

Common situations: New Betfair accounts that haven't requested an app key; forgetting to export the app-key env var in CI/production; app key delayed by Betfair approval process.

Understand the failure class

Background: "API key is required" / "API key not found" / "No API key was set": the missing-api-key error family across 16 libraries — this error's family across 16 libraries.

Related errors


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

Appendix: source

Thrown at crates/adapters/betfair/src/config.rs:82

    password: Option<SecretString>,
    app_key: Option<SecretString>,
) -> anyhow::Result<BetfairCredential> {
    match BetfairCredential::resolve(
        username.map(SecretString::into_inner),
        password.map(SecretString::into_inner),
        app_key.map(SecretString::into_inner),
    ) {
        Ok(Some(credential)) => Ok(credential),
        Ok(None) => anyhow::bail!("Missing Betfair credentials in config and environment"),
        Err(e) => Err(match e {
            CredentialError::MissingPassword => anyhow::anyhow!(
                "Invalid Betfair credentials: username provided but password is missing",
            ),
            CredentialError::MissingUsername => anyhow::anyhow!(
                "Invalid Betfair credentials: password or app key provided but username is missing",
            ),
            CredentialError::MissingAppKey => {
                anyhow::anyhow!("Invalid Betfair credentials: app key is missing")
            }
        }),
    }
}

fn build_stream_config(
    stream_host: &Option<String>,
    stream_port: &Option<u16>,
    stream_heartbeat_secs: Option<u64>,
    stream_heartbeat_timeout_secs: Option<u64>,
    stream_reconnect_delay_initial_ms: u64,
    stream_reconnect_delay_max_ms: u64,
    stream_use_tls: bool,
) -> BetfairStreamConfig {
    let defaults = BetfairStreamConfig::default();

    BetfairStreamConfig {
        host: stream_host.clone().unwrap_or(defaults.host),

View on GitHub (pinned to 18893faf8b)