{"record":{"id":"3a3408f7790d7e43","repo":"nautechsystems/nautilus_trader","slug":"commission-calculation-overflow-3a3408","errorCode":null,"errorMessage":"commission calculation overflow","messagePattern":"commission calculation overflow","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/model/src/accounts/base.rs","lineNumber":409,"sourceCode":"        use_quote_for_inverse: Option<bool>,\n    ) -> anyhow::Result<Money> {\n        anyhow::ensure!(\n            liquidity_side != LiquiditySide::NoLiquiditySide,\n            \"Invalid `LiquiditySide`: {liquidity_side}\"\n        );\n        let notional =\n            instrument.try_calculate_notional_value(last_qty, last_px, use_quote_for_inverse)?;\n        let rate = match liquidity_side {\n            LiquiditySide::Maker => instrument.maker_fee(),\n            LiquiditySide::Taker => instrument.taker_fee(),\n            LiquiditySide::NoLiquiditySide => {\n                anyhow::bail!(\"Invalid `LiquiditySide`: {liquidity_side}\")\n            }\n        };\n        let commission = notional\n            .as_decimal()\n            .checked_mul(rate)\n            .ok_or_else(|| anyhow::anyhow!(\"commission calculation overflow\"))?;\n\n        Ok(Money::from_decimal(commission, notional.currency)?)\n    }\n}\n\n/// Updates the locked balance for the given instrument and currency, then recalculates the\n/// account balance for that currency from all per-(instrument, currency) locks.\n///\n/// The reservation is recorded without a balance when the currency has no observed balance yet,\n/// so a later balance report derives from it.\n///\n/// # Errors\n///\n/// Returns an error if `locked` is negative, its precision differs from the balance precision,\n/// 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>,","sourceCodeStart":391,"sourceCodeEnd":427,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/accounts/base.rs#L391-L427","documentation":"While computing commission as notional * rate in Decimal space, the checked multiplication overflowed, meaning the operands are too large for the Decimal representation. The library bails instead of producing a silently wrong commission.","triggerScenarios":"Calling base_calculate_commission with a notional value and commission rate whose product exceeds Decimal bounds — pathological prices/quantities or a wildly wrong rate.","commonSituations":"Misconfigured commission rate (e.g. percentage passed as 25 instead of 0.0025) combined with large notional, or corrupted price/quantity data from an adapter.","solutions":["Verify the commission rate is a fraction (e.g. 0.0002) not a percentage","Check that instrument price/quantity used for the notional are correct and within exchange norms","Scale down or validate inputs before calling calculate_commission"],"exampleFix":"// before\nrate = Decimal(\"25\")  # percent mistaken as fraction\n// after\nrate = Decimal(\"0.0025\")","handlingStrategy":"validation","validationCode":"notional = qty.as_decimal() * px.as_decimal()\nif notional * rate > Decimal('1e30'):\n    raise ValueError('commission operands out of plausible range')","typeGuard":null,"tryCatchPattern":"try:\n    commission = account.calculate_commission(instrument, qty, px, side, None)\nexcept Exception as e:\n    log.error(f\"commission overflow: {e}\")","preventionTips":["Keep rates as small Decimal fractions","Validate prices/quantities against exchange tick/lot limits","Flag implausible notionals before commission calculation"],"tags":["rust","overflow","decimal-arithmetic"],"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"}