nautechsystems/nautilus_trader · error

size precision {precision} exceeds maximum {MAX_DECIMALS}

Error message

size precision {precision} exceeds maximum {MAX_DECIMALS}

What it means

parse_quantity converts a decimal string into a non-negative Nautilus Quantity at a requested precision. Nautilus Quantity is fixed-precision with a maximum of MAX_DECIMALS decimal places; any precision argument above that cannot be represented and is rejected before parsing begins.

Source

Thrown at crates/adapters/lighter/src/common/parse.rs:113

    );
    let decimal =
        Decimal::from_str(value).map_err(|e| anyhow::anyhow!("invalid price `{value}`: {e}"))?;
    Price::from_decimal_dp(decimal, precision)
        .map_err(|e| anyhow::anyhow!("invalid price `{value}` at precision {precision}: {e}"))
}

/// Converts a decimal string into a non-negative Nautilus [`Quantity`].
///
/// Zero is allowed because Lighter sends zero-size book levels to delete
/// existing orders.
///
/// # Errors
///
/// Returns an error if the string is not a decimal, if `precision` exceeds
/// [`MAX_DECIMALS`], if the value is negative, or if the resulting quantity
/// is out of range.
pub fn parse_quantity(value: &str, precision: u8) -> anyhow::Result<Quantity> {
    anyhow::ensure!(
        precision <= MAX_DECIMALS,
        "size precision {precision} exceeds maximum {MAX_DECIMALS}",
    );
    let decimal =
        Decimal::from_str(value).map_err(|e| anyhow::anyhow!("invalid quantity `{value}`: {e}"))?;
    anyhow::ensure!(decimal.is_sign_positive(), "negative quantity `{value}`");
    Quantity::from_decimal_dp(decimal, precision)
        .map_err(|e| anyhow::anyhow!("invalid quantity `{value}` at precision {precision}: {e}"))
}

/// Converts a [`Decimal`] into a Nautilus [`Price`] at the requested precision.
///
/// Use this when the wire value has already been deserialized as a [`Decimal`]
/// (the standard pattern for model fields tagged with `deserialize_decimal`).
///
/// # Errors
///
/// Returns an error if `precision` exceeds [`MAX_DECIMALS`] or if the value

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Validate the market's size_decimals against MAX_DECIMALS when loading instrument definitions and skip unsupported markets.
  2. Pass size_decimals from the orderBookDetails response rather than hard-coded values.
  3. Clamp with `precision.min(MAX_DECIMALS)` only if truncating to representable decimals is acceptable for your strategy.
  4. If you see this for a real market, the market cannot be modeled in Nautilus fixed-precision; exclude it.

Example fix

// before
let qty = parse_quantity(raw, size_decimals)?;
// after
anyhow::ensure!(size_decimals <= MAX_DECIMALS, "unsupported size precision");
let qty = parse_quantity(raw, size_decimals)?;
Defensive patterns

Strategy: validation

Validate before calling

fn precision_supported(precision: u8) -> bool {
    precision <= MAX_DECIMALS
}

Try / catch

match parse_quantity(raw, precision) {
    Ok(q) => q,
    Err(e) if e.to_string().contains("exceeds maximum") => {
        tracing::error!("size precision {precision} unsupported; skipping instrument");
        return Ok(None);
    }
    Err(e) => return Err(e.into()),
}

Prevention

When it happens

Trigger: Calling parse_quantity with a precision greater than MAX_DECIMALS — e.g. passing size_decimals=20 from market metadata, or a hard-coded literal that exceeds the fixed-precision limit.

Common situations: A Lighter market reporting unusually high size_decimals; copy-pasted precision constants from another venue; confusing bit-width (e.g. 32/64) with decimal places when wiring the precision parameter.

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