nautechsystems/nautilus_trader · error

invalid fee notional for last_qty=

Error message

invalid fee notional for last_qty='{last_qty}' and last_px='{last_px}': multiplication overflow

What it means

When a futures order update has no explicit commission but provides a `takerFee` rate, `resolve_commission` computes the fee as taker_fee × notional, where notional = last_qty × last_px. This error is raised when the `checked_mul` of quantity and price overflows the `Decimal` capacity, so the notional cannot be represented and the fee cannot be computed safely.

Solutions

  1. Check `last_qty` and `last_px` in the surrounding log for implausible magnitude or precision.
  2. Validate/sanitize quantity and price against the instrument's tick size and max quantity before fee computation.
  3. Reconcile the fee from the REST user-trades endpoint for that fill instead of computing from rate.
  4. If legitimate large notional is expected, widen the decimal representation used before this call.
Defensive patterns

Strategy: validation

Validate before calling

// Rust: bound-check qty/px before fee computation
fn notional_computable(qty: &rust_decimal::Decimal, px: &rust_decimal::Decimal) -> bool {
    qty.is_sign_positive() && px.is_sign_positive()
        && qty.mantissa().checked_mul(px.mantissa()).is_some()
}

Prevention

When it happens

Trigger: `parse_futures_order_update_to_fill` handles a Trade update with `taker_fee` set but no `commission` field, and `last_qty.as_decimal().checked_mul(last_px.as_decimal())` returns None (combined magnitude/digits exceed Decimal limits).

Common situations: Extremely large fills (huge COIN-M quantities × high prices) or values with excessive decimal places produced by a bad/mocked payload; corrupted or adversarial venue data rather than normal trading.

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/7dfc788dc8439a28. Report an issue: GitHub.

Appendix: source

Thrown at crates/adapters/binance/src/futures/websocket/streams/parse_exec.rs:187

    taker_fee: Option<Decimal>,
    quote_currency: Option<Currency>,
    bnfcr_currency: Currency,
) -> anyhow::Result<Money> {
    if order.commission.is_some() || order.commission_asset.is_some() {
        let raw_commission = order.commission.as_deref().unwrap_or("0");
        let amount = parse_required_decimal(raw_commission, "commission")?;
        let currency = order.commission_asset.as_ref().map_or(bnfcr_currency, |a| {
            normalize_futures_asset(a.as_str(), bnfcr_currency)
        });
        Money::from_decimal(amount, currency)
            .map_err(|e| anyhow::anyhow!("invalid commission='{raw_commission}': {e}"))
    } else if let Some(fee) = taker_fee {
        let currency = quote_currency.unwrap_or_else(Currency::USDT);
        let notional = last_qty
            .as_decimal()
            .checked_mul(last_px.as_decimal())
            .ok_or_else(|| {
                anyhow::anyhow!(
                    "invalid fee notional for last_qty='{last_qty}' and last_px='{last_px}': multiplication overflow",
                )
            })?;
        let amount = fee.checked_mul(notional).ok_or_else(|| {
            anyhow::anyhow!(
                "invalid fee amount for taker_fee='{fee}' and notional='{notional}': multiplication overflow"
            )
        })?;
        Money::from_decimal(amount, currency)
            .map_err(|e| anyhow::anyhow!("invalid fee amount='{amount}': {e}"))
    } else {
        Ok(Money::zero(Currency::USDT()))
    }
}

/// Converts a Binance Futures order update (Trade type) to a Nautilus fill report.
///
/// # Errors

View on GitHub (pinned to 18893faf8b)