nautechsystems/nautilus_trader · error · anyhow::Error
invalid =' ' at precision
Error message
invalid {field}='{raw}' at precision {precision}: {e} What it means
The venue quantity string parsed into a Decimal but could not be converted into a `Quantity` at the instrument's specified precision — typically because the value has more decimal places than the precision allows or falls outside the Quantity range. The message names the field, raw value, and precision.
Solutions
- Refresh instrument definitions so quantityPrecision matches current exchange-info
- Round/truncate the raw decimal to the instrument precision before constructing the Quantity
- Check that the instrument being used matches the symbol's actual market (spot vs futures)
- Update the adapter if the precision contract changed
Example fix
// before
let qty = parse_required_quantity_at_precision(raw, precision, "origQty")?;
// after
let dec = Decimal::from_str(raw)?;
let qty = Quantity::from_decimal_dp(dec.round_dp(precision as u32), precision)
.map_err(|e| anyhow::anyhow!("invalid origQty='{raw}' at precision {precision}: {e}"))?; Defensive patterns
Strategy: validation
Validate before calling
let dec = Decimal::from_str(raw)?; assert!(dec.round_dp(0) == dec || dec.fract().dp() <= precision as u32, "qty exceeds precision {precision}"); Try / catch
match parse_required_quantity_at_precision(raw, precision, field) { Ok(q) => q, Err(e) => { warn!("precision mismatch, rounding: {e}"); Quantity::from_decimal_dp(Decimal::from_str(raw)?.round_dp(precision as u32), precision)? } } Prevention
- Keep instrument definitions refreshed from exchange-info
- Match market type (spot/futures) with the correct instrument set
- Round venue values to instrument precision defensively
When it happens
Trigger: Order updates, book snapshots, trade ticks, klines, or fill events (handle_ws_message, request_book_snapshot, parse_futures_trade_tick, parse_futures_kline_binance_bar, dispatch_order_update, parse_order_fill_event_fields) where a quantity string like "0.001234567" is re-precised to the instrument's quantityPrecision (e.g. 3).
Common situations: Binance emitting quantities with more decimals than the instrument's stated precision (exchange-info drift); mismatched instrument definitions loaded for a different market; kline volume fields with higher precision than expected.
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
- Failed to convert quote-to-base quantity for ord_id=
- Instrument not found in cache
- invalid quantity
- size precision exceeds maximum
- AX scale must not exceed 26 for exact percent conversion…
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/89806d5bcf687d22.
Report an issue: GitHub.
Appendix: source
Thrown at crates/adapters/binance/src/common/parse.rs:225
}
Price::from_decimal_dp(decimal, precision).ok()
}
/// Parses a required venue decimal string.
pub(crate) fn parse_required_decimal(raw: &str, field: &str) -> anyhow::Result<Decimal> {
Decimal::from_str(raw).map_err(|e| anyhow::anyhow!("invalid {field}='{raw}': {e}"))
}
/// Parses a required venue quantity string into a `Quantity` at the given precision.
pub(crate) fn parse_required_quantity_at_precision(
raw: &str,
precision: u8,
field: &str,
) -> anyhow::Result<Quantity> {
let decimal = parse_required_decimal(raw, field)?;
Quantity::from_decimal_dp(decimal, precision)
.map_err(|e| anyhow::anyhow!("invalid {field}='{raw}' at precision {precision}: {e}"))
}
/// Parses a required venue price string into a `Price` at the given precision.
pub(crate) fn parse_required_price_at_precision(
raw: &str,
precision: u8,
field: &str,
) -> anyhow::Result<Price> {
let decimal = parse_required_decimal(raw, field)?;
Price::from_decimal_dp(decimal, precision)
.map_err(|e| anyhow::anyhow!("invalid {field}='{raw}' at precision {precision}: {e}"))
}
/// Re-precisions an existing `Quantity` to the given precision via `Decimal`.
#[must_use]
pub(crate) fn quantity_at_precision(quantity: Quantity, precision: u8) -> Option<Quantity> {
Quantity::from_decimal_dp(quantity.as_decimal(), precision).ok()
}View on GitHub (pinned to 18893faf8b)