nautechsystems/nautilus_trader · error
invalid `value` for make_qty, was {value}
Error message
invalid `value` for make_qty, was {value} What it means
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.
Source
Thrown at crates/model/src/instruments/mod.rs:465
Quantity::from_decimal_dp(rounded, self.size_precision()).map_err(Into::into)
}
/// # Panics
///
/// Panics if the value cannot be converted to a `Quantity` (see `try_make_qty_from_decimal`).
fn make_qty_from_decimal(&self, value: Decimal, round_down: Option<bool>) -> Quantity {
self.try_make_qty_from_decimal(value, round_down).unwrap()
}
/// # Errors
///
/// Returns an error if the value is not finite, not representable as a `Decimal`, rounds to
/// zero, or cannot be converted to a `Quantity`.
#[inline(always)]
fn try_make_qty(&self, value: f64, round_down: Option<bool>) -> anyhow::Result<Quantity> {
let dec_value = Decimal::from_str(&value.to_string())
.map_err(|_| anyhow::anyhow!("invalid `value` for make_qty, was {value}"))?;
self.try_make_qty_from_decimal(dec_value, round_down)
}
/// # Panics
///
/// Panics if the value cannot be converted to a `Quantity` (see `try_make_qty`).
fn make_qty(&self, value: f64, round_down: Option<bool>) -> Quantity {
self.try_make_qty(value, round_down).unwrap()
}
/// Returns `quantity` rebuilt with the instrument precision when it is on the size grid.
///
/// # Errors
///
/// Returns an error when `quantity` is undefined or would require rounding.
#[inline(always)]
fn try_normalize_qty(&self, quantity: Quantity) -> CorrectnessResult<Quantity> {
if quantity.is_undefined() {View on GitHub (pinned to 18893faf8b)
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.
Example fix
// before let qty = instrument.make_qty(size / risk); // after let raw = size / risk; anyhow::ensure!(raw.is_finite() && raw > 0.0, "invalid size computed"); let qty = instrument.make_qty(raw);
Defensive patterns
Strategy: try-catch
Validate before calling
if !value.is_finite() || value <= 0.0 { return Err(TradeError::NonFiniteQty); } Try / catch
// Rust
let qty = instrument
.try_make_qty(value, None)
.map_err(|e| { log::warn!("qty build failed: {e}"); TradeError::BadQty })?; Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- invalid `value` for make_price, was {value}
- Binance Futures position has unresolved instrument {instrume
- AX requires whole contract quantities, was {}
- Order quantity must be at least 1 contract
- Quote-denominated quantities are not supported; quantity mus
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/31de8fc19dc775c6.
Report an issue: GitHub.