{"record":{"id":"5ce8361d16934e2f","repo":"nautechsystems/nautilus_trader","slug":"quantity-was-undefined","errorCode":null,"errorMessage":"quantity was undefined","messagePattern":"quantity was undefined","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/portfolio/src/manager.rs","lineNumber":1415,"sourceCode":"                instrument.id().venue,\n                source_currency,\n                base_curr,\n                if side == OrderSide::Buy {\n                    PriceType::Bid\n                } else {\n                    PriceType::Ask\n                },\n            ),\n        }\n    }\n}\n\n#[allow(\n    clippy::useless_conversion,\n    reason = \"the raw width differs when high-precision is disabled\"\n)]\nfn wallet_money_from_quantity(quantity: Quantity, currency: Currency) -> anyhow::Result<Money> {\n    anyhow::ensure!(!quantity.is_undefined(), \"quantity was undefined\");\n    Quantity::from_raw_checked(quantity.raw, quantity.precision)?;\n    check_fixed_raw_u128(u128::from(quantity.raw), quantity.precision)?;\n\n    let source_precision = quantity.precision.max(FIXED_PRECISION);\n    let target_precision = currency.precision.max(FIXED_PRECISION);\n    let raw = i128::try_from(u128::from(quantity.raw))\n        .map_err(|_| anyhow::anyhow!(\"quantity for {currency} exceeds signed raw bounds\"))?;\n    let raw = match source_precision.cmp(&target_precision) {\n        Ordering::Less => {\n            let scale = 10_i128.pow(u32::from(target_precision - source_precision));\n            raw.checked_mul(scale).ok_or_else(|| {\n                anyhow::anyhow!(\"quantity for {currency} overflowed while increasing raw scale\")\n            })?\n        }\n        Ordering::Greater => {\n            let scale = 10_i128.pow(u32::from(source_precision - target_precision));\n            anyhow::ensure!(\n                raw % scale == 0,","sourceCodeStart":1397,"sourceCodeEnd":1433,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/portfolio/src/manager.rs#L1397-L1433","documentation":"wallet_money_from_quantity converts a Quantity into Money for wallet balance updates. It first asserts the quantity is defined (raw != u64::MAX sentinel, i.e. not 'undefined'); an undefined Quantity cannot represent a monetary amount, so it errors via anyhow::ensure!.","triggerScenarios":"update_balance_locked_wallet receiving a balance/locked amount whose Quantity was constructed with the UNDEFINED raw sentinel (Quantity::new_checked on NaN/None paths, or a default-uninitialized Quantity).","commonSituations":"Strategies that lock balances before any fill sets a quantity; adapters returning placeholder quantities; deserializing events with missing quantity fields; uninitialized struct fields defaulting to undefined.","solutions":["Ensure the Quantity is set to a real value before updating locked balances","Validate event/adapter data so undefined quantities never reach the portfolio manager","Use Quantity::new_checked to construct quantities so invalid values fail early","Skip or log-and-drop balance updates carrying undefined quantities"],"exampleFix":"// before\nmanager.update_balance_locked_wallet(&instrument.id(), asset, quantity)?;\n// after\nif quantity.is_undefined() {\n    log::warn!(\"skipping locked-balance update: quantity undefined for {asset}\");\n} else {\n    manager.update_balance_locked_wallet(&instrument.id(), asset, quantity)?;\n}","handlingStrategy":"type-guard","validationCode":"if quantity.is_undefined() {\n    log::warn!(\"skipping wallet lock update: undefined quantity\");\n    return Ok(());\n}","typeGuard":"fn is_defined(q: &Quantity) -> bool { !q.is_undefined() }","tryCatchPattern":"match manager.update_balance_locked_wallet(&instrument_id, currency, quantity) {\n    Ok(_) => {}\n    Err(e) if e.to_string().contains(\"quantity was undefined\") => {\n        log::warn!(\"undefined quantity for {currency}; skipping lock update\");\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Construct quantities with Quantity::new_checked so invalid values fail at creation","Initialize struct fields with defined defaults, not the UNDEFINED sentinel","Validate adapter/event payloads before feeding them to the portfolio manager"],"tags":["rust","portfolio","quantity","validation"],"backgroundTag":"empty-required-field","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"}