{"record":{"id":"9c794cd384ec03ee","repo":"nautechsystems/nautilus_trader","slug":"failed-to-parse-base-quantity-for-ord-id-sz","errorCode":null,"errorMessage":"Failed to parse base quantity for ord_id={}, sz='{}': {e}","messagePattern":"Failed to parse base quantity for ord_id=(.+?), sz='(.+?)': (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/okx/src/common/parse.rs","lineNumber":806,"sourceCode":"                    order.ord_id.as_str(),\n                    order.sz\n                )\n            })?\n        };\n\n        let filled_qty_dec = parse_quantity(&order.acc_fill_sz, size_precision).map_err(|e| {\n            anyhow::anyhow!(\n                \"Failed to parse filled quantity for ord_id={}, acc_fill_sz='{}': {e}\",\n                order.ord_id.as_str(),\n                order.acc_fill_sz\n            )\n        })?;\n\n        (quantity_base, filled_qty_dec)\n    } else {\n        // Base-quantity order: both sz and acc_fill_sz are in base currency\n        let quantity_dec = parse_quantity(&order.sz, size_precision).map_err(|e| {\n            anyhow::anyhow!(\n                \"Failed to parse base quantity for ord_id={}, sz='{}': {e}\",\n                order.ord_id.as_str(),\n                order.sz\n            )\n        })?;\n        let filled_qty_dec = parse_quantity(&order.acc_fill_sz, size_precision).map_err(|e| {\n            anyhow::anyhow!(\n                \"Failed to parse filled quantity for ord_id={}, acc_fill_sz='{}': {e}\",\n                order.ord_id.as_str(),\n                order.acc_fill_sz\n            )\n        })?;\n\n        (quantity_dec, filled_qty_dec)\n    };\n\n    // For quote-quantity orders marked as FILLED, adjust quantity to match filled_qty\n    // to avoid precision mismatches from quote-to-base conversion","sourceCodeStart":788,"sourceCodeEnd":824,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/okx/src/common/parse.rs#L788-L824","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nlet qty = parse_quantity(&order.sz, size_precision)?;\n// after\nlet qty = match parse_quantity(order.sz.trim(), size_precision) {\n    Ok(q) => q,\n    Err(e) => { log::warn!(\"Skipping order {}: bad sz '{}': {e}\", order.ord_id, order.sz); return Ok(None); }\n};","handlingStrategy":"validation","validationCode":"let sz = order.sz.trim();\nif sz.is_empty() || rust_decimal::Decimal::from_str(sz).is_err() { /* skip order */ }","typeGuard":"fn parseable_base_sz(s: &str, precision: u8) -> bool {\n    rust_decimal::Decimal::from_str(s.trim()).map(|d| d.fract_digits() as u8 <= precision).unwrap_or(false)\n}","tryCatchPattern":"match parse_order_status_report(&order, &instrument, ts_init) {\n    Ok(r) => handle(r),\n    Err(e) if e.to_string().contains(\"base quantity\") => { log::warn!(\"bad sz for {}: {e}\", order.ord_id); Ok(None) }\n    Err(e) => Err(e),\n}","preventionTips":["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"],"tags":["okx","rust","parsing","quantity","decimal"],"backgroundTag":"invalid-argument-format","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}