nautechsystems/nautilus_trader · error · anyhow::Error
value rounded to zero for quantity
Error message
value rounded to zero for quantity
What it means
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).
Source
Thrown at crates/model/src/instruments/mod.rs:445
///
/// Returns an error if the value rounds to zero or cannot be converted to a `Quantity`.
#[inline(always)]
fn try_make_qty_from_decimal(
&self,
value: Decimal,
round_down: Option<bool>,
) -> anyhow::Result<Quantity> {
let precision = u32::from(self.min_size_increment_precision());
let strategy = if round_down.unwrap_or(false) {
RoundingStrategy::ToZero
} else {
RoundingStrategy::MidpointNearestEven
};
let rounded = value.round_dp_with_strategy(precision, strategy);
if value > Decimal::ZERO && rounded.is_zero() {
anyhow::bail!("value rounded to zero for quantity");
}
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> {View on GitHub (pinned to 18893faf8b)
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.
Example fix
// before
let qty = instrument.make_qty_from_decimal(notional / price, None)?;
// after
let raw = notional / price;
if raw > Decimal::ZERO && raw.round_dp(instrument.size_precision().into()).is_zero() {
return Ok(None); // size below minimum increment, skip
}
let qty = instrument.make_qty_from_decimal(raw, None)?; Defensive patterns
Strategy: validation
Validate before calling
let min_incr = Decimal::new(1, u32::from(instrument.size_precision())); let ok = raw.is_zero() || raw >= min_incr / Decimal::TWO;
Try / catch
match instrument.try_make_qty(raw, None) {
Ok(q) if !q.is_zero() => { /* trade */ }
_ => { /* size below increment: skip */ }
} Prevention
- Enforce min_size_increment / min_quantity checks on every computed order size.
- Aggregate dust-sized trades into larger batches.
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- Order quantity {quantity} is not exactly representable in {d
- quantity size={} cannot be represented with precision={}
- invalid {field}='{raw}' at precision {precision}: {e}
- invalid {name} quantity: {e}
- Failed to parse '{field_name}' value '{value}' into Quantity
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/b5b466776ddf08b1.
Report an issue: GitHub.