{"record":{"id":"edf8a87f61ecab58","repo":"nautechsystems/nautilus_trader","slug":"cannot-include-emulated-or-local-orders-in-batch-c","errorCode":null,"errorMessage":"Cannot include emulated or local orders in batch cancel","messagePattern":"Cannot include emulated or local orders in batch cancel","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/trading/src/strategy/mod.rs","lineNumber":722,"sourceCode":"                        .try_order_owned(id)\n                        .map_err(|e| anyhow::anyhow!(\"Cannot cancel order: {e}\"))\n                })\n                .collect::<Result<_, _>>()?\n        };\n\n        let instrument_id = orders[0].instrument_id();\n\n        for order in &orders {\n            if order.instrument_id() != instrument_id {\n                anyhow::bail!(\n                    \"Cannot batch cancel orders for different instruments: {} vs {}\",\n                    instrument_id,\n                    order.instrument_id()\n                );\n            }\n\n            if order.is_emulated() || order.is_active_local() {\n                anyhow::bail!(\"Cannot include emulated or local orders in batch cancel\");\n            }\n        }\n\n        let mut cancels = Vec::with_capacity(orders.len());\n\n        for order in orders {\n            if !self.mark_order_pending_cancel(&order)? {\n                continue;\n            }\n\n            cancels.push(CancelOrder::new(\n                trader_id,\n                client_id,\n                strategy_id,\n                instrument_id,\n                order.client_order_id(),\n                order.venue_order_id(),\n                UUID4::new(),","sourceCodeStart":704,"sourceCodeEnd":740,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/trading/src/strategy/mod.rs#L704-L740","documentation":"Batch cancel only supports orders routed directly to the venue. Emulated or active-local orders are managed by the execution emulator/risk engine, so they are rejected from BatchCancelOrders commands.","triggerScenarios":"Passing a client_order_id whose resolved order has `is_emulated()` or `is_active_local()` true to `cancel_orders`.","commonSituations":"Emulated contingent orders on venues without native support; blanket 'cancel all working orders' sweeps that include emulated orders; mixing direct and emulated orders collected from the cache.","solutions":["Exclude emulated/active-local orders from the batch and cancel them individually via cancel_order","Filter: if order.is_emulated() || order.is_active_local() { strategy.cancel_order(...) } else { include in batch }","Adjust emulation config if direct venue cancels should cover these orders"],"exampleFix":"// before\nstrategy.cancel_orders(&ids, instrument_id, None, None).await?;\n// after\nlet (direct, emulated): (Vec<_>, Vec<_>) = orders.iter()\n    .partition(|o| !o.is_emulated() && !o.is_active_local());\nif !direct.is_empty() {\n    strategy.cancel_orders(&ids_for(direct), instrument_id, None, None).await?;\n}\nfor o in &emulated {\n    strategy.cancel_order(o.client_order_id(), None).await?;\n}","handlingStrategy":"validation","validationCode":"let direct: Vec<_> = ids.iter()\n    .filter(|id| !cache.order(id).map(|o| o.is_emulated() || o.is_active_local()).unwrap_or(false))\n    .collect();","typeGuard":"fn batch_cancel_eligible(o: &OrderAny) -> bool { !o.is_emulated() && !o.is_active_local() }","tryCatchPattern":null,"preventionTips":["Exclude emulated/active-local orders from batch cancels","Cancel those orders individually via cancel_order","Audit emulation settings to know which orders they affect"],"tags":["validation","batch-orders","emulated-orders"],"backgroundTag":"unsupported-operation","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"}