nautechsystems/nautilus_trader · error

Invalid Betfair credentials: username provided but password…

Error message

Invalid Betfair credentials: username provided but password is missing

What it means

Betfair adapter credential resolution builds a Credential from config values or environment variables. If a username is present but no password, CredentialError::MissingPassword is mapped to this anyhow error in resolve_credential. The adapter refuses to start with a partially specified credential set.

Solutions

  1. Set the password in the config (betfair.password) or export BETFAIR_PASSWORD before starting the node
  2. Verify the env var name is exactly BETFAIR_PASSWORD and it is visible to the process (source the .env, check container env)
  3. If you intend key-only auth, remove the username instead of leaving a partial credential set

Example fix

// before (shell)
export BETFAIR_USERNAME=myuser
# after
export BETFAIR_USERNAME=myuser
export BETFAIR_PASSWORD=secret
export BETFAIR_APP_KEY=myappkey
Defensive patterns

Strategy: validation

Validate before calling

if username_set && password.is_none() {
    return Err(anyhow!("Betfair username provided but password is missing"));
}

Type guard

fn has_complete_creds(u: Option<&str>, p: Option<&str>, k: Option<&str>) -> bool {
    u.is_some() == p.is_some() || k.is_some()
}

Try / catch

match resolve_credential(cfg) {
    Ok(c) => c,
    Err(e) if e.to_string().contains("password is missing") => {
        eprintln!("set BETFAIR_PASSWORD"); std::process::exit(1);
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: resolve_credential is called (via credential()) during BetfairDataConfig/BetfairExecutionClientConfig credential resolution when username (from config or BETFAIR_USERNAME env) is set but password is neither in config nor BETFAIR_PASSWORD env.

Common situations: Setting BETFAIR_USERNAME but forgetting BETFAIR_PASSWORD in the environment or .env file; providing credentials in a TOML config and omitting the password field; rotating secrets and removing the password entry.

Related errors


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

Appendix: source

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

    }

    Ok(())
}

fn resolve_credential(
    username: Option<SecretString>,
    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,

View on GitHub (pinned to 18893faf8b)