nautechsystems/nautilus_trader · error
Failed to parse filled quantity for ord_id={}, acc_fill_sz='
Error message
Failed to parse filled quantity for ord_id={}, acc_fill_sz='{}': {e} What it means
parse_order_status_report parses the accumulated filled size acc_fill_sz (always base currency on OKX) via parse_quantity with the instrument's size precision. This error means acc_fill_sz was not a valid decimal number representable at that precision, so the order status report cannot be built.
Source
Thrown at crates/adapters/okx/src/common/parse.rs:795
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(),
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!(View on GitHub (pinned to 18893faf8b)
Solutions
- Log the raw acc_fill_sz for the failing ord_id
- Treat empty acc_fill_sz as zero before parsing (normalize upstream)
- Check the instrument's size_precision matches OKX lotSz for the instrument
- Upgrade the adapter in case a newer version normalizes this field
Example fix
// before
let filled = parse_quantity(&order.acc_fill_sz, size_precision)?;
// after
let acc = if order.acc_fill_sz.trim().is_empty() { "0" } else { order.acc_fill_sz.as_str() };
let filled = parse_quantity(acc, size_precision)?; Defensive patterns
Strategy: validation
Validate before calling
let acc = order.acc_fill_sz.trim();
if acc.is_empty() || rust_decimal::Decimal::from_str(acc).is_err() { /* normalize to "0" or skip */ } Type guard
fn parseable_at_precision(s: &str, precision: u8) -> bool {
match rust_decimal::Decimal::from_str(s.trim()) {
Ok(d) => d.fract_digits() as u8 <= precision,
Err(_) => false,
}
} Try / catch
match parse_order_status_report(&order, &instrument, ts_init) {
Ok(r) => handle(r),
Err(e) if e.to_string().contains("filled quantity") => log::warn!("bad acc_fill_sz for {}: {e}", order.ord_id),
Err(e) => return Err(e),
} Prevention
- Normalize empty acc_fill_sz to "0" before parsing
- Verify size_precision equals OKX lotSz decimals
- Test fixtures with empty and zero acc_fill_sz
- Monitor OKX API changelogs for field format changes
When it happens
Trigger: OKX returns an acc_fill_sz that is empty, non-numeric, or has precision beyond size_precision for any order being parsed into an OrderStatusReport.
Common situations: Cancelled orders where OKX returns empty acc_fill_sz; adapter/instrument definition precision mismatch vs lotSz; OKX API changes to field formatting; corrupted recorded payloads.
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 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/bf3e32b66f028706.
Report an issue: GitHub.