{"record":{"id":"7e94d63f3675fa83","repo":"nautechsystems/nautilus_trader","slug":"order-reports-status-expected-canceled","errorCode":null,"errorMessage":"order {} reports status {:?}, expected Canceled","messagePattern":"order (.+?) reports status (.+?), expected Canceled","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/spot/execution.rs","lineNumber":2628,"sourceCode":") -> anyhow::Result<()> {\n    anyhow::ensure!(\n        response.order_id >= 0\n            && !response.symbol.is_empty()\n            && !response.orig_client_order_id.is_empty(),\n        \"cancel-all response has an invalid order ID, symbol, or original client order ID\",\n    );\n    anyhow::ensure!(\n        response.status == SbeOrderStatus::Canceled,\n        \"order {} reports status {:?}, expected Canceled\",\n        response.order_id,\n        response.status,\n    );\n    let client_order_id = decode_client_order_id(\n        &response.orig_client_order_id,\n        BINANCE_NAUTILUS_SPOT_BROKER_ID,\n    )?;\n    let instrument_id = InstrumentId::new(response.symbol.as_str().into(), *BINANCE_VENUE);\n    anyhow::ensure!(\n        order_ids.insert((instrument_id, response.order_id)),\n        \"cancel-all response contains duplicate order ID {} for {}\",\n        response.order_id,\n        instrument_id,\n    );\n    anyhow::ensure!(\n        client_order_ids.insert(client_order_id),\n        \"cancel-all response contains duplicate client order ID {client_order_id}\",\n    );\n    prepared.push(PreparedCancelOrder {\n        venue_order_id: VenueOrderId::new(response.order_id.to_string()),\n        transaction_time: response.transact_time,\n        client_order_id,\n        instrument_id,\n        order_list,\n    });\n    Ok(())\n}","sourceCodeStart":2610,"sourceCodeEnd":2646,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/binance/src/spot/execution.rs#L2610-L2646","documentation":"prepare_cancel_order requires every cancel-all/cancel-list child response to report SbeOrderStatus::Canceled. Any other status (e.g. NEW, PENDING_CANCEL, REJECTED, EXPIRED) fails this check because the adapter only treats an explicitly Canceled confirmation as a successful cancel.","triggerScenarios":"Calling cancel_all_orders / cancel_order_list when Binance reports a non-Canceled status for one of the child orders — e.g. the order was already filled, already canceled, or the cancel is still pending at the venue.","commonSituations":"Race conditions where the order fills just as cancel-all is issued; repeated cancels of the same order; canceling orders that expired via time-in-force (FOK/GTD).","solutions":["Check order status before canceling; skip already-terminal orders","Treat the error as a race condition and retry only orders still open","Use client.supplied_order_status / order status reports to reconcile state","Avoid duplicate cancels for the same order"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match result { Err(e) if e.to_string().contains(\"expected Canceled\") => { /* order likely already filled/canceled; query status and continue */ } Err(e) => return Err(e), Ok(_) => continue }","preventionTips":["Reconcile order state before canceling to skip terminal orders","Avoid issuing duplicate cancel requests for the same order","Handle fill-vs-cancel races in strategy logic (on_event handlers)"],"tags":["binance","cancel-order","order-status"],"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-14T05:17:10.506Z"}