nautechsystems/nautilus_trader · error · anyhow::Error

invalid cumulative_quote_qty='{}' for cumulative_filled_qty=

Error message

invalid cumulative_quote_qty='{}' for cumulative_filled_qty='{}': division overflow

What it means

While computing the average price of an execution report, `cumulative_quote_qty / cumulative_filled_qty` overflowed the `Decimal` checked-division capacity. `parse_spot_exec_report_to_order_status` only computes `avg_px` when filled quantity is positive, and `checked_div` returning `None` (numeric overflow in fixed-point Decimal) yields this error.

Source

Thrown at crates/adapters/binance/src/spot/websocket/trading/parse.rs:84

    let order_status = parse_order_status(msg.order_status, treat_expired_as_canceled);
    let order_type = parse_spot_order_type(&msg.order_type);
    let time_in_force = parse_time_in_force(msg.time_in_force);

    let quantity =
        parse_required_quantity_at_precision(&msg.original_qty, size_precision, "original_qty")?;
    let filled_qty = parse_required_quantity_at_precision(
        &msg.cumulative_filled_qty,
        size_precision,
        "cumulative_filled_qty",
    )?;
    let price = parse_required_price_at_precision(&msg.price, price_precision, "price")?;

    let filled_qty_decimal =
        parse_required_decimal(&msg.cumulative_filled_qty, "cumulative_filled_qty")?;
    let avg_px = if filled_qty_decimal > Decimal::ZERO {
        let cum_quote = parse_required_decimal(&msg.cumulative_quote_qty, "cumulative_quote_qty")?;
        let avg_px = cum_quote.checked_div(filled_qty_decimal).ok_or_else(|| {
            anyhow::anyhow!(
                "invalid cumulative_quote_qty='{}' for cumulative_filled_qty='{}': division overflow",
                msg.cumulative_quote_qty,
                msg.cumulative_filled_qty,
            )
        })?;
        Some(Price::from_decimal_dp(avg_px, price_precision)?)
    } else {
        None
    };

    let mut report = OrderStatusReport::new(
        account_id,
        instrument_id,
        Some(client_order_id),
        venue_order_id,
        order_side.into(),
        order_type,
        time_in_force,

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Inspect the report's `cumulative_quote_qty` and `cumulative_filled_qty` for extreme values; if it's a dust fill, consider computing avg_px as None for negligible fills.
  2. Verify instrument `price_precision`/`size_precision` are correct; wrong precision amplifies exponent overflow.
  3. Pre-check the ratio magnitude before dividing and fall back to a None/rounded avg price instead of failing the whole report.
  4. Update the adapter if Binance changed quantity/quote precision for the symbol.

Example fix

// before: hard fail on division overflow
let avg_px = cum_quote.checked_div(filled_qty_decimal).ok_or_else(|| anyhow!("...division overflow"))?;
// after: tolerate overflow for dust fills
let avg_px = cum_quote.checked_div(filled_qty_decimal).ok_or(None).map(Price::from_decimal_dp).ok();
Defensive patterns

Strategy: fallback

Validate before calling

fn avg_px_computable(cum_quote: Decimal, filled: Decimal) -> bool {
    filled > Decimal::ZERO
        && cum_quote.checked_div(filled).is_some()
}

Try / catch

let avg_px = match cum_quote.checked_div(filled_qty_decimal) {
    Some(px) => Some(Price::from_decimal_dp(px, price_precision)?),
    None => {
        log::warn!("avg px division overflow; leaving avg_px unset");
        None
    }
};

Prevention

When it happens

Trigger: An execution report where `cumulative_quote_qty` is enormous relative to `cumulative_filled_qty` (or a filled qty like a tiny epsilon) so the quotient exceeds Decimal's 128-bit fixed-point range; `checked_div` returns `None`.

Common situations: Dust fills with a minuscule `cumulative_filled_qty` and a normal quote amount; Binance sending scientific/mismatched precision strings; extreme price symbols where the quotient blows past the Decimal exponent 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/650c0a5ea5d24b76. Report an issue: GitHub.