{"record":{"id":"ac595e1143d4f4fa","repo":"nautechsystems/nautilus_trader","slug":"binance-futures-account-state-request-failed-e","errorCode":null,"errorMessage":"Binance Futures account state request failed: {e}","messagePattern":"Binance Futures account state request failed: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"critical","filePath":"crates/adapters/binance/src/futures/execution.rs","lineNumber":469,"sourceCode":"            account_id,\n            account_type,\n            balances,\n            margins,\n            true, // reported\n            UUID4::new(),\n            ts_now,\n            ts_now,\n            None, // base currency\n        )\n        .with_info(info)\n    }\n\n    async fn refresh_account_state(&self) -> anyhow::Result<AccountState> {\n        let account_info = match self.http_client.query_account().await {\n            Ok(info) => info,\n            Err(e) => {\n                log::error!(\"Binance Futures account state request failed: {e}\");\n                anyhow::bail!(\"Binance Futures account state request failed: {e}\");\n            }\n        };\n\n        Ok(self.create_account_state(&account_info))\n    }\n\n    fn update_account_state(&self) {\n        let http_client = self.http_client.clone();\n        let account_id = self.core.account_id;\n        let account_type = self.core.account_type;\n        let bnfcr_currency = self.config.bnfcr_currency;\n        let emitter = self.emitter.clone();\n        let clock = self.clock;\n\n        self.spawn_task(\"query_account\", async move {\n            let account_info = http_client\n                .query_account()\n                .await","sourceCodeStart":451,"sourceCodeEnd":487,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/a4b06ed870971b5671d12754ea138a3ab99b1dec/crates/adapters/binance/src/futures/execution.rs#L451-L487","documentation":"refresh_account_state bails when the HTTP query_account call fails, wrapping the underlying transport/API error in a message that duplicates the log::error line above it. This runs during the execution client's connect flow, so the failure prevents the client from finishing connection and no orders can be managed until it succeeds. The meaningful detail is inside the wrapped {e}: the Binance error code for auth, timestamp, or permission problems.","triggerScenarios":"Connecting the Binance Futures execution client with invalid or futures-disabled API credentials (-2015), IP-restricted keys used off the allowlist, clock skew beyond recvWindow (-1021), network outage, or a testnet/live environment mismatch between keys and base URL.","commonSituations":"First live run with keys that lack futures permissions; testnet keys pointed at api.binance.com; NTP drift on the host; firewall blocking egress to the exchange; read-only keys where balances/trading info is restricted.","solutions":["Read the wrapped error code: -2015 invalid key/permissions, -1021 timestamp outside recvWindow, -1003 IP ban/rate limit","Verify the api_key/api_secret pair and that USD-M or COIN-M futures access is enabled for the key","Confirm the environment (Live/Testnet/Demo) matches the credentials and base URL","Sync the system clock via NTP and retry connect with backoff; check network egress to the exchange host"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Pre-flight before connect: credentials resolvable and clock in sync\nfn preflight_ok() -> bool {\n    let key_missing = std::env::var(\"BINANCE_API_KEY\").map_or(true, |v| v.is_empty());\n    // optionally GET /fapi/v1/time and compare to local clock; |delta| should be far under recvWindow (default 5s)\n    !key_missing\n}","typeGuard":null,"tryCatchPattern":"// account-state failures surface from the connect flow; retry with backoff, treat\n// auth codes (-2015) as fatal, transient network as retryable\nconst MAX: u32 = 3;\nfor attempt in 1..=MAX {\n    match client.connect().await {\n        Ok(()) => break,\n        Err(e) if attempt < MAX && !e.to_string().contains(\"-2015\") => {\n            tokio::time::sleep(std::time::Duration::from_secs(2u64.pow(attempt))).await;\n        }\n        Err(e) => return Err(e),\n    }\n}","preventionTips":["Store keys via the project's secret-resolution path (env/registry), never inline","Enable futures permissions on the API key before first connect","Run NTP on trading hosts; monitor clock delta against /fapi/v1/time","Pin environment (Live/Testnet/Demo) in one config source"],"tags":["binance-futures","account-state","authentication","connect","http","rust"],"backgroundTag":"exchange-api-request-failed","analyzedSha":"a4b06ed870971b5671d12754ea138a3ab99b1dec","analyzedAt":"2026-08-16T22:54:50.089Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}