nautechsystems/nautilus_trader · error

commission total exceeded Money bounds

Error message

commission total exceeded Money bounds

What it means

`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.

Source

Thrown at crates/model/src/accounts/base.rs:196

    /// Note: This method does NOT validate negative balances. Derived account types
    /// (`CashAccount`, `MarginAccount`) should perform their own validation in `apply()`:
    /// - `MarginAccount`: allows negative balances (normal for margin trading)
    /// - `CashAccount`: rejects negative unless `allow_borrowing` is true
    pub fn update_balances(&mut self, balances: &[AccountBalance]) {
        for balance in balances {
            self.balances.insert(balance.currency, *balance);
        }
    }

    /// Updates the account commissions with the provided amount.
    ///
    /// # Panics
    ///
    /// Panics if the accumulated commission exceeds [`Money`] bounds. Operational callers should
    /// use [`Self::try_update_commissions`] when the input is not already known to fit.
    pub fn update_commissions(&mut self, commission: Money) {
        self.try_update_commissions(commission)
            .expect("commission total exceeded Money bounds");
    }

    /// Updates the account commissions with the provided amount.
    ///
    /// # Errors
    ///
    /// Returns an error if the accumulated commission exceeds [`Money`] bounds.
    pub fn try_update_commissions(&mut self, commission: Money) -> anyhow::Result<()> {
        // TODO: Remove once from_raw enforces canonical precision alignment (v2)
        let commission = commission.normalized();
        if commission.is_zero() {
            return Ok(());
        }
        let currency = commission.currency;
        let total = self
            .commissions
            .get(&currency)
            .copied()

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Use `try_update_commissions` and handle the `Result`/error instead of `update_commissions` when the input is not pre-validated
  2. Cap or sanity-check incoming commission amounts (reject values from the venue beyond plausible bounds) before applying them
  3. Audit the venue adapter producing the commission for precision/currency-denomination mistakes
  4. Reset or reconcile the account commission state if a corrupted accumulated total is causing the overflow

Example fix

// before
account.update_commissions(commission); // panics on Money overflow
// after
if let Err(e) = account.try_update_commissions(commission) {
    log::error!("failed to apply commission: {e}");
}
Defensive patterns

Strategy: try-catch

Validate before calling

if let Err(e) = account.try_update_commissions(commission) {
    log::error!("commission update failed: {e}");
}

Try / catch

account.try_update_commissions(commission)
    .unwrap_or_else(|e| log::error!("failed to apply commission: {e}"));

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/1b1d77341fe66d3e. Report an issue: GitHub.