{"record":{"id":"92910e82d7a5504e","repo":"nautechsystems/nautilus_trader","slug":"currency-must-be-specified","errorCode":null,"errorMessage":"Currency must be specified","messagePattern":"Currency must be specified","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/model/src/accounts/base.rs","lineNumber":113,"sourceCode":"            base_currency: self.base_currency,\n            calculate_account_state: self.calculate_account_state,\n            events: Vec::new(),\n            commissions: self.commissions.clone(),\n            balances: self.balances.clone(),\n            balances_starting: self.balances_starting.clone(),\n        }\n    }\n\n    /// Returns a reference to the `AccountBalance` for the specified currency, or `None` if absent.\n    ///\n    /// # Panics\n    ///\n    /// Panics if `currency` is `None` and `self.base_currency` is `None`.\n    #[must_use]\n    pub fn base_balance(&self, currency: Option<Currency>) -> Option<&AccountBalance> {\n        let currency = currency\n            .or(self.base_currency)\n            .expect(\"Currency must be specified\");\n        self.balances.get(&currency)\n    }\n\n    /// Returns the total `Money` balance for the specified currency, or `None` if absent.\n    ///\n    /// # Panics\n    ///\n    /// Panics if `currency` is `None` and `self.base_currency` is `None`.\n    #[must_use]\n    pub fn base_balance_total(&self, currency: Option<Currency>) -> Option<Money> {\n        self.base_balance(currency).map(|balance| balance.total)\n    }\n\n    #[must_use]\n    pub fn base_balances_total(&self) -> IndexMap<Currency, Money> {\n        self.balances\n            .iter()\n            .map(|(currency, balance)| (*currency, balance.total))","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/accounts/base.rs#L95-L131","documentation":"`base_balance(&self, currency: Option<Currency>)` on the account base resolves the currency as the argument or the account's `base_currency`; if both are `None` (e.g. a margin/multi-currency account without a base currency), `.expect(\"Currency must be specified\")` panics. This panic is explicitly documented on the method, and the derived helpers `base_balance_total`, `base_balance_free`, and `base_balance_locked` inherit it.","triggerScenarios":"Calling `base_balance(None)` (or `base_balance_total(None)` / `base_balance_free(None)` / `base_balance_locked(None)`) on an account whose `base_currency` is `None` — typical for margin accounts supporting multiple currencies.","commonSituations":"Generic reporting code passing `None` assuming every account has a default base currency; querying balances on a `MarginAccount`; using an account before its base currency was set at construction.","solutions":["Pass an explicit `Some(currency)` instead of `None` when the account may have no base currency","Check `account.base_currency()` first and fall back to per-currency `account_balance(currency)` / iterating `balances()` for multi-currency accounts","For cash accounts, construct the account with its base currency so `base_currency` is `Some`","Wrap the call if you must use it generically, or use the `balances()` map accessor instead"],"exampleFix":"// before\nlet balance = account.base_balance(None); // panics if base_currency is None\n// after\nlet balance = match account.base_currency() {\n    Some(base) => account.base_balance(Some(base)),\n    None => None, // multi-currency account: iterate account.balances() instead\n};","handlingStrategy":"type-guard","validationCode":"let currency = currency.or(account.base_currency());\nif currency.is_none() {\n    // multi-currency account: use account.balances() / account_balance(currency) instead\n    return None;\n}","typeGuard":"fn base_currency_or_none(account: &dyn Account) -> Option<Currency> { account.base_currency() }","tryCatchPattern":"match account.base_currency() {\n    Some(_) => account.base_balance(None),\n    None => None, // or iterate account.balances()\n}","preventionTips":["Never pass `None` to `base_balance*` for margin/multi-currency accounts","Check `base_currency()` before using base-balance helpers","Prefer per-currency accessors in generic reporting code","Construct cash accounts with an explicit base currency"],"tags":["panic","accounts","api-misuse"],"backgroundTag":"missing-required-argument","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"}