{"record":{"id":"4c022ddc69bdb51f","repo":"nautechsystems/nautilus_trader","slug":"missing-environment-variable-secret-env","errorCode":null,"errorMessage":"Missing environment variable: {secret_env}","messagePattern":"Missing environment variable: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/deribit/src/websocket/client.rs","lineNumber":312,"sourceCode":"    /// - Mainnet: `DERIBIT_API_KEY` and `DERIBIT_API_SECRET`\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if neither the argument nor the environment variable\n    /// provides a credential.\n    pub fn with_credentials(\n        environment: DeribitEnvironment,\n        api_key: Option<String>,\n        api_secret: Option<String>,\n        auth_timeout_secs: Option<u64>,\n        proxy_url: Option<String>,\n    ) -> anyhow::Result<Self> {\n        let (key_env, secret_env) = credential_env_vars(environment);\n\n        let api_key = get_or_env_var_opt(api_key, key_env)\n            .ok_or_else(|| anyhow::anyhow!(\"Missing environment variable: {key_env}\"))?;\n        let api_secret = get_or_env_var_opt(api_secret, secret_env)\n            .ok_or_else(|| anyhow::anyhow!(\"Missing environment variable: {secret_env}\"))?;\n\n        Self::new(\n            None,\n            Some(api_key),\n            Some(api_secret),\n            DERIBIT_WS_HEARTBEAT_SECS,\n            auth_timeout_secs,\n            environment,\n            TransportBackend::default(),\n            proxy_url,\n        )\n    }\n\n    /// Returns the current connection mode.\n    fn connection_mode(&self) -> ConnectionMode {\n        let mode_u8 = self.connection_mode.load().load(Ordering::Relaxed);\n        ConnectionMode::from_u8(mode_u8)\n    }","sourceCodeStart":294,"sourceCodeEnd":330,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/deribit/src/websocket/client.rs#L294-L330","documentation":"with_credentials resolves the API secret from the provided value or from the environment-specific secret variable (e.g. DERIBIT_TESTNET_API_SECRET). When both the explicit api_secret argument and the environment variable are absent, authenticated construction fails. The API key may be present, but the client cannot authenticate without the secret.","triggerScenarios":"Calling with_credentials with a key supplied (or key env var set) but no api_secret argument and the secret env var unset in the process environment.","commonSituations":"Setting only DERIBIT_API_KEY but forgetting DERIBIT_API_SECRET, .env files loaded after client construction, secrets not mounted in containers, or testnet secret variable used while environment is production (or vice versa).","solutions":["Export the required secret variable (e.g. `export DERIBIT_API_SECRET=...`) before process start.","Pass the api_secret explicitly as the second argument to with_credentials.","Verify both key and secret environment variables match the configured environment (testnet vs mainnet)."],"exampleFix":"// before\nlet client = DeribitWebSocketClient::with_credentials(Some(key), None, None, environment, ...).await?;\n// after\nlet secret = std::env::var(\"DERIBIT_API_SECRET\")?; // or pass Some(secret)\nlet client = DeribitWebSocketClient::with_credentials(Some(key), Some(secret), None, environment, ...).await?;","handlingStrategy":"validation","validationCode":"// Rust: ensure both key and secret are set before connecting\nstd::env::var(\"DERIBIT_API_SECRET\")\n    .map_err(|_| anyhow!(\"set DERIBIT_API_SECRET (or pass api_secret) before connecting\"))?;","typeGuard":"fn secret_env_present(environment: Environment) -> bool {\n    let (_, secret_env) = credential_env_vars(environment);\n    std::env::var(secret_env).is_ok()\n}","tryCatchPattern":"let client = match DeribitWebSocketClient::with_credentials(Some(key), None, None, env, ...).await {\n    Ok(c) => c,\n    Err(e) if e.to_string().contains(\"Missing environment variable\") => {\n        return Err(anyhow!(\"configure {}\", e))\n    }\n    Err(e) => return Err(e),\n};","preventionTips":["Always set both key and secret variables as a pair","Load .env before any adapter initialization","Keep testnet and mainnet secrets in separate, clearly named variables","Run a startup config check that asserts both credential vars exist"],"tags":["configuration","environment","credentials","rust"],"backgroundTag":"missing-env-var","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}