{"record":{"id":"7b51c0b66fe1346c","repo":"nautechsystems/nautilus_trader","slug":"order-quantity-must-be-positive","errorCode":null,"errorMessage":"Order quantity must be positive","messagePattern":"Order quantity must be positive","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/execution/client.rs","lineNumber":5203,"sourceCode":"            plan.token_in,\n            balance.value,\n            plan.amount_in\n        );\n    }\n    decisions.push(verification_decision(&balance, Some(block), Some(block)));\n\n    Ok(decisions)\n}\n\n/// Converts a base-denominated order quantity into raw token units with exact integer\n/// scaling by the base token decimals.\n///\n/// `Quantity::raw` is scaled to the greater of its declared precision and `FIXED_PRECISION`;\n/// token amounts are scaled to the token's decimals. Quantities not exactly representable in\n/// token units are rejected rather than rounded.\nfn quantity_to_raw_amount(quantity: Quantity, decimals: u8) -> anyhow::Result<U256> {\n    if quantity.is_zero() {\n        anyhow::bail!(\"Order quantity must be positive\");\n    }\n\n    let raw = U256::from(quantity.raw);\n    let raw_precision = quantity.precision.max(FIXED_PRECISION);\n    if decimals >= raw_precision {\n        let scale = U256::from(10u64)\n            .checked_pow(U256::from(decimals - raw_precision))\n            .ok_or_else(|| anyhow::anyhow!(\"Order amount scaling overflow\"))?;\n        raw.checked_mul(scale).ok_or_else(|| {\n            anyhow::anyhow!(\"Order amount overflow scaling quantity to raw token units\")\n        })\n    } else {\n        let divisor = U256::from(10u64)\n            .checked_pow(U256::from(raw_precision - decimals))\n            .ok_or_else(|| anyhow::anyhow!(\"Order amount scaling overflow\"))?;\n        if !(raw % divisor).is_zero() {\n            anyhow::bail!(\n                \"Order quantity {quantity} is not exactly representable in {decimals} base token decimals\"","sourceCodeStart":5185,"sourceCodeEnd":5221,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/execution/client.rs#L5185-L5221","documentation":"quantity_to_raw_amount converts an order Quantity into a raw U256 token amount scaled to the token's decimals. A zero quantity cannot represent a valid order, so the conversion bails immediately with this error.","triggerScenarios":"Calling any order/swap path that converts an order Quantity (quantity_to_raw_amount) with quantity.is_zero() — e.g. an order built with size 0, a quantity computed as zero after fee/netting math, or an uninitialized default Quantity.","commonSituations":"Order sizing logic producing 0 after subtracting fees from a small balance; a market-data-driven quantity of 0 for a delisted/illiquid instrument; a bug where the quantity field was never populated before submission.","solutions":["Validate the order quantity is strictly positive before constructing/submitting the order","Fix the sizing calculation that produced zero (fees, rounding, or floor-to-zero)","Check upstream market data / balance inputs that led to a zero size","Skip zero-sized orders rather than submitting them"],"exampleFix":"// before: submitting whatever quantity was computed\nlet order = Order::new(instrument, quantity);\n// after: guard zero size upstream\nif quantity.is_zero() {\n    return Ok(None); // skip order\n}\nlet order = Order::new(instrument, quantity);","handlingStrategy":"validation","validationCode":"anyhow::ensure!(!quantity.is_zero(), \"order quantity must be positive, got {:?}\", quantity);","typeGuard":"fn is_valid_order_quantity(q: &Quantity) -> bool { !q.is_zero() }","tryCatchPattern":"match res {\n    Err(e) if e.to_string().contains(\"quantity must be positive\") => {\n        log::warn!(\"skipping zero-sized order\");\n        Ok(None)\n    }\n    other => other?,\n}","preventionTips":["Guard zero quantity at order construction time","Review sizing math for floor-to-zero on small balances","Skip rather than submit zero-sized orders","Add unit tests for fee-heavy sizing edge cases"],"tags":["validation","quantity","order","zero-value"],"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-23T08:17:48.524Z"}