{"record":{"id":"6b100416b1e292e4","repo":"nautechsystems/nautilus_trader","slug":"markettolimit-order-price-not-set","errorCode":null,"errorMessage":"MarketToLimit order price not set","messagePattern":"MarketToLimit order price not set","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/model/src/orders/any.rs","lineNumber":316,"sourceCode":"pub enum LimitOrderAny {\n    Limit(LimitOrder),\n    MarketToLimit(MarketToLimitOrder),\n    StopLimit(StopLimitOrder),\n    TrailingStopLimit(TrailingStopLimitOrder),\n    MarketOrderWithProtection(MarketOrder),\n}\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(),","sourceCodeStart":298,"sourceCodeEnd":334,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/orders/any.rs#L298-L334","documentation":"OrderAny::limit_px returns the limit price of the contained order. MarketToLimit orders store their price as Option<Price> (initially None; it is set when the order is converted to a limit order on the venue), so calling limit_px before a price exists panics with 'MarketToLimit order price not set'.","triggerScenarios":"Calling OrderAny::limit_px() on an order that is OrderAny::MarketToLimit while order.price is still None, i.e. before the venue-side conversion has produced a limit price.","commonSituations":"Strategy or reporting code that calls limit_px uniformly across all order variants without first checking the order type, or processing a freshly-submitted MarketToLimit order that has not yet received its determined-price update.","solutions":["Only call limit_px for order types with a guaranteed price (Limit, StopLimit); handle MarketToLimit and TrailingStopLimit separately.","For MarketToLimit, read the price via a method returning Option<Price> or check order.price is Some first.","Wait for the order's price to be determined (e.g. after the PriceDetermined/updated event) before querying limit_px."],"exampleFix":"// before\nlet px = order.limit_px(); // panics for MarketToLimit with no price\n// after\nlet px = match order {\n    OrderAny::MarketToLimit(o) => o.price, // Option<Price>\n    _ => Some(order.limit_px()),\n};","handlingStrategy":"type-guard","validationCode":"let px = match &order {\n    OrderAny::MarketToLimit(o) => o.price,\n    OrderAny::MarketOrderWithProtection(o) => o.protection_price,\n    _ => Some(order.limit_px()),\n};","typeGuard":"fn safe_limit_px(order: &OrderAny) -> Option<Price> {\n    match order {\n        OrderAny::MarketToLimit(o) => o.price,\n        OrderAny::TrailingStopLimit(o) => o.price,\n        OrderAny::MarketOrderWithProtection(o) => o.protection_price,\n        _ => Some(order.limit_px()),\n    }\n}","tryCatchPattern":"// limit_px panics, not returns Result; guard the variant before calling\nlet px = safe_limit_px(&order).expect(\"order has no price yet\");","preventionTips":["Match on the order variant before accessing prices on optional-price types.","Remember MarketToLimit gets its price only after venue-side price determination.","Prefer Option-returning accessors in strategy code over panicking helpers."],"tags":["rust","panic","optional-price","market-to-limit"],"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"}