{"record":{"id":"359b21c704ed0c86","repo":"nautechsystems/nautilus_trader","slug":"failed-to-create-quantity-from-filled-sz-e","errorCode":null,"errorMessage":"Failed to create quantity from filled_sz: {e}","messagePattern":"Failed to create quantity from filled_sz: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/hyperliquid/src/http/parse.rs","lineNumber":970,"sourceCode":"        OrderType::Limit\n    };\n\n    let time_in_force = order\n        .tif\n        .map_or(TimeInForce::Gtc, hyperliquid_time_in_force_to_nautilus);\n    let order_status = OrderStatus::from(*status);\n\n    let price_precision = instrument.price_precision();\n    let size_precision = instrument.size_precision();\n\n    let orig_sz = order.orig_sz;\n    let current_sz = order.sz;\n\n    let quantity = Quantity::from_decimal_dp(orig_sz.abs(), size_precision)\n        .map_err(|e| anyhow::anyhow!(\"Failed to create quantity from orig_sz: {e}\"))?;\n    let filled_sz = orig_sz.abs() - current_sz.abs();\n    let filled_qty = Quantity::from_decimal_dp(filled_sz, size_precision)\n        .map_err(|e| anyhow::anyhow!(\"Failed to create quantity from filled_sz: {e}\"))?;\n\n    let ts_accepted = UnixNanos::from(order.timestamp * 1_000_000);\n    let ts_last = ts_accepted;\n    let report_id = UUID4::new();\n\n    let mut report = OrderStatusReport::new(\n        account_id,\n        instrument_id,\n        None, // client_order_id - will be set if present\n        venue_order_id,\n        order_side.into(),\n        order_type,\n        time_in_force,\n        order_status,\n        quantity,\n        filled_qty,\n        ts_accepted,\n        ts_last,","sourceCodeStart":952,"sourceCodeEnd":988,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/hyperliquid/src/http/parse.rs#L952-L988","documentation":"This error is raised in parse_order_status_report_from_basic when Quantity::from_decimal_dp fails while converting the computed filled size (orig_sz - sz, both absolute) into a domain Quantity at the instrument's size precision. Quantity::from_decimal_dp rejects negative values, values exceeding the fixed-point raw range, and conversion overflow, so it fails when the exchange reports an inconsistent pair (sz > orig_sz) or absurdly large/precision-heavy sizes. The anyhow context wraps the underlying CorrectnessError for the caller.","triggerScenarios":"Calling request_order_status_report(s), request_order_status_report_by_client_order_id, historical_order_status_reports_from_response, or parsing a WS order update where the Hyperliquid order response yields filled_sz = |orig_sz| - |sz| that is negative (sz > orig_sz in exchange data), or whose mantissa scale/overflow cannot round-trip into QuantityRaw at the instrument's size_precision.","commonSituations":"Exchange data anomalies or API changes returning orig_sz/sz inconsistently (e.g. after partial-cancel events or during reconciliation of old orders); instruments defined with a size_precision that makes banker's rounding overflow; reconciling orders for many dexes where stale/corrupted records appear.","solutions":["Check the raw response fields orig_sz and sz from Hyperliquid; verify sz <= orig_sz and both parse as valid non-negative decimals","Verify the instrument definition (size_precision from the parsed Instrument) matches the venue's asset decimals; re-fetch instrument definitions if stale","Log the full order payload and the inner CorrectnessError to distinguish negative-value vs overflow failure and report a data-quality issue upstream if the exchange data is inconsistent","If handling historical/reconciliation data, guard the parse call and skip (or mark degraded) the offending order rather than failing the whole batch"],"exampleFix":"// before\nlet filled_sz = orig_sz.abs() - current_sz.abs();\nlet filled_qty = Quantity::from_decimal_dp(filled_sz, size_precision)\n    .map_err(|e| anyhow::anyhow!(\"Failed to create quantity from filled_sz: {e}\"))?;\n// after\nlet filled_sz = orig_sz.abs() - current_sz.abs();\nanyhow::ensure!(filled_sz >= Decimal::ZERO, \"Negative filled_sz {filled_sz} (orig_sz={orig_sz}, sz={current_sz})\");\nlet filled_qty = Quantity::from_decimal_dp(filled_sz, size_precision)\n    .map_err(|e| anyhow::anyhow!(\"Failed to create quantity from filled_sz: {e}\"))?;","handlingStrategy":"validation","validationCode":"// Rust: before requesting order status, sanity-check reported sizes\nif order.sz.abs() > order.orig_sz.abs() {\n    // inconsistent data; skip or log\n}\nanyhow::ensure!(orig_sz.abs() >= current_sz.abs(), \"sz exceeds orig_sz\");","typeGuard":"fn is_valid_filled_size(orig_sz: rust_decimal::Decimal, sz: rust_decimal::Decimal) -> bool {\n    orig_sz.abs() >= sz.abs() && orig_sz.abs() <= rust_decimal::Decimal::from_i128_with_scale(1, 0)\n        || orig_sz.abs() >= sz.abs()\n}","tryCatchPattern":"match parse_order_status_report_from_basic(...) {\n    Ok(report) => emit(report),\n    Err(e) if e.to_string().contains(\"filled_sz\") => log::warn!(\"skipping order with bad filled size: {e}\"),\n    Err(e) => return Err(e),\n}","preventionTips":["Keep instrument definitions (size_precision) fresh by re-fetching from the venue","Validate orig_sz/sz ordering before computing filled size","Skip-and-log individual bad orders instead of failing whole reconciliation sweeps"],"tags":["rust","hyperliquid","parsing","order-status","quantity-conversion"],"backgroundTag":"invalid-argument-value","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"}