{"record":{"id":"b5b466776ddf08b1","repo":"nautechsystems/nautilus_trader","slug":"value-rounded-to-zero-for-quantity","errorCode":null,"errorMessage":"value rounded to zero for quantity","messagePattern":"value rounded to zero for quantity","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/model/src/instruments/mod.rs","lineNumber":445,"sourceCode":"    ///\n    /// Returns an error if the value rounds to zero or cannot be converted to a `Quantity`.\n    #[inline(always)]\n    fn try_make_qty_from_decimal(\n        &self,\n        value: Decimal,\n        round_down: Option<bool>,\n    ) -> anyhow::Result<Quantity> {\n        let precision = u32::from(self.min_size_increment_precision());\n\n        let strategy = if round_down.unwrap_or(false) {\n            RoundingStrategy::ToZero\n        } else {\n            RoundingStrategy::MidpointNearestEven\n        };\n\n        let rounded = value.round_dp_with_strategy(precision, strategy);\n        if value > Decimal::ZERO && rounded.is_zero() {\n            anyhow::bail!(\"value rounded to zero for quantity\");\n        }\n\n        Quantity::from_decimal_dp(rounded, self.size_precision()).map_err(Into::into)\n    }\n\n    /// # Panics\n    ///\n    /// Panics if the value cannot be converted to a `Quantity` (see `try_make_qty_from_decimal`).\n    fn make_qty_from_decimal(&self, value: Decimal, round_down: Option<bool>) -> Quantity {\n        self.try_make_qty_from_decimal(value, round_down).unwrap()\n    }\n\n    /// # Errors\n    ///\n    /// Returns an error if the value is not finite, not representable as a `Decimal`, rounds to\n    /// zero, or cannot be converted to a `Quantity`.\n    #[inline(always)]\n    fn try_make_qty(&self, value: f64, round_down: Option<bool>) -> anyhow::Result<Quantity> {","sourceCodeStart":427,"sourceCodeEnd":463,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/instruments/mod.rs#L427-L463","documentation":"Instrument::try_make_qty_from_decimal rounds a Decimal value to the instrument's size precision; if a strictly positive value rounds down to zero at that precision, the resulting quantity would be meaningless, so it bails instead of returning Quantity(0).","triggerScenarios":"Calling make_qty_from_decimal / try_make_qty with a positive value smaller than half of the instrument's size_increment (e.g. 0.0004 on an instrument with 3-decimal size precision where rounding yields 0.000).","commonSituations":"Computing position sizes from small notional amounts or high-priced assets, converting notional to base quantity for tokens with coarse size precision, or sizing dust rebalances below the minimum increment.","solutions":["Clamp or reject order sizes below the instrument's min quantity / size increment before calling make_qty.","Skip or batch trades whose computed size rounds to zero.","Verify you are using an instrument definition with the correct size_precision for the asset."],"exampleFix":"// before\nlet qty = instrument.make_qty_from_decimal(notional / price, None)?;\n// after\nlet raw = notional / price;\nif raw > Decimal::ZERO && raw.round_dp(instrument.size_precision().into()).is_zero() {\n    return Ok(None); // size below minimum increment, skip\n}\nlet qty = instrument.make_qty_from_decimal(raw, None)?;","handlingStrategy":"validation","validationCode":"let min_incr = Decimal::new(1, u32::from(instrument.size_precision()));\nlet ok = raw.is_zero() || raw >= min_incr / Decimal::TWO;","typeGuard":null,"tryCatchPattern":"match instrument.try_make_qty(raw, None) {\n    Ok(q) if !q.is_zero() => { /* trade */ }\n    _ => { /* size below increment: skip */ }\n}","preventionTips":["Enforce min_size_increment / min_quantity checks on every computed order size.","Aggregate dust-sized trades into larger batches."],"tags":["quantity","precision","rounding"],"backgroundTag":"value-out-of-range","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"}