nautechsystems/nautilus_trader · error
invalid notional value
Error message
invalid notional value
What it means
The infallible `calculate_notional_value` is a thin wrapper over `try_calculate_notional_value` and panics with "invalid notional value" when the fallible computation returns an error. Errors arise from invalid arithmetic inputs — e.g. a zero/invalid price or quantity for the instrument type, or an inverse instrument without base currency where quote conversion is disallowed. The panic intentionally surfaces invalid inputs that the typed API assumed could not occur.
Source
Thrown at crates/model/src/instruments/mod.rs:611
self.multiplier(),
self.is_inverse(),
use_quote_inverse,
currency,
)
}
/// # Panics
///
/// Panics if [`Instrument::try_calculate_notional_value`] returns an error.
#[inline(always)]
fn calculate_notional_value(
&self,
quantity: Quantity,
price: Price,
use_quote_for_inverse: Option<bool>,
) -> Money {
self.try_calculate_notional_value(quantity, price, use_quote_for_inverse)
.expect("invalid notional value")
}
#[inline(always)]
fn next_bid_price(&self, value: f64, n: i32) -> Option<Price> {
if n < 0 {
return None;
}
let price = if let Some(scheme) = self.tick_scheme_rule() {
scheme.next_bid_price(value, n, self.price_precision())?
} else {
let value = Decimal::from_str(&value.to_string()).ok()?;
let increment = self.price_increment().as_decimal();
if increment.is_zero() {
return None;
}
let base = (value / increment).floor() * increment;
let result = base - Decimal::from(n) * increment;View on GitHub (pinned to 18893faf8b)
Solutions
- Validate that price > 0 and quantity > 0 before calling calculate_notional_value.
- For inverse instruments, pass Some(true) for use_quote_for_inverse if you want quote-currency notional, or ensure the instrument has a base currency.
- Switch to try_calculate_notional_value and handle the Result to avoid the panic.
- Check the instrument definition (currencies, precision) is fully populated from the adapter.
Example fix
// before
let notional = inst.calculate_notional_value(qty, Price::zero(), None); // panics
// after
let notional = inst.try_calculate_notional_value(qty, price, None)
.map_err(|e| log::error!("notional calc failed: {e}"))?; Defensive patterns
Strategy: validation
Validate before calling
// Rust caller
if price.as_f64() <= 0.0 || quantity.as_f64() <= 0.0 {
return Err("notional requires positive price and quantity");
}
let notional = instrument.calculate_notional_value(quantity, price, None); Type guard
fn notional_inputs_valid(q: Quantity, p: Price) -> bool {
!p.is_zero() && !q.is_zero()
} Try / catch
// Prefer the fallible API to avoid panics
match instrument.try_calculate_notional_value(qty, price, None) {
Ok(notional) => use(notional),
Err(e) => log::warn!("notional calc failed: {e}"),
} Prevention
- Check price/quantity are positive and initialized (not from an empty book) before computing.
- For inverse instruments, decide explicitly on use_quote_for_inverse semantics.
- Prefer try_calculate_notional_value in fallible contexts.
When it happens
Trigger: Calling calculate_notional_value(quantity, price, use_quote_for_inverse) with a zero or invalid Price/Quantity, or on an inverse instrument whose underlying try_ computation fails (e.g. inverse without base currency and use_quote_for_inverse not permitting the fallback).
Common situations: Feeding uninitialized/zero prices from an empty order book, passing mismatched price precision, or computing notional for an instrument definition loaded with missing currency fields.
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
- instrument update lock poisoned
- inverse instrument without base_currency
- invalid notional value
- in-flight mutex poisoned
- wallet balance mutex poisoned
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/956c8904f37627f0.
Report an issue: GitHub.