nautechsystems/nautilus_trader · error

price precision {precision} exceeds maximum {MAX_DECIMALS}

Error message

price precision {precision} exceeds maximum {MAX_DECIMALS}

What it means

parse_price converts a decimal string into a Nautilus Price at a requested precision. Nautilus Price is fixed-precision and supports at most MAX_DECIMALS (FIXED_PRECISION, 16/18 depending on build) decimal places. The library rejects any precision argument above that maximum before attempting conversion, because such a precision cannot be represented.

Source

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

    anyhow::ensure!(
        decimals <= MAX_DECIMALS,
        "size decimals {decimals} exceeds maximum {MAX_DECIMALS}",
    );
    anyhow::ensure!(ticks >= 0, "negative tick count {ticks} for Quantity");
    let decimal = Decimal::new(ticks, u32::from(decimals));
    Quantity::from_decimal_dp(decimal, decimals).map_err(|e| {
        anyhow::anyhow!("Quantity overflow for ticks={ticks}, decimals={decimals}: {e}")
    })
}

/// Converts a decimal string into a Nautilus [`Price`] at the requested precision.
///
/// # Errors
///
/// Returns an error if the string is not a decimal, if `precision` exceeds
/// [`MAX_DECIMALS`], or if the resulting value is out of range.
pub fn parse_price(value: &str, precision: u8) -> anyhow::Result<Price> {
    anyhow::ensure!(
        precision <= MAX_DECIMALS,
        "price precision {precision} exceeds maximum {MAX_DECIMALS}",
    );
    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

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Check the market's price_decimals in the orderBookDetails response and clamp or reject markets whose precision exceeds MAX_DECIMALS before calling parse_price.
  2. Pass the precision straight from the parsed market metadata instead of a hard-coded literal.
  3. Cap the precision with `precision.min(MAX_DECIMALS)` only if rounding to fewer decimals is acceptable for your use case (note it may reject valid tick alignment otherwise).
  4. Skip instruments whose precision is unsupported — Nautilus cannot represent them.

Example fix

// before
let price = parse_price(raw, market.price_decimals)?;
// after
anyhow::ensure!(market.price_decimals <= MAX_DECIMALS, "unsupported market precision");
let price = parse_price(raw, market.price_decimals)?;
Defensive patterns

Strategy: validation

Validate before calling

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

Try / catch

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

Prevention

When it happens

Trigger: Calling parse_price with a precision argument greater than MAX_DECIMALS — e.g. hard-coding precision=18 or 20, or passing an unvalidated price_decimals value from a payload where the market reports more decimals than Nautilus supports.

Common situations: Copy-pasting precision from a different market or venue spec; a Lighter market with unusually high price_decimals in orderBookDetails; confusion between Lighter's decimal count and Nautilus's fixed-precision exponent.

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