{"record":{"id":"a7cdc5bbff6697e3","repo":"nautechsystems/nautilus_trader","slug":"failed-to-parse-active-quantity-for-e","errorCode":null,"errorMessage":"Failed to parse active quantity for {}: {e}","messagePattern":"Failed to parse active quantity for (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/betfair/src/execution.rs","lineNumber":3838,"sourceCode":"            if response.more_available && page_size == 0 {\n                anyhow::bail!(\"listCurrentOrders returned an empty page with moreAvailable=true\");\n            }\n\n            for order in &response.current_orders {\n                let mut report =\n                    parse_current_order_report(order, account_id, ts_init).map_err(|e| {\n                        anyhow::anyhow!(\"Failed to parse order report for {}: {e}\", order.bet_id)\n                    })?;\n\n                if let Some(resolution) = ocm_state.lock().resolve_order_owner(\n                    order.customer_order_ref.as_deref(),\n                    report.venue_order_id.as_str(),\n                ) {\n                    report.client_order_id = resolution.client_order_id();\n                }\n\n                let active_quantity = current_order_active_quantity(order).map_err(|e| {\n                    anyhow::anyhow!(\"Failed to parse active quantity for {}: {e}\", order.bet_id)\n                })?;\n                active_quantities.insert(order.bet_id.clone(), active_quantity);\n                reports.push(report);\n            }\n\n            if !response.more_available {\n                break;\n            }\n\n            from_record += page_size;\n        }\n    }\n\n    if merge_batches {\n        reports.sort_by_key(|report| (report.ts_accepted, report.venue_order_id));\n    }\n\n    Ok(FetchedOrderStatusReports {","sourceCodeStart":3820,"sourceCodeEnd":3856,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/betfair/src/execution.rs#L3820-L3856","documentation":"During reconciliation, the client computes the active (unmatched) size of each current order via current_order_active_quantity. If that helper cannot derive a valid quantity from the raw order (e.g. missing or unparseable sizeRemaining/size fields), the error is wrapped with the bet_id.","triggerScenarios":"listCurrentOrders returns an order whose size fields are absent or in an unexpected format while generating order status reports; the helper returns Err for that order.","commonSituations":"Orders in unusual states (fully matched/voided with odd size fields), Betfair API field changes, or None values where Decimal parsing was expected.","solutions":["Inspect the raw order payload for the bet_id to see which size field is missing or malformed.","Update current_order_active_quantity to handle the encountered state (e.g. treat missing sizeRemaining as 0 when appropriate).","Upgrade the adapter in case the fix already exists upstream; retry reconciliation."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match client.generate_order_status_reports().await {\n    Ok(reports) => apply(reports),\n    Err(e) if e.to_string().contains(\"Failed to parse active quantity\") => {\n        tracing::error!(\"active quantity parse failure: {e:#}\");\n        // fall back to manual reconciliation for the affected bet_id\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Track adapter updates for Betfair size-field handling.","Log raw order JSON when reconciliation fails to speed diagnosis.","Treat missing sizeRemaining deliberately (0 vs error) per business rules."],"tags":["reconciliation","parsing","quantity"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}