{"record":{"id":"faf6f975941bbcb3","repo":"nautechsystems/nautilus_trader","slug":"invalid-ordertype-order-type-for-trailing-stop","errorCode":null,"errorMessage":"Invalid `OrderType` {order_type} for trailing stop calculation","messagePattern":"Invalid `OrderType` (.+?) for trailing stop calculation","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/execution/src/trailing.rs","lineNumber":54,"sourceCode":"/// - the order type, trigger type, or trailing offset type is invalid.\n/// - the order lacks a required trigger, trailing offset, trailing offset type, or limit offset.\n/// - the calculated price cannot be represented as a [`Price`].\npub fn trailing_stop_calculate(\n    price_increment: Price,\n    trigger_px: Option<Price>,\n    order: &OrderAny,\n    bid: Option<Price>,\n    ask: Option<Price>,\n    last: Option<Price>,\n) -> anyhow::Result<(Option<Price>, Option<Price>)> {\n    let order_side = order.order_side();\n    let order_type = order.order_type();\n\n    if !matches!(\n        order_type,\n        OrderType::TrailingStopMarket | OrderType::TrailingStopLimit\n    ) {\n        anyhow::bail!(\"Invalid `OrderType` {order_type} for trailing stop calculation\");\n    }\n\n    // Seed from the current trigger only (never the activation price): when the trigger has\n    // not yet materialized it stays `None` here so the offset candidate below becomes the\n    // initial trigger on the first update (matches v1 `TrailingStopCalculator`).\n    let mut trigger_price = trigger_px.or(order.trigger_price());\n\n    let mut limit_price = if order_type == OrderType::TrailingStopLimit {\n        order.price()\n    } else {\n        None\n    };\n\n    let trigger_type = order\n        .trigger_type()\n        .ok_or_else(|| anyhow::anyhow!(\"Missing `TriggerType` for trailing stop calculation\"))?;\n    let trailing_offset = order.trailing_offset().ok_or_else(|| {\n        anyhow::anyhow!(\"Missing `trailing_offset` for trailing stop calculation\")","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/execution/src/trailing.rs#L36-L72","documentation":"trailing_stop_calculate only supports trailing stop orders; the check `matches!(order_type, TrailingStopMarket | TrailingStopLimit)` guards the offset/trigger math that follows. Passing any other OrderType means the caller routed a non-trailing order into a trailing-stop-only code path, so the library refuses to compute a trailing stop price for it.","triggerScenarios":"Calling trailing_stop_calculate (directly or via update_trailing_stop_order) with an order whose order_type() is e.g. StopMarket, StopLimit, Limit, or MarketOrder instead of TrailingStopMarket/TrailingStopLimit.","commonSituations":"An order factory or strategy code emits a plain StopMarket but then the risk/trailing module tries to update it as trailing; refactoring changed the constructed order type; a bug passes a parsed order of the wrong type from a venue adapter.","solutions":["Ensure the order is created as OrderType::TrailingStopMarket or OrderType::TrailingStopLimit before calling trailing_stop_calculate.","In the caller, branch on order.order_type() and route non-trailing orders to a different update path.","Check the order factory / venue adapter mapping that produced the order for a mislabeled order type."],"exampleFix":"// before\nlet order = factory.stop_market(...);\nupdate_trailing_stop_order(&order, ...)?; // bails: invalid OrderType\n// after\nlet order = factory.trailing_stop_market(...);\nupdate_trailing_stop_order(&order, ...)?;","handlingStrategy":"validation","validationCode":"fn ensure_trailing(order: &dyn Order) -> anyhow::Result<()> {\n    matches!(order.order_type(), OrderType::TrailingStopMarket | OrderType::TrailingStopLimit)\n        .then_some(())\n        .ok_or_else(|| anyhow::anyhow!(\"order {} is not a trailing stop\", order.client_order_id()))\n}","typeGuard":"fn is_trailing_stop(order_type: OrderType) -> bool {\n    matches!(order_type, OrderType::TrailingStopMarket | OrderType::TrailingStopLimit)\n}","tryCatchPattern":null,"preventionTips":["Construct trailing orders only through factory methods that guarantee the order type.","Route non-trailing order updates through separate handlers.","Add an assert/match check in strategy code before invoking trailing calculations."],"tags":["trailing-stop","order-type","validation","rust"],"backgroundTag":"invalid-enum-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"}