{"record":{"id":"b461e94ab5b9aa1a","repo":"nautechsystems/nautilus_trader","slug":"cannot-batch-modify-orders-for-different-instrumen","errorCode":null,"errorMessage":"Cannot batch modify orders for different instruments: {} vs {}","messagePattern":"Cannot batch modify orders for different instruments: (.+?) vs (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/trading/src/strategy/mod.rs","lineNumber":493,"sourceCode":"\n        let orders: Vec<OrderAny> = {\n            let cache_rc = StrategyNative::strategy_core_mut(self).cache_rc();\n            let cache = cache_rc.borrow();\n            updates\n                .iter()\n                .map(|(client_order_id, _, _, _)| {\n                    cache\n                        .try_order_owned(client_order_id)\n                        .map_err(|e| anyhow::anyhow!(\"Cannot modify order: {e}\"))\n                })\n                .collect::<Result<_, _>>()?\n        };\n\n        let instrument_id = orders[0].instrument_id();\n\n        for (order, (_, quantity, price, trigger_price)) in orders.iter().zip(updates.iter()) {\n            if order.instrument_id() != instrument_id {\n                anyhow::bail!(\n                    \"Cannot batch modify 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 modify\");\n            }\n\n            let mut updating = false;\n\n            if quantity.is_some_and(|q| q != order.quantity()) {\n                updating = true;\n            }\n\n            if let Some(price) = price {\n                if !LIMIT_ORDER_TYPES.contains(&order.order_type()) {","sourceCodeStart":475,"sourceCodeEnd":511,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/trading/src/strategy/mod.rs#L475-L511","documentation":"All orders in a batch modify must belong to the same instrument. During validation, each order's instrument_id is compared with the first order's; a mismatch aborts the whole batch since a single BatchModifyOrders command cannot span instruments.","triggerScenarios":"Passing orders for two or more different instrument_ids (e.g. AAPL.NASDAQ and MSFT.NASDAQ) in the same `orders` slice to `modify_orders`, even if updates align positionally.","commonSituations":"Collecting open orders from a cache across all instruments instead of per-instrument; loop variables capturing multiple symbols; merging order lists from different strategies or subscriptions.","solutions":["Partition the orders by instrument_id and issue one modify_orders call per instrument","Verify the collection/filter that builds the orders list only selects one instrument","Add an assert or filter on `order.instrument_id() == instrument_id` before the call"],"exampleFix":"// before\nstrategy.modify_orders(&orders, &updates, None, None).await?;\n// after\nfor (iid, group) in orders.iter().map(|o| o.instrument_id()).collect::<std::collections::HashSet<_>>() {\n    let subset: Vec<_> = orders.iter().filter(|o| o.instrument_id() == iid).collect();\n    strategy.modify_orders(&subset, &matching_updates, None, None).await?;\n}","handlingStrategy":"validation","validationCode":"let iid = orders[0].instrument_id();\nassert!(orders.iter().all(|o| o.instrument_id() == iid), \"batch spans multiple instruments\");","typeGuard":"fn same_instrument(orders: &[OrderAny]) -> bool {\n    orders.iter().map(|o| o.instrument_id()).all_equal()\n}","tryCatchPattern":"match strategy.modify_orders(&orders, &updates, None, None).await {\n    Err(e) if e.to_string().contains(\"different instruments\") => { /* partition per instrument and retry */ }\n    r => r?,\n}","preventionTips":["Collect orders per instrument_id, never across symbols","Filter the cache query by instrument_id","Add an assert before batch calls in strategy code"],"tags":["validation","batch-orders","instrument-mismatch"],"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"}