{"record":{"id":"8c6bf3d7f29b5b25","repo":"nautechsystems/nautilus_trader","slug":"no-price-for-order","errorCode":null,"errorMessage":"No price for order","messagePattern":"No price for order","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/model/src/orders/any.rs","lineNumber":322,"sourceCode":"}\n\nimpl LimitOrderAny {\n    /// Returns the limit price for this order.\n    ///\n    /// # Panics\n    ///\n    /// Panics if the `MarketToLimit` order price is not set.\n    #[must_use]\n    pub fn limit_px(&self) -> Price {\n        match self {\n            Self::Limit(order) => order.price,\n            Self::MarketToLimit(order) => order.price.expect(\"MarketToLimit order price not set\"),\n            Self::StopLimit(order) => order.price,\n            Self::TrailingStopLimit(order) => {\n                order.price.expect(\"TrailingStopLimit order price not set\")\n            }\n            Self::MarketOrderWithProtection(order) => {\n                order.protection_price.expect(\"No price for order\")\n            }\n        }\n    }\n}\n\nimpl PartialEq for LimitOrderAny {\n    fn eq(&self, rhs: &Self) -> bool {\n        match self {\n            Self::Limit(order) => order.client_order_id == rhs.client_order_id(),\n            Self::MarketToLimit(order) => order.client_order_id == rhs.client_order_id(),\n            Self::StopLimit(order) => order.client_order_id == rhs.client_order_id(),\n            Self::TrailingStopLimit(order) => order.client_order_id == rhs.client_order_id(),\n            Self::MarketOrderWithProtection(order) => {\n                order.client_order_id == rhs.client_order_id()\n            }\n        }\n    }\n}","sourceCodeStart":304,"sourceCodeEnd":340,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/orders/any.rs#L304-L340","documentation":"OrderAny::limit_px on MarketOrderWithProtection variants unwraps protection_price, which is optional; if no protection price was supplied when the order was created, the call panics with 'No price for order'.","triggerScenarios":"Calling OrderAny::limit_px() on an OrderAny::MarketOrderWithProtection that was built without .protection_price (or equivalent) set.","commonSituations":"Generic price-reporting code that calls limit_px on every order in a cache, where market orders with protection legitimately may have no price.","solutions":["Set the protection price when constructing MarketOrderWithProtection orders if downstream code reads limit_px.","Skip MarketOrderWithProtection orders (or handle their price as Option) in generic limit_px loops.","Use a price accessor that returns Option<Price> instead of the panicking limit_px."],"exampleFix":"// before\nlet px = order.limit_px(); // panics when protection_price is None\n// after\nif matches!(order, OrderAny::MarketOrderWithProtection(_)) { continue; } // no price to report\nlet px = order.limit_px();","handlingStrategy":"type-guard","validationCode":"let px = match &order {\n    OrderAny::MarketOrderWithProtection(o) => o.protection_price,\n    _ => Some(order.limit_px()),\n};","typeGuard":"fn order_price_opt(order: &OrderAny) -> Option<Price> {\n    match order {\n        OrderAny::MarketOrderWithProtection(o) => o.protection_price,\n        OrderAny::MarketToLimit(o) => o.price,\n        OrderAny::TrailingStopLimit(o) => o.price,\n        _ => Some(order.limit_px()),\n    }\n}","tryCatchPattern":"// skip or default instead of calling limit_px on price-less market orders\nlet px = order_price_opt(&order).unwrap_or_default();","preventionTips":["Do not call limit_px uniformly on all order variants in reporting loops.","Set protection_price at construction when downstream code expects a price.","Filter out price-less order types (Market, MarketOrderWithProtection) before price aggregation."],"tags":["rust","panic","optional-price","market-order"],"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-14T00:17:10.932Z"}