{"record":{"id":"31de8fc19dc775c6","repo":"nautechsystems/nautilus_trader","slug":"invalid-value-for-make-qty-was-value","errorCode":null,"errorMessage":"invalid `value` for make_qty, was {value}","messagePattern":"invalid `value` for make_qty, was (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/model/src/instruments/mod.rs","lineNumber":465,"sourceCode":"\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> {\n        let dec_value = Decimal::from_str(&value.to_string())\n            .map_err(|_| anyhow::anyhow!(\"invalid `value` for make_qty, was {value}\"))?;\n        self.try_make_qty_from_decimal(dec_value, round_down)\n    }\n\n    /// # Panics\n    ///\n    /// Panics if the value cannot be converted to a `Quantity` (see `try_make_qty`).\n    fn make_qty(&self, value: f64, round_down: Option<bool>) -> Quantity {\n        self.try_make_qty(value, round_down).unwrap()\n    }\n\n    /// Returns `quantity` rebuilt with the instrument precision when it is on the size grid.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error when `quantity` is undefined or would require rounding.\n    #[inline(always)]\n    fn try_normalize_qty(&self, quantity: Quantity) -> CorrectnessResult<Quantity> {\n        if quantity.is_undefined() {","sourceCodeStart":447,"sourceCodeEnd":483,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/instruments/mod.rs#L447-L483","documentation":"Instrument::try_make_qty converts an f64 to a Decimal via its string representation before building a Quantity. If the value cannot be parsed as a Decimal (NaN, infinity, unrepresentable value), this error is returned.","triggerScenarios":"Calling instrument.make_qty(f64::NAN), make_qty(f64::INFINITY), or forwarding a computed quantity that Decimal::from_str cannot parse; also via make_qty wrappers passing raw calculation output.","commonSituations":"Position sizing math that divides by zero producing NaN/infinity, passing a None/default sentinel value, or feeding cumulative PnL-derived sizes that overflow into non-finite values.","solutions":["Validate value.is_finite() before calling make_qty and sanitize upstream math.","Clamp the computed size to instrument limits (min/max quantity) before conversion.","Use try_make_qty and handle the Result instead of relying on the panicking make_qty wrapper."],"exampleFix":"// before\nlet qty = instrument.make_qty(size / risk);\n// after\nlet raw = size / risk;\nanyhow::ensure!(raw.is_finite() && raw > 0.0, \"invalid size computed\");\nlet qty = instrument.make_qty(raw);","handlingStrategy":"try-catch","validationCode":"if !value.is_finite() || value <= 0.0 { return Err(TradeError::NonFiniteQty); }","typeGuard":null,"tryCatchPattern":"// Rust\nlet qty = instrument\n    .try_make_qty(value, None)\n    .map_err(|e| { log::warn!(\"qty build failed: {e}\"); TradeError::BadQty })?;","preventionTips":["Check is_finite() on all sizing math before conversion","Clamp sizes to instrument min/max quantity first","Use try_make_qty instead of the panicking make_qty wrapper"],"tags":["quantity","decimal-conversion","nan","instrument"],"backgroundTag":"invalid-argument-value","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"}