{"record":{"id":"1b6a54da51035a55","repo":"nautechsystems/nautilus_trader","slug":"cannot-cancel-order-e","errorCode":null,"errorMessage":"Cannot cancel order: {e}","messagePattern":"Cannot cancel order: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/trading/src/strategy/mod.rs","lineNumber":627,"sourceCode":"        let (trader_id, strategy_id, ts_init) = {\n            let core = StrategyNative::strategy_core_mut(self);\n            (\n                registered_trader_id(core)?,\n                registered_strategy_id(core)?,\n                core.clock_mut().timestamp_ns(),\n            )\n        };\n\n        let params = params.filter(|params| !params.is_empty());\n\n        // TODO: Snapshot the order from the cache. Callers identify it by ID; we own the\n        // snapshot so later calls (which take `&OrderAny` and may re-enter the cache)\n        // run without holding a live cache borrow.\n        let order = StrategyNative::strategy_core_mut(self)\n            .cache_rc()\n            .borrow()\n            .try_order_owned(&client_order_id)\n            .map_err(|e| anyhow::anyhow!(\"Cannot cancel order: {e}\"))?;\n\n        if !self.mark_order_pending_cancel(&order)? {\n            return Ok(());\n        }\n\n        let command = CancelOrder::new(\n            trader_id,\n            client_id,\n            strategy_id,\n            order.instrument_id(),\n            order.client_order_id(),\n            order.venue_order_id(),\n            UUID4::new(),\n            ts_init,\n            params,\n            None, // correlation_id\n        );\n","sourceCodeStart":609,"sourceCodeEnd":645,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/trading/src/strategy/mod.rs#L609-L645","documentation":"Raised in `cancel_order` when the cache cannot return an owned snapshot of the order for the given client_order_id, so a CancelOrder command cannot be built. The strategy snapshots the order (releasing the cache borrow before later re-entrant calls) and fails fast if the lookup errors.","triggerScenarios":"Calling `cancel_order` (directly or via cancel_all_orders, dispatch_manager_actions, set_gtd_expiry, expire_gtd_order, reactivate_gtd_timers) with a client_order_id absent from the cache or not retrievable via `try_order_owned`.","commonSituations":"Cancelling an order already filled/expired and dropped from the live index, cancelling externally submitted orders not tracked by this strategy, or timer-based expiry firing for a stale order.","solutions":["Check cache.order(&client_order_id) is Some before cancelling.","Ensure cancel_all_orders / timers only run for orders still open in the cache.","Confirm the strategy owns the orders (correct client_id on submission).","Handle the error gracefully on reconnection where order state may not yet be reconciled."],"exampleFix":"// before\nstrategy.cancel_order(&stale_id)?;\n// after\nif let Some(order) = cache.order(&stale_id) {\n    if order.is_open() { strategy.cancel_order(&stale_id)?; }\n}","handlingStrategy":"validation","validationCode":"if cache.order(&client_order_id).is_none() { log::warn!(\"cannot cancel unknown order {client_order_id}\"); return; }","typeGuard":null,"tryCatchPattern":"if let Err(e) = strategy.cancel_order(&id) {\n    log::warn!(\"cancel failed for {id}: {e}\"); // skip instead of aborting cancel_all\n}","preventionTips":["Verify order is open in cache before cancel","Guard timer-based expiry handlers against stale IDs","Reconcile order state after reconnect before cancelling"],"tags":["rust","order-management","cache"],"backgroundTag":"record-not-found","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"}