{"record":{"id":"1b1d77341fe66d3e","repo":"nautechsystems/nautilus_trader","slug":"commission-total-exceeded-money-bounds","errorCode":null,"errorMessage":"commission total exceeded Money bounds","messagePattern":"commission total exceeded Money bounds","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/model/src/accounts/base.rs","lineNumber":196,"sourceCode":"    /// Note: This method does NOT validate negative balances. Derived account types\n    /// (`CashAccount`, `MarginAccount`) should perform their own validation in `apply()`:\n    /// - `MarginAccount`: allows negative balances (normal for margin trading)\n    /// - `CashAccount`: rejects negative unless `allow_borrowing` is true\n    pub fn update_balances(&mut self, balances: &[AccountBalance]) {\n        for balance in balances {\n            self.balances.insert(balance.currency, *balance);\n        }\n    }\n\n    /// Updates the account commissions with the provided amount.\n    ///\n    /// # Panics\n    ///\n    /// Panics if the accumulated commission exceeds [`Money`] bounds. Operational callers should\n    /// use [`Self::try_update_commissions`] when the input is not already known to fit.\n    pub fn update_commissions(&mut self, commission: Money) {\n        self.try_update_commissions(commission)\n            .expect(\"commission total exceeded Money bounds\");\n    }\n\n    /// Updates the account commissions with the provided amount.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the accumulated commission exceeds [`Money`] bounds.\n    pub fn try_update_commissions(&mut self, commission: Money) -> anyhow::Result<()> {\n        // TODO: Remove once from_raw enforces canonical precision alignment (v2)\n        let commission = commission.normalized();\n        if commission.is_zero() {\n            return Ok(());\n        }\n        let currency = commission.currency;\n        let total = self\n            .commissions\n            .get(&currency)\n            .copied()","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/accounts/base.rs#L178-L214","documentation":"`update_commissions` delegates to `try_update_commissions` and unwraps with `.expect(\"commission total exceeded Money bounds\")`. It panics when the accumulated commission total plus the new commission exceeds the representable range of the fixed-precision `Money` type. The doc comment states operational callers should use `try_update_commissions` when the input is not already known to fit; this method is intended for already-validated inputs.","triggerScenarios":"Calling `update_commissions` repeatedly on a long-lived account until the running total overflows `Money`'s raw bounds, or passing a single enormous commission amount (e.g. from a malformed venue report) that pushes the total out of range.","commonSituations":"Long-running high-frequency sessions accumulating commissions without bound; buggy venue adapters reporting absurd fee values; token-denominated crypto fees whose precision scaling inflates the raw fixed-point value beyond bounds.","solutions":["Use `try_update_commissions` and handle the `Result`/error instead of `update_commissions` when the input is not pre-validated","Cap or sanity-check incoming commission amounts (reject values from the venue beyond plausible bounds) before applying them","Audit the venue adapter producing the commission for precision/currency-denomination mistakes","Reset or reconcile the account commission state if a corrupted accumulated total is causing the overflow"],"exampleFix":"// before\naccount.update_commissions(commission); // panics on Money overflow\n// after\nif let Err(e) = account.try_update_commissions(commission) {\n    log::error!(\"failed to apply commission: {e}\");\n}","handlingStrategy":"try-catch","validationCode":"if let Err(e) = account.try_update_commissions(commission) {\n    log::error!(\"commission update failed: {e}\");\n}","typeGuard":null,"tryCatchPattern":"account.try_update_commissions(commission)\n    .unwrap_or_else(|e| log::error!(\"failed to apply commission: {e}\"));","preventionTips":["Prefer `try_update_commissions` over `update_commissions` unless inputs are pre-validated","Sanity-cap commission values accepted from venue reports","Audit adapters for precision scaling that inflates raw Money values","Monitor accumulated commission totals on long-running accounts"],"tags":["panic","overflow","accounts","money"],"backgroundTag":"value-out-of-range","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"}