nautechsystems/nautilus_trader · error
Failed to parse base quantity for ord_id={}, sz='{}': {e}
Error message
Failed to parse base quantity for ord_id={}, sz='{}': {e} What it means
For base-quantity orders (not quote-quantity per tgt_ccy/heuristic), parse_order_status_report parses sz directly as the base-currency quantity with the instrument's size precision. This error means the sz string from OKX failed decimal parsing or precision normalization.
Source
Thrown at crates/adapters/okx/src/common/parse.rs:806
order.ord_id.as_str(),
order.sz
)
})?
};
let filled_qty_dec = parse_quantity(&order.acc_fill_sz, size_precision).map_err(|e| {
anyhow::anyhow!(
"Failed to parse filled quantity for ord_id={}, acc_fill_sz='{}': {e}",
order.ord_id.as_str(),
order.acc_fill_sz
)
})?;
(quantity_base, filled_qty_dec)
} else {
// Base-quantity order: both sz and acc_fill_sz are in base currency
let quantity_dec = parse_quantity(&order.sz, size_precision).map_err(|e| {
anyhow::anyhow!(
"Failed to parse base quantity for ord_id={}, sz='{}': {e}",
order.ord_id.as_str(),
order.sz
)
})?;
let filled_qty_dec = parse_quantity(&order.acc_fill_sz, size_precision).map_err(|e| {
anyhow::anyhow!(
"Failed to parse filled quantity for ord_id={}, acc_fill_sz='{}': {e}",
order.ord_id.as_str(),
order.acc_fill_sz
)
})?;
(quantity_dec, filled_qty_dec)
};
// For quote-quantity orders marked as FILLED, adjust quantity to match filled_qty
// to avoid precision mismatches from quote-to-base conversionView on GitHub (pinned to 18893faf8b)
Solutions
- Log order.sz and ord_id to inspect the failing value
- Align the Nautilus instrument definition's size_precision with the OKX instrument lotSz
- Normalize empty sz to "0" or skip the order upstream
- Upgrade the OKX adapter in case newer versions handle the format
Example fix
// before
let qty = parse_quantity(&order.sz, size_precision)?;
// after
let qty = match parse_quantity(order.sz.trim(), size_precision) {
Ok(q) => q,
Err(e) => { log::warn!("Skipping order {}: bad sz '{}': {e}", order.ord_id, order.sz); return Ok(None); }
}; Defensive patterns
Strategy: validation
Validate before calling
let sz = order.sz.trim();
if sz.is_empty() || rust_decimal::Decimal::from_str(sz).is_err() { /* skip order */ } Type guard
fn parseable_base_sz(s: &str, precision: u8) -> bool {
rust_decimal::Decimal::from_str(s.trim()).map(|d| d.fract_digits() as u8 <= precision).unwrap_or(false)
} Try / catch
match parse_order_status_report(&order, &instrument, ts_init) {
Ok(r) => handle(r),
Err(e) if e.to_string().contains("base quantity") => { log::warn!("bad sz for {}: {e}", order.ord_id); Ok(None) }
Err(e) => Err(e),
} Prevention
- Validate sz is a decimal string before calling the parser
- Keep instrument size_precision aligned with OKX lotSz
- Skip cancelled orders carrying empty sz
- Add round-trip tests against live OKX order payloads
When it happens
Trigger: A limit order, SELL market order, or non-spot order whose sz field is empty, non-numeric, or has more decimal places than the instrument's size_precision allows.
Common situations: Mismatched instrument definition (size_precision does not match OKX lotSz); empty sz on cancelled legacy orders; OKX returning unexpected formats (e.g. exponent notation); wrong instrument mapping for the inst_id.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Failed to parse fallback quantity for ord_id={}, sz='{}': {e
- Failed to parse filled quantity for ord_id={}, acc_fill_sz='
- invalid quantity `{value}`: {e}
- Failed to convert quote-to-base quantity for ord_id={}, sz={
- Failed to parse liab '{liab_str}': {e}
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/9c794cd384ec03ee.
Report an issue: GitHub.