{"record":{"id":"05463f65d37c07a0","repo":"nautechsystems/nautilus_trader","slug":"cancel-all-response-contains-an-order-for-a-differ","errorCode":null,"errorMessage":"cancel-all response contains an order for a different instrument","messagePattern":"cancel-all response contains an order for a different instrument","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/spot/execution.rs","lineNumber":1969,"sourceCode":"        let lifecycle_lock = self.lifecycle_lock.clone();\n\n        // Build strategy lookup from cache before spawning (cache is not Send)\n        let strategy_lookup: AHashMap<ClientOrderId, StrategyId> = {\n            let cache = self.core.cache();\n            cache\n                .orders_open(None, Some(&cmd.instrument_id), None, None, None)\n                .into_iter()\n                .map(|order| (order.client_order_id(), order.strategy_id()))\n                .collect()\n        };\n\n        let command = cmd;\n        self.spawn_task(\"cancel_all_orders_http\", async move {\n            let responses = http_client\n                .cancel_all_order_responses(command.instrument_id)\n                .await?;\n            let canceled_orders = prepare_cancel_all_orders(responses)?;\n            anyhow::ensure!(\n                canceled_orders\n                    .iter()\n                    .all(|order| order.instrument_id == command.instrument_id),\n                \"cancel-all response contains an order for a different instrument\",\n            );\n            let _lifecycle_guard = lifecycle_lock.lock();\n\n            for canceled_order in canceled_orders {\n                let client_order_id = canceled_order.client_order_id;\n                if canceled_order.order_list {\n                    dispatch_order_list_canceled(\n                        &canceled_order,\n                        &event_emitter,\n                        account_id,\n                        &dispatch_state,\n                        clock.get_time_ns(),\n                    );\n                    continue;","sourceCodeStart":1951,"sourceCodeEnd":1987,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/binance/src/spot/execution.rs#L1951-L1987","documentation":"Binance's cancel-all-orders (openOrders delete) response returned a prepared cancel whose instrument_id does not match the instrument the cancel command targeted. The adapter validates the response before emitting cancel events so that order state is never mutated for the wrong instrument. This is a safety invariant violation on the exchange response, not a client request failure.","triggerScenarios":"Calling cancel_all_orders for instrument A while the HTTP cancel_all_order_responses call returns order reports that resolve to instrument B — e.g. the exchange response's symbol maps to a different InstrumentId, or the response contains stale/foreign symbols such as orders in a different quote asset.","commonSituations":"Exchange responses mixing symbols during rapid cancel-all on a multi-symbol account; symbol-to-InstrumentId mapping drift after instrument redefinition; a buggy or intercepted HTTP response.","solutions":["Log the raw cancel_all_order_responses payload and the offending order's instrument_id to identify which symbol mismatched","Verify the InstrumentId passed to cancel_all_orders matches the Binance symbol exactly (no stale instrument definition)","Retry cancel_all_orders once the mismatched response subsides; if it persists, report the exchange response inconsistency","Compare the instrument definition (crates/adapters/binance instrument parsing) against the returned symbol to rule out mapping drift"],"exampleFix":"// before\ncanceled_orders.iter().all(|order| order.instrument_id == command.instrument_id)\n// after\n// same check, but log the mismatch first to diagnose:\nfor order in &canceled_orders {\n    if order.instrument_id != command.instrument_id {\n        tracing::error!(\"cancel-all mismatch: got {} expected {}\", order.instrument_id, command.instrument_id);\n    }\n}","handlingStrategy":"try-catch","validationCode":"// Rust caller: verify command targets a live instrument before cancel\nassert_eq!(command.instrument_id, expected_instrument_id);","typeGuard":null,"tryCatchPattern":"match cancel_all_orders(command.instrument_id).await {\n    Ok(_) => {},\n    Err(e) if e.to_string().contains(\"different instrument\") => {\n        tracing::warn!(\"exchange returned foreign symbol in cancel-all; ignoring\");\n    },\n    Err(e) => return Err(e),\n}","preventionTips":["Keep instrument definitions synchronized with the exchange info snapshot","Cancel per instrument with exact InstrumentId matching exchange symbol","Log raw HTTP responses for cancel-all to enable debugging","Reconcile open orders after cancel-all rather than trusting the response alone"],"tags":["binance","cancel-orders","instrument-mismatch","response-validation"],"backgroundTag":"unexpected-response-shape","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"}