nautechsystems/nautilus_trader · error · anyhow::Error

Failed to create commission from fee: {e}

Error message

Failed to create commission from fee: {e}

What it means

Raised in parse_fill_report when Money::from_decimal fails creating the commission Money from fill.fee in the resolved fee currency. Money::from_decimal fails when the value cannot be scaled to the currency's precision without overflow or exceeds the MoneyRaw range. The fee currency is resolved via resolve_fee_currency (the instrument's quote currency or the fee_token), so a mismatch between the fee's decimal scale and the currency precision, or an extreme fee value, triggers this.

Source

Thrown at crates/adapters/hyperliquid/src/http/parse.rs:1194

        fill.sz,
        fill.time,
        fill.start_position,
    );
    let order_side = parse_fill_side(&fill.side);

    let price_precision = instrument.price_precision();
    let size_precision = instrument.size_precision();

    let last_px = Price::from_decimal_dp(fill.px, price_precision)
        .map_err(|e| anyhow::anyhow!("Failed to create price from fill px: {e}"))?;
    let last_qty = Quantity::from_decimal_dp(fill.sz.abs(), size_precision)
        .map_err(|e| anyhow::anyhow!("Failed to create quantity from fill sz: {e}"))?;

    let fee_amount = fill.fee;

    let fee_currency = resolve_fee_currency(fill.fee_token.as_str(), fee_amount, instrument)?;
    let commission = Money::from_decimal(fee_amount, fee_currency)
        .map_err(|e| anyhow::anyhow!("Failed to create commission from fee: {e}"))?;

    // Determine liquidity side based on 'crossed' flag
    let liquidity_side = if fill.crossed {
        LiquiditySide::Taker
    } else {
        LiquiditySide::Maker
    };

    let ts_event = UnixNanos::from(fill.time * 1_000_000);
    let report_id = UUID4::new();

    let report = FillReport::new(
        account_id,
        instrument_id,
        venue_order_id,
        trade_id,
        order_side,
        last_qty,

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Log the fee value and resolved fee currency; verify resolve_fee_currency picked the right currency for fill.fee_token
  2. Confirm the fee magnitude is sane for the currency's precision; refresh currency definitions if the token's decimals are wrong
  3. Scale/round the fee to the currency precision before Money::from_decimal, or fix the currency's precision in its definition
  4. Handle the error per-fill to avoid failing the entire fills response

Example fix

// before
let commission = Money::from_decimal(fee_amount, fee_currency)
    .map_err(|e| anyhow::anyhow!("Failed to create commission from fee: {e}"))?;
// after
let commission = Money::from_decimal(fee_amount, fee_currency)
    .map_err(|e| anyhow::anyhow!("Failed to create commission from fee {} {}: {e}", fee_amount, fee_currency.code))?;
Defensive patterns

Strategy: try-catch

Validate before calling

# Python: sanity-check fee magnitude relative to fill notional
if abs(fee) > fill_notional:
    log.warning("suspicious fee %s for fill notional %s", fee, fill_notional)

Try / catch

try:
    fills = client.request_fill_reports(...)
except ValueError as e:
    if "commission" in str(e):
        log.warning("fee not representable as Money, skipping fill: %s", e)
    else:
        raise

Prevention

When it happens

Trigger: Calling fill_reports_from_response for a fill whose fee magnitude overflows the raw Money representation at the fee currency's precision, or whose decimal scale can't be converted (e.g. fee denominated in a token resolved to a currency with fewer decimals and huge magnitude).

Common situations: Fees paid in a non-quote token whose currency has low precision while the fee value is large; unusual fee values during volatility spikes; resolve_fee_currency returning a currency whose precision doesn't match the fee_token's decimals.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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