{"record":{"id":"6ee37648012c132d","repo":"nautechsystems/nautilus_trader","slug":"cannot-update-currency-reservation-precision","errorCode":null,"errorMessage":"Cannot update {currency} reservation: precision {} differed from balance precision {}","messagePattern":"Cannot update (.+?) reservation: precision (.+?) differed from balance precision (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/model/src/accounts/base.rs","lineNumber":442,"sourceCode":"/// or the reservations cannot produce a valid balance. Balances and reservations are left\n/// unchanged when an error is returned.\npub(crate) fn update_balance_locked(\n    balances: &mut IndexMap<Currency, AccountBalance>,\n    balances_locked: &mut AHashMap<(InstrumentId, Currency), Money>,\n    instrument_id: InstrumentId,\n    locked: Money,\n) -> anyhow::Result<()> {\n    anyhow::ensure!(locked.raw >= 0, \"locked balance was negative: {locked}\");\n\n    let currency = locked.currency;\n    let key = (instrument_id, currency);\n\n    let Some(current_balance) = balances.get(&currency).copied() else {\n        balances_locked.insert(key, locked);\n        return Ok(());\n    };\n\n    anyhow::ensure!(\n        current_balance.currency.precision == currency.precision,\n        \"Cannot update {currency} reservation: precision {} differed from balance precision {}\",\n        currency.precision,\n        current_balance.currency.precision\n    );\n\n    let previous = balances_locked.insert(key, locked);\n\n    match balance_from_locks(current_balance, balances_locked) {\n        Ok(balance) => {\n            balances.insert(currency, balance);\n            Ok(())\n        }\n        Err(e) => {\n            // Restore the prior reservation so a rejected update leaves nothing behind\n            match previous {\n                Some(previous) => balances_locked.insert(key, previous),\n                None => balances_locked.remove(&key),","sourceCodeStart":424,"sourceCodeEnd":460,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/accounts/base.rs#L424-L460","documentation":"A balance reservation for a currency must have the same decimal precision as the account's existing balance in that currency; a differing precision would corrupt the balance arithmetic. The guard rejects the reservation update when `locked.currency.precision` differs from the current balance currency's precision.","triggerScenarios":"Calling update_balance_locked with a Money whose currency carries a different precision than the precision of the account's existing balance for that currency (e.g. BTC with 8 vs 6 digits, or USD 2 vs 0).","commonSituations":"Adapters reporting balances/reservations with different decimal precision than the configured account currency, currency objects constructed ad hoc with the wrong precision, or mixing custom Currency instances with the canonical ones.","solutions":["Construct the locked Money using the same Currency instance/precision as the account balance (use Currency.from_str or the canonical currency)","Normalize adapter-reported precision to the account's precision before reserving","Check the account's balance snapshot to confirm the precision the account expects"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if locked.currency.precision != balances[locked.currency].currency.precision:\n    locked = Money(locked.as_decimal(), balances[locked.currency].currency)","typeGuard":null,"tryCatchPattern":"try:\n    update_balance_locked(balances, locks, instrument_id, locked)\nexcept Exception as e:\n    log.warning(f\"reservation rejected: {e}\")","preventionTips":["Always build Money from the canonical Currency instance","Normalize adapter precision to account precision on ingest","Avoid ad-hoc Currency constructions with custom precision"],"tags":["rust","precision","currency"],"backgroundTag":"type-mismatch","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}