nautechsystems/nautilus_trader · error
Failed to parse fallback quantity for ord_id={}, sz='{}': {e
Error message
Failed to parse fallback quantity for ord_id={}, sz='{}': {e} What it means
In parse_order_status_report, when a quote-currency order has a zero conversion price, the parser falls back to using the raw sz string as the base quantity. If that string cannot be parsed into a Quantity, this error is raised. It means OKX returned an sz value that is not a valid decimal number.
Source
Thrown at crates/adapters/okx/src/common/parse.rs:761
log::warn!(
"No price available for conversion: ord_id={}, px='{}', avg_px='{}'",
order.ord_id.as_str(),
order.px,
order.avg_px
);
None
};
// 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='{}'",View on GitHub (pinned to 18893faf8b)
Solutions
- Log order.sz, order.px and order.avg_px for the failing ord_id to see the raw payload
- Check the OKX order record for empty/placeholder sz and skip such orders before parsing
- Upgrade the nautilus OKX adapter so empty/zero-price quote orders are handled upstream
- If sz uses an unexpected format, file an issue with the raw response and handle the format in a preprocessing step
Example fix
// before
let report = parse_order_status_report(&order, ...)?;
// after
if order.sz.trim().is_empty() {
log::warn!("Skipping order {} with empty sz", order.ord_id);
return Ok(None);
}
let report = parse_order_status_report(&order, ...)?; Defensive patterns
Strategy: validation
Validate before calling
fn is_valid_decimal_string(s: &str) -> bool { !s.trim().is_empty() && rust_decimal::Decimal::from_str(s.trim()).is_ok() }
// call before: if !is_valid_decimal_string(&order.sz) { skip } Type guard
fn parseable_quantity(s: &str) -> Option<Quantity> { Quantity::from_str(s).ok() } Try / catch
match parse_order_status_report(&order, &instrument, ts_init) {
Ok(r) => handle(r),
Err(e) if e.to_string().contains("fallback quantity") => log::warn!("unparseable sz for {}: {e}", order.ord_id),
Err(e) => return Err(e),
} Prevention
- Pre-validate numeric string fields from OKX payloads
- Skip cancelled/empty orders before parsing
- Keep instrument definitions in sync with OKX lotSz/tickSz
- Add fixture tests covering empty-field edge cases
When it happens
Trigger: A quote-quantity order (tgt_ccy=QuoteCcy, or spot/margin BUY market order per the heuristic) where px and avg_px are empty/zero, AND order.sz contains a non-numeric, empty, or malformed string (e.g. "", "1,000", scientific notation out of range).
Common situations: Cancelled or unfilled market orders with no price yet; OKX returning empty strings for fields on cancelled orders; locale-formatted numbers copied in custom responses; new OKX API versions changing field formats.
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 filled quantity for ord_id={}, acc_fill_sz='
- Failed to parse base quantity for ord_id={}, sz='{}': {e}
- 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/45cd78d7de08652b.
Report an issue: GitHub.