nautechsystems/nautilus_trader · error
MarketToLimit order price not set
Error message
MarketToLimit order price not set
What it means
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'.
Source
Thrown at crates/model/src/orders/any.rs:316
pub enum LimitOrderAny {
Limit(LimitOrder),
MarketToLimit(MarketToLimitOrder),
StopLimit(StopLimitOrder),
TrailingStopLimit(TrailingStopLimitOrder),
MarketOrderWithProtection(MarketOrder),
}
impl LimitOrderAny {
/// Returns the limit price for this order.
///
/// # Panics
///
/// Panics if the `MarketToLimit` order price is not set.
#[must_use]
pub fn limit_px(&self) -> Price {
match self {
Self::Limit(order) => order.price,
Self::MarketToLimit(order) => order.price.expect("MarketToLimit order price not set"),
Self::StopLimit(order) => order.price,
Self::TrailingStopLimit(order) => {
order.price.expect("TrailingStopLimit order price not set")
}
Self::MarketOrderWithProtection(order) => {
order.protection_price.expect("No price for order")
}
}
}
}
impl PartialEq for LimitOrderAny {
fn eq(&self, rhs: &Self) -> bool {
match self {
Self::Limit(order) => order.client_order_id == rhs.client_order_id(),
Self::MarketToLimit(order) => order.client_order_id == rhs.client_order_id(),
Self::StopLimit(order) => order.client_order_id == rhs.client_order_id(),
Self::TrailingStopLimit(order) => order.client_order_id == rhs.client_order_id(),View on GitHub (pinned to 18893faf8b)
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.
Example fix
// before
let px = order.limit_px(); // panics for MarketToLimit with no price
// after
let px = match order {
OrderAny::MarketToLimit(o) => o.price, // Option<Price>
_ => Some(order.limit_px()),
}; Defensive patterns
Strategy: type-guard
Validate before calling
let px = match &order {
OrderAny::MarketToLimit(o) => o.price,
OrderAny::MarketOrderWithProtection(o) => o.protection_price,
_ => Some(order.limit_px()),
}; Type guard
fn safe_limit_px(order: &OrderAny) -> Option<Price> {
match order {
OrderAny::MarketToLimit(o) => o.price,
OrderAny::TrailingStopLimit(o) => o.price,
OrderAny::MarketOrderWithProtection(o) => o.protection_price,
_ => Some(order.limit_px()),
}
} Try / catch
// limit_px panics, not returns Result; guard the variant before calling
let px = safe_limit_px(&order).expect("order has no price yet"); Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
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
- TrailingStopLimit order price not set
- No price for order
- in-flight mutex poisoned
- wallet balance mutex poisoned
- instrument update lock poisoned
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/6b100416b1e292e4.
Report an issue: GitHub.