{"record":{"id":"956c8904f37627f0","repo":"nautechsystems/nautilus_trader","slug":"invalid-notional-value","errorCode":null,"errorMessage":"invalid notional value","messagePattern":"invalid notional value","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/model/src/instruments/mod.rs","lineNumber":611,"sourceCode":"            self.multiplier(),\n            self.is_inverse(),\n            use_quote_inverse,\n            currency,\n        )\n    }\n\n    /// # Panics\n    ///\n    /// Panics if [`Instrument::try_calculate_notional_value`] returns an error.\n    #[inline(always)]\n    fn calculate_notional_value(\n        &self,\n        quantity: Quantity,\n        price: Price,\n        use_quote_for_inverse: Option<bool>,\n    ) -> Money {\n        self.try_calculate_notional_value(quantity, price, use_quote_for_inverse)\n            .expect(\"invalid notional value\")\n    }\n\n    #[inline(always)]\n    fn next_bid_price(&self, value: f64, n: i32) -> Option<Price> {\n        if n < 0 {\n            return None;\n        }\n\n        let price = if let Some(scheme) = self.tick_scheme_rule() {\n            scheme.next_bid_price(value, n, self.price_precision())?\n        } else {\n            let value = Decimal::from_str(&value.to_string()).ok()?;\n            let increment = self.price_increment().as_decimal();\n            if increment.is_zero() {\n                return None;\n            }\n            let base = (value / increment).floor() * increment;\n            let result = base - Decimal::from(n) * increment;","sourceCodeStart":593,"sourceCodeEnd":629,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/instruments/mod.rs#L593-L629","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nlet notional = inst.calculate_notional_value(qty, Price::zero(), None); // panics\n// after\nlet notional = inst.try_calculate_notional_value(qty, price, None)\n    .map_err(|e| log::error!(\"notional calc failed: {e}\"))?;","handlingStrategy":"validation","validationCode":"// Rust caller\nif price.as_f64() <= 0.0 || quantity.as_f64() <= 0.0 {\n    return Err(\"notional requires positive price and quantity\");\n}\nlet notional = instrument.calculate_notional_value(quantity, price, None);","typeGuard":"fn notional_inputs_valid(q: Quantity, p: Price) -> bool {\n    !p.is_zero() && !q.is_zero()\n}","tryCatchPattern":"// Prefer the fallible API to avoid panics\nmatch instrument.try_calculate_notional_value(qty, price, None) {\n    Ok(notional) => use(notional),\n    Err(e) => log::warn!(\"notional calc failed: {e}\"),\n}","preventionTips":["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."],"tags":["rust","panic","instruments","notional"],"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"}