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 quantityView on GitHub (pinned to 18893faf8b)
Solutions
- Check the market's price_decimals in the orderBookDetails response and clamp or reject markets whose precision exceeds MAX_DECIMALS before calling parse_price.
- Pass the precision straight from the parsed market metadata instead of a hard-coded literal.
- 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).
- 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
- Validate price_decimals from orderBookDetails once at instrument load, not per message
- Never hard-code precision literals; always take them from parsed market metadata
- Skip instruments whose precision exceeds MAX_DECIMALS instead of clamping (clamping misaligns ticks)
- Keep a subscription-time check so bad markets fail fast, not mid-stream
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
- size precision {precision} exceeds maximum {MAX_DECIMALS}
- invalid price `{value}` at precision {precision}: {e}
- {field} {value} is not exactly representable with price prec
- quantity size={} cannot be represented with precision={}
- Gamma {scope} filter '{key}' must be true or false, was '{va
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/31ef310dc4eddba1.
Report an issue: GitHub.