nautechsystems/nautilus_trader · error

Failed to parse active quantity for {}: {e}

Error message

Failed to parse active quantity for {}: {e}

What it means

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.

Source

Thrown at crates/adapters/betfair/src/execution.rs:3838

            if response.more_available && page_size == 0 {
                anyhow::bail!("listCurrentOrders returned an empty page with moreAvailable=true");
            }

            for order in &response.current_orders {
                let mut report =
                    parse_current_order_report(order, account_id, ts_init).map_err(|e| {
                        anyhow::anyhow!("Failed to parse order report for {}: {e}", order.bet_id)
                    })?;

                if let Some(resolution) = ocm_state.lock().resolve_order_owner(
                    order.customer_order_ref.as_deref(),
                    report.venue_order_id.as_str(),
                ) {
                    report.client_order_id = resolution.client_order_id();
                }

                let active_quantity = current_order_active_quantity(order).map_err(|e| {
                    anyhow::anyhow!("Failed to parse active quantity for {}: {e}", order.bet_id)
                })?;
                active_quantities.insert(order.bet_id.clone(), active_quantity);
                reports.push(report);
            }

            if !response.more_available {
                break;
            }

            from_record += page_size;
        }
    }

    if merge_batches {
        reports.sort_by_key(|report| (report.ts_accepted, report.venue_order_id));
    }

    Ok(FetchedOrderStatusReports {

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Inspect the raw order payload for the bet_id to see which size field is missing or malformed.
  2. Update current_order_active_quantity to handle the encountered state (e.g. treat missing sizeRemaining as 0 when appropriate).
  3. Upgrade the adapter in case the fix already exists upstream; retry reconciliation.
Defensive patterns

Strategy: try-catch

Try / catch

match client.generate_order_status_reports().await {
    Ok(reports) => apply(reports),
    Err(e) if e.to_string().contains("Failed to parse active quantity") => {
        tracing::error!("active quantity parse failure: {e:#}");
        // fall back to manual reconciliation for the affected bet_id
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: 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.

Common situations: Orders in unusual states (fully matched/voided with odd size fields), Betfair API field changes, or None values where Decimal parsing was expected.

Understand the failure class

Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/a7cdc5bbff6697e3. Report an issue: GitHub.