{"record":{"id":"f3996a32a0be6749","repo":"nautechsystems/nautilus_trader","slug":"cannot-create-command-batchmodifyorders-state-is","errorCode":null,"errorMessage":"Cannot create command BatchModifyOrders: state is {:?}, {order:?}","messagePattern":"Cannot create command BatchModifyOrders: state is (.+?), (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/trading/src/strategy/mod.rs","lineNumber":542,"sourceCode":"                        order.order_type()\n                    );\n                }\n\n                if Some(*trigger_price) != order.trigger_price() {\n                    updating = true;\n                }\n            }\n\n            if !updating {\n                anyhow::bail!(\n                    \"Cannot create command BatchModifyOrders: quantity, price, and trigger were \\\n                    either None or the same as existing values for {}\",\n                    order.client_order_id()\n                );\n            }\n\n            if order.is_closed() || order.is_pending_cancel() {\n                anyhow::bail!(\n                    \"Cannot create command BatchModifyOrders: state is {:?}, {order:?}\",\n                    order.status()\n                );\n            }\n        }\n\n        let params = params.filter(|params| !params.is_empty());\n        let mut modifies = Vec::with_capacity(orders.len());\n\n        for (order, (_, quantity, price, trigger_price)) in orders.into_iter().zip(updates) {\n            if !self.mark_order_pending_update(&order)? {\n                continue;\n            }\n\n            modifies.push(ModifyOrder::new(\n                trader_id,\n                client_id,\n                strategy_id,","sourceCodeStart":524,"sourceCodeEnd":560,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/trading/src/strategy/mod.rs#L524-L560","documentation":"The order is in a terminal state (is_closed) or has a pending cancel, so a batch modify command cannot be created. Modifying such an order would be invalid; the error includes the order's status and full debug representation.","triggerScenarios":"Including a filled, canceled, expired, denied, or pending-cancel order in the batch passed to modify_orders.","commonSituations":"Stale order handles captured earlier in the strategy while the order filled or was canceled in the meantime; racing between cancel_all and modify_orders; rebatching open orders read from a cache just before they fill.","solutions":["Filter the batch to orders where !order.is_closed() && !order.is_pending_cancel() before calling","Re-read current order status from the cache immediately before building the batch","Handle the race with retry: drop the offending order and re-issue the batch for the rest"],"exampleFix":"// before\nlet batch: Vec<&OrderAny> = tracked_orders.iter().collect();\nstrategy.modify_orders(&batch, &updates, None, None).await?;\n// after\nlet batch: Vec<&OrderAny> = tracked_orders.iter()\n    .filter(|o| !o.is_closed() && !o.is_pending_cancel())\n    .collect();\nif !batch.is_empty() {\n    strategy.modify_orders(&batch, &updates, None, None).await?;\n}","handlingStrategy":"validation","validationCode":"let batch: Vec<_> = orders.iter()\n    .filter(|o| !o.is_closed() && !o.is_pending_cancel())\n    .collect();","typeGuard":"fn modifiable(o: &OrderAny) -> bool { !o.is_closed() && !o.is_pending_cancel() }","tryCatchPattern":null,"preventionTips":["Re-read order status immediately before batching","Subscribe to order events and drop stale handles on fill/cancel","Avoid racing cancel_all with modify_orders on the same orders"],"tags":["validation","batch-orders","order-state","stale-order"],"backgroundTag":"invalid-state-transition","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"}