{"record":{"id":"f95e9853d879f2d8","repo":"nautechsystems/nautilus_trader","slug":"no-margin-data-returned-from-bitmex","errorCode":null,"errorMessage":"No margin data returned from BitMEX","messagePattern":"No margin data returned from BitMEX","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/bitmex/src/http/client.rs","lineNumber":1608,"sourceCode":"                Decimal::from(margin_msg.maint_margin.unwrap_or(0).max(0)) / divisor;\n\n            if !initial_dec.is_zero() || !maintenance_dec.is_zero() {\n                let currency = balance.total.currency;\n                // BitMEX reports cross-margin aggregates per collateral currency.\n                margins_vec.push(MarginBalance::new(\n                    Money::from_decimal(initial_dec, currency)\n                        .unwrap_or_else(|_| Money::zero(currency)),\n                    Money::from_decimal(maintenance_dec, currency)\n                        .unwrap_or_else(|_| Money::zero(currency)),\n                    None,\n                ));\n            }\n\n            balances.push(balance);\n        }\n\n        if balances.is_empty() {\n            anyhow::bail!(\"No margin data returned from BitMEX\");\n        }\n\n        let account_type = AccountType::Margin;\n        let is_reported = true;\n        let event_id = UUID4::new();\n\n        // Use server timestamp if available, otherwise fall back to local time\n        let ts_event = latest_timestamp.map_or(ts_init, |ts| {\n            UnixNanos::from(u64::try_from(ts.as_nanosecond()).unwrap_or_default())\n        });\n\n        Ok(AccountState::new(\n            account_id,\n            account_type,\n            balances,\n            margins_vec,\n            is_reported,\n            event_id,","sourceCodeStart":1590,"sourceCodeEnd":1626,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/bitmex/src/http/client.rs#L1590-L1626","documentation":"When building an account state, request_account_statre collects margin/balance data from the BitMEX /user/margin response; if no margin rows were converted into balances, it bails because an account state cannot be constructed without any balance data.","triggerScenarios":"Calling request_account_state for a currency/account whose BitMEX margin response is empty or whose rows all fail conversion so `balances` ends up empty.","commonSituations":"Querying an account with no positions or wallet in the requested currency; wrong currency code; API returning an empty margin array for an unverified/unfunded account.","solutions":["Verify the account has funds/margin for the requested currency on BitMEX","Check the currency/instrument ID used in the request","Inspect the raw HTTP response for empty /user/margin payloads and confirm API credentials and account status"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match client.request_account_state(currency).await {\n    Ok(state) => state,\n    Err(e) if e.to_string().contains(\"No margin data\") => {\n        log::warn!(\"no margin data for {currency}; skipping account state\");\n        Default::default()\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Confirm the BitMEX account holds margin in the requested currency","Check that /user/margin returns data for the account before polling","Handle unfunded/new accounts explicitly"],"tags":["rust","bitmex","account-state","empty-response"],"backgroundTag":"empty-result-set","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"}