nautechsystems/nautilus_trader · error

invalid `value` for make_price, was {value}

Error message

invalid `value` for make_price, was {value}

What it means

Instrument::try_make_price converts an f64 to a Decimal via its string representation and then to a Price. If the f64 cannot be parsed into a Decimal (NaN, infinity, or a value Decimal cannot represent), this error is returned before any price-precision conversion happens.

Source

Thrown at crates/model/src/instruments/mod.rs:340

            value.round_dp_with_strategy(precision, RoundingStrategy::MidpointNearestEven);
        Price::from_decimal_dp(rounded_decimal, self.price_precision()).map_err(Into::into)
    }

    /// # Panics
    ///
    /// Panics if the value cannot be converted to a `Price` (see `try_make_price_from_decimal`).
    fn make_price_from_decimal(&self, value: Decimal) -> Price {
        self.try_make_price_from_decimal(value).unwrap()
    }

    /// # Errors
    ///
    /// Returns an error if the value is not finite, not representable as a `Decimal`, or cannot
    /// be converted to a `Price`.
    #[inline(always)]
    fn try_make_price(&self, value: f64) -> anyhow::Result<Price> {
        let dec_value = Decimal::from_str(&value.to_string())
            .map_err(|_| anyhow::anyhow!("invalid `value` for make_price, was {value}"))?;
        self.try_make_price_from_decimal(dec_value)
    }

    /// # Panics
    ///
    /// Panics if the value cannot be converted to a `Price` (see `try_make_price`).
    fn make_price(&self, value: f64) -> Price {
        self.try_make_price(value).unwrap()
    }

    /// Returns `price` rebuilt with the instrument precision when it is on the price grid.
    ///
    /// # Errors
    ///
    /// Returns an error when `price` is a sentinel value or would require rounding.
    #[inline(always)]
    fn try_normalize_price(&self, price: Price) -> CorrectnessResult<Price> {
        if price == ERROR_PRICE {

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Check value.is_finite() before calling make_price and handle NaN/infinity upstream.
  2. Round/sanitize the computed value to a sane magnitude before conversion.
  3. Prefer try_make_price (Result-returning) and map the error instead of panicking via make_price.

Example fix

// before
let price = instrument.make_price(sma / len);
// after
let raw = sma / len;
anyhow::ensure!(raw.is_finite(), "non-finite price computed");
let price = instrument.make_price(raw);
Defensive patterns

Strategy: try-catch

Validate before calling

if !value.is_finite() { return Err(TradeError::NonFinitePrice); }

Try / catch

// Rust
let price = instrument
    .try_make_price(value)
    .map_err(|e| { log::warn!("price build failed: {e}"); TradeError::BadPrice })?;

Prevention

When it happens

Trigger: Calling instrument.make_price(f64::NAN), make_price(f64::INFINITY), or a value whose textual form Decimal::from_str rejects; also any path through make_price that forwards such values.

Common situations: Computing a price from an upstream indicator that yielded NaN (division by zero, empty data), propagating a sentinel infinite value from a calculation, or passing unset/optional values straight into make_price.

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


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/f11b6cc28ae2b190. Report an issue: GitHub.