{"record":{"id":"e9bc57ac65c1631e","repo":"nautechsystems/nautilus_trader","slug":"cannot-cancel-order-not-connected","errorCode":null,"errorMessage":"Cannot cancel order: not connected","messagePattern":"Cannot cancel order: not connected","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/dydx/src/execution/mod.rs","lineNumber":1899,"sourceCode":"    ///\n    /// Strategies should handle `OrderModifyRejected` by canceling and resubmitting.\n    fn modify_order(&self, cmd: ModifyOrder) -> anyhow::Result<()> {\n        let reason = \"dYdX does not support order modification. Use cancel and resubmit instead.\";\n        log::error!(\"{reason}\");\n\n        self.send_modify_rejected(\n            cmd.strategy_id,\n            cmd.instrument_id,\n            cmd.client_order_id,\n            cmd.venue_order_id,\n            reason,\n        );\n        Ok(())\n    }\n\n    fn cancel_order(&self, cmd: CancelOrder) -> anyhow::Result<()> {\n        if !self.is_connected() {\n            anyhow::bail!(\"Cannot cancel order: not connected\");\n        }\n\n        let client_order_id = cmd.client_order_id;\n        let instrument_id = cmd.instrument_id;\n        let strategy_id = cmd.strategy_id;\n        let venue_order_id = cmd.venue_order_id;\n\n        let (order_time_in_force, order_expire_time) = {\n            let cache = self.core.cache();\n\n            let order = match cache.order(&client_order_id) {\n                Some(order) => order,\n                None => {\n                    log::error!(\"Cannot cancel order {client_order_id}: not found in cache\");\n                    return Ok(()); // Not an error - order may have been filled/canceled already\n                }\n            };\n","sourceCodeStart":1881,"sourceCodeEnd":1917,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/dydx/src/execution/mod.rs#L1881-L1917","documentation":"cancel_order state guard in the dYdX execution client: a cancel command arrived while the client is not connected, so no WebSocket/HTTP session exists to relay it. The command is rejected instead of being silently dropped.","triggerScenarios":"Calling `cancel_order` when `is_connected()` is false — pre-connect, after WebSocket/gRPC drop, or during reconnect.","commonSituations":"Attempting to flatten positions during a network outage; canceling stale orders after the adapter lost its link; shutdown ordering where the client disconnects before pending cancels flush.","solutions":["Reconnect the client before retrying the cancel","Check network connectivity and dYdX status","On the venue side, verify whether the order still exists once reconnected — it may have filled or expired"],"exampleFix":"// before\nclient.cancel_order(cmd)?;\n// after\nif client.is_connected() {\n    client.cancel_order(cmd)?;\n} else {\n    client.connect().await?;\n    client.cancel_order(cmd)?;\n}","handlingStrategy":"validation","validationCode":"if !client.is_connected() { return Err(anyhow!(\"client not connected\")); }","typeGuard":null,"tryCatchPattern":"match client.cancel_order(cmd) {\n    Err(e) if e.to_string().contains(\"not connected\") => { client.connect().await?; client.cancel_order(cmd)?; }\n    r => r?,\n}","preventionTips":["Check connectivity before risk-reducing actions","Reconcile open orders after reconnect — the order may be gone","Avoid tearing down the adapter while cancels are pending"],"tags":["dydx","connectivity","order-cancellation"],"backgroundTag":"connection-refused","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"}