{"record":{"id":"6943ddd636e3fa32","repo":"nautechsystems/nautilus_trader","slug":"standard-key-var-not-found-in-config-or-environm","errorCode":null,"errorMessage":"{standard_key_var} not found in config or environment","messagePattern":"(.+?) not found in config or environment","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/common/credential.rs","lineNumber":100,"sourceCode":"            BinanceEnvironment::Live => (\n                \"BINANCE_ED25519_API_KEY\",\n                \"BINANCE_ED25519_API_SECRET\",\n                \"BINANCE_API_KEY\",\n                \"BINANCE_API_SECRET\",\n            ),\n        };\n\n    // Futures: soft deprecation (warn + fallback),\n    // Spot/Margin: hard error on removed env vars.\n    let is_futures = matches!(\n        product_type,\n        BinanceProductType::UsdM | BinanceProductType::CoinM\n    );\n\n    let api_key = config_api_key\n        .or_else(|| std::env::var(standard_key_var).ok())\n        .or_else(|| resolve_deprecated_var(deprecated_key_var, standard_key_var, is_futures))\n        .ok_or_else(|| anyhow::anyhow!(\"{standard_key_var} not found in config or environment\"))?;\n\n    let api_secret = config_api_secret\n        .or_else(|| std::env::var(standard_secret_var).ok())\n        .or_else(|| resolve_deprecated_var(deprecated_secret_var, standard_secret_var, is_futures))\n        .ok_or_else(|| {\n            anyhow::anyhow!(\"{standard_secret_var} not found in config or environment\")\n        })?;\n\n    Ok((api_key, api_secret))\n}\n\nfn resolve_deprecated_var(\n    deprecated_var: &str,\n    standard_var: &str,\n    allow_fallback: bool,\n) -> Option<String> {\n    if deprecated_var.is_empty() {\n        return None;","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/a4b06ed870971b5671d12754ea138a3ab99b1dec/crates/adapters/binance/src/common/credential.rs#L82-L118","documentation":"resolve_credentials could not find a Binance API key in either the client config or the standard environment variable named in the message (live: BINANCE_API_KEY; spot/margin/options testnet: BINANCE_TESTNET_API_KEY; futures testnet: BINANCE_FUTURES_TESTNET_API_KEY; demo: BINANCE_DEMO_API_KEY). The adapter refuses to create a client without credentials.","triggerScenarios":"Building a Binance data/execution client with no api_key in the config while the exact env var for the configured environment+product_type combination is unset - e.g. only BINANCE_FUTURES_TESTNET_API_KEY is exported but the client is Spot testnet, or a live client with no BINANCE_API_KEY.","commonSituations":"Forgot to export the variable or it lives only in an unloaded .env; CI/deploy environment not passing secrets; copied config between live/testnet without changing env var names; still relying on removed *_ED25519_* variables, which spot/margin reject and futures only fall back from with a warning.","solutions":["Export the exact variable named in the message: export BINANCE_API_KEY=... (and the matching _API_SECRET)","Verify the variable name matches environment+product type: live=BINANCE_API_KEY, spot testnet=BINANCE_TESTNET_API_KEY, futures testnet=BINANCE_FUTURES_TESTNET_API_KEY, demo=BINANCE_DEMO_API_KEY","Alternatively pass api_key/api_secret directly in the BinanceDataClientConfig / execution client config","Migrate any deprecated BINANCE*_ED25519_API_KEY variables to the standard names"],"exampleFix":"# before\nexport BINANCE_FUTURES_TESTNET_API_KEY=...   # spot testnet client still fails\n\n# after\nexport BINANCE_TESTNET_API_KEY=...\nexport BINANCE_TESTNET_API_SECRET=...","handlingStrategy":"validation","validationCode":"fn required_env(name: &str) -> anyhow::Result<String> {\n    std::env::var(name).map_err(|_| anyhow::anyhow!(\"{name} not set - export it or pass credentials in config\"))\n}\nlet _ = required_env(\"BINANCE_API_KEY\")?;      // adjust per environment/product\nlet _ = required_env(\"BINANCE_API_SECRET\")?;","typeGuard":"fn binance_key_var(env: BinanceEnvironment, pt: BinanceProductType) -> &'static str {\n    match (env, pt) {\n        (BinanceEnvironment::Live, _) => \"BINANCE_API_KEY\",\n        (BinanceEnvironment::Demo, _) => \"BINANCE_DEMO_API_KEY\",\n        (BinanceEnvironment::Testnet, BinanceProductType::UsdM | BinanceProductType::CoinM) => \"BINANCE_FUTURES_TESTNET_API_KEY\",\n        (BinanceEnvironment::Testnet, _) => \"BINANCE_TESTNET_API_KEY\",\n    }\n}","tryCatchPattern":"if let Err(e) = resolve_credentials(None, None, environment, product_type) {\n    eprintln!(\"Binance credentials missing: {e}. Check env vars for {environment}/{product_type}.\");\n    std::process::exit(1);\n}","preventionTips":["Fail fast at process start: assert required env vars before building clients","Encode the environment/product -> env-var-name mapping in one helper so configs never reference wrong names","Use a secrets manager or .env loaded at startup; never assume the shell that ran tests also runs production"],"tags":["binance","credentials","environment-variables","configuration","startup"],"backgroundTag":"missing-api-credentials","analyzedSha":"a4b06ed870971b5671d12754ea138a3ab99b1dec","analyzedAt":"2026-08-16T22:54:50.089Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}