{"record":{"id":"7a5a8a363d051808","repo":"nautechsystems/nautilus_trader","slug":"cancel-order-rejected-reason","errorCode":null,"errorMessage":"cancel order rejected: {reason}","messagePattern":"cancel order rejected: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/bybit/src/execution.rs","lineNumber":1978,"sourceCode":"                        instrument_id,\n                        Some(client_order_id),\n                        venue_order_id,\n                    )\n                    .await;\n\n                if let Err(e) = result {\n                    match classify_cancel_http_failure(&e) {\n                        CommandFailure::VenueRejected(reason) => {\n                            let ts_event = clock.get_time_ns();\n                            emitter.emit_order_cancel_rejected_event(\n                                strategy_id,\n                                instrument_id,\n                                client_order_id,\n                                venue_order_id,\n                                &format!(\"cancel-order-error: {reason}\"),\n                                ts_event,\n                            );\n                            anyhow::bail!(\"cancel order rejected: {reason}\");\n                        }\n                        CommandFailure::NotSent(reason) => {\n                            log::warn!(\n                                \"HTTP cancel command failed local validation for {client_order_id}: {reason}\"\n                            );\n                        }\n                        CommandFailure::Ambiguous(reason) => {\n                            log::warn!(\n                                \"Ambiguous HTTP cancel failure for {client_order_id}, awaiting reconciliation: {reason}\"\n                            );\n                        }\n                    }\n                }\n\n                Ok(())\n            });\n\n            return Ok(());","sourceCodeStart":1960,"sourceCodeEnd":1996,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/bybit/src/execution.rs#L1960-L1996","documentation":"Raised when a cancel-order request is rejected by Bybit (or fails with a confirmed reason) during cancel_order. The adapter emits an OrderCancelRejected event with 'cancel-order-error: {reason}' and then bails with the venue reason.","triggerScenarios":"Calling cancel_order when Bybit rejects the cancel — e.g. the order already filled or cancelled, unknown order ID, or the order belongs to another API key.","commonSituations":"Attempting to cancel an order that just filled; duplicate cancel requests; stale order state after disconnects; cancels submitted for orders from a different session/key.","solutions":["Check current order status in the cache before cancelling; treat already-filled/cancelled as benign","Handle rejection reason 'order not exists or too late to cancel' as informational rather than fatal","Deduplicate cancel requests in strategy logic","Reconcile order state with the venue after reconnects"],"exampleFix":"// before\nclient.cancel_order(&order)?; // bails if order already filled\n// after\nif let Some(o) = cache.order(&order.client_order_id()) && o.is_open() {\n    client.cancel_order(&order)?;\n} // else: nothing to cancel","handlingStrategy":"try-catch","validationCode":"if let Some(o) = cache.order(client_order_id) {\n    if !o.is_open() {\n        // already filled/cancelled — nothing to cancel\n        return Ok(());\n    }\n}","typeGuard":null,"tryCatchPattern":"match exec_client.cancel_order(&order) {\n    Err(e) if e.to_string().starts_with(\"cancel order rejected:\") => {\n        let reason = e.to_string();\n        if reason.contains(\"not exists\") || reason.contains(\"too late\") {\n            tracing::info!(\"order already closed on venue; treating cancel as no-op\");\n        } else {\n            return Err(e);\n        }\n    }\n    r => r?,\n}","preventionTips":["Check cached order status before cancelling","Deduplicate cancel requests; reconcile state after reconnects","Treat 'already filled/cancelled' rejection reasons as benign","Ensure cancels target orders owned by the same API key/session"],"tags":["bybit","order-rejected","cancel-order","venue-rejection"],"backgroundTag":"http-error-response","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"}