nautechsystems/nautilus_trader · error
Failed to convert quote-to-base quantity for ord_id={}, sz={
Error message
Failed to convert quote-to-base quantity for ord_id={}, sz={sz}, price={price}, quantity_dec={quantity_dec}: {e} What it means
For quote-currency orders with a valid non-zero price, parse_order_status_report converts sz (quote ccy) to base quantity as sz / price and rounds it to the instrument's size precision via Quantity::from_decimal_dp. This error is raised when that conversion or rounding fails (e.g. result is negative, zero-precision violation, or exceeds Quantity bounds).
Source
Thrown at crates/adapters/okx/src/common/parse.rs:770
// Convert quote quantity to base: quantity_base = sz_quote / price
let quantity_base = if let (Some(sz), Some(price)) = (sz_quote_dec, conversion_price_dec) {
if price.is_zero() {
log::warn!(
"Cannot convert quote quantity with zero price: ord_id={}, sz={}, using sz as-is",
order.ord_id.as_str(),
order.sz
);
Quantity::from_str(&order.sz).map_err(|e| {
anyhow::anyhow!(
"Failed to parse fallback quantity for ord_id={}, sz='{}': {e}",
order.ord_id.as_str(),
order.sz
)
})?
} else {
let quantity_dec = sz / price;
Quantity::from_decimal_dp(quantity_dec, size_precision).map_err(|e| {
anyhow::anyhow!(
"Failed to convert quote-to-base quantity for ord_id={}, sz={sz}, price={price}, quantity_dec={quantity_dec}: {e}",
order.ord_id.as_str()
)
})?
}
} else {
log::warn!(
"Cannot convert quote quantity to base without price, using raw sz: \
ord_id={}, sz={}, px='{}', avg_px='{}'",
order.ord_id.as_str(),
order.sz,
order.px,
order.avg_px
);
Quantity::from_str(&order.sz).map_err(|e| {
anyhow::anyhow!(
"Failed to parse fallback quantity for ord_id={}, sz='{}': {e}",
order.ord_id.as_str(),View on GitHub (pinned to 18893faf8b)
Solutions
- Verify the instrument definition's size_precision matches the OKX instrument's lot size (lotSz)
- Log sz, price and the computed quantity_dec to check which bound was violated
- Reject/handle dust orders whose converted base quantity is below min size precision
- Upgrade or patch the adapter if OKX instruments require finer precision than configured
Example fix
// before let report = parse_order_status_report(&order, &instrument, ...)?; // after assert_eq!(instrument.size_precision as u32, okx_lot_sz_dec.fract_digits(), "size_precision must match OKX lotSz"); let report = parse_order_status_report(&order, &instrument, ...)?;
Defensive patterns
Strategy: validation
Validate before calling
let sz = Decimal::from_str(&order.sz)?;
let price = Decimal::from_str(&order.px)?;
let qty = sz / price;
if qty < Decimal::ZERO || qty.mantissa().unsigned_abs() > u64::MAX as u128 { /* reject before calling */ } Type guard
fn converts_to_quantity(sz: Decimal, price: Decimal, precision: u8) -> bool {
price > Decimal::ZERO && Quantity::from_decimal_dp(sz / price, precision).is_ok()
} Try / catch
match parse_order_status_report(&order, &instrument, ts_init) {
Ok(r) => handle(r),
Err(e) if e.to_string().contains("quote-to-base quantity") => log::warn!("conversion failed for {}: {e}", order.ord_id),
Err(e) => return Err(e),
} Prevention
- Match size_precision to OKX lotSz for every instrument
- Reject dust orders whose converted quantity is below precision
- Validate price > 0 and sz >= 0 before conversion
- Re-generate instrument definitions when OKX updates instrument specs
When it happens
Trigger: A quote-quantity order where sz/price yields a value that cannot be represented as a Quantity at the given size_precision: negative sz, price so small that the quotient overflows, or more decimals than size_precision allows without valid rounding.
Common situations: Wrong instrument definition (size_precision too small for OKX lot sizes); tiny dust orders producing sub-precision quantities; corrupted price or sz values from OKX; using the wrong instrument_id mapping so precision mismatches.
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}
- Failed to parse fallback quantity for ord_id={}, sz='{}': {e
- Failed to parse filled quantity for ord_id={}, acc_fill_sz='
- Failed to parse base quantity for ord_id={}, sz='{}': {e}
- Failed to parse `lot_sz` '{}' for {}: {e}
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/20cb37e14d9b14fc.
Report an issue: GitHub.