{"record":{"id":"5a375159f73eccef","repo":"nautechsystems/nautilus_trader","slug":"no-order-returned-in-cancel-response","errorCode":null,"errorMessage":"No order returned in cancel response","messagePattern":"No order returned in cancel response","errorType":"http","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/bitmex/src/http/client.rs","lineNumber":1821,"sourceCode":"    ) -> anyhow::Result<OrderStatusReport> {\n        let mut params = super::query::DeleteOrderParamsBuilder::default();\n        params.text(NAUTILUS_TRADER);\n\n        if let Some(venue_order_id) = venue_order_id {\n            params.order_id(vec![venue_order_id.as_str().to_string()]);\n        } else if let Some(client_order_id) = client_order_id {\n            params.cl_ord_id(vec![client_order_id.as_str().to_string()]);\n        } else {\n            anyhow::bail!(\"Either client_order_id or venue_order_id must be provided\");\n        }\n\n        let params = params.build().map_err(|e| anyhow::anyhow!(e))?;\n\n        let orders: Vec<BitmexOrder> = self.inner.cancel_orders_response(params).await?;\n        let order = orders\n            .into_iter()\n            .next()\n            .ok_or_else(|| anyhow::anyhow!(\"No order returned in cancel response\"))?;\n\n        let instrument = self.instrument_from_cache(instrument_id.symbol.inner())?;\n        let ts_init = self.generate_ts_init();\n\n        parse_order_status_report(&order, &instrument, &self.order_type_cache, ts_init)\n    }\n\n    /// Cancel multiple orders.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if:\n    /// - Credentials are missing.\n    /// - The request fails.\n    /// - The order doesn't exist.\n    /// - The API returns an error.\n    pub async fn cancel_orders(\n        &self,","sourceCodeStart":1803,"sourceCodeEnd":1839,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/bitmex/src/http/client.rs#L1803-L1839","documentation":"cancel_order requested a cancel via BitMEX DELETE /api/v1/order but the API returned an empty array of orders, so there is nothing to parse into an OrderStatusReport. The adapter treats an empty cancel response as an error because a successful cancel echoes back the cancelled order.","triggerScenarios":"Calling cancel_order with a client_order_id or venue_order_id that does not exist on BitMEX, that was already cancelled/filled, or that belongs to a different account/symbol; the order being cancelled concurrently by another process between check and cancel.","commonSituations":"Re-submitting a cancel after a timeout (idempotency retry on an already-cancelled order); stale VenueOrderId after a disconnect; cancelling during settlement or when the order was rejected on the venue; testnet vs mainnet credential mismatch so the order is not visible to the API key.","solutions":["Check the order exists and is open (e.g. via query_order/request_order_status_report) before cancelling, or treat empty cancel responses as already-cancelled.","Verify the client_order_id/venue_order_id corresponds to a live order on the same environment (testnet vs mainnet) and API key.","If a cancel retry produced this, treat it as success-if-cancelled: look the order up and confirm Canceled status instead of failing.","Log the exact order id used and confirm with a direct GET /api/v1/order filter query."],"exampleFix":"// before\nlet order = orders.into_iter().next().ok_or_else(|| anyhow::anyhow!(\"No order returned in cancel response\"))?;\n// after\nlet order = match orders.into_iter().next() {\n    Some(o) => o,\n    None => anyhow::bail!(\n        \"Cancel returned no order for client_order_id={client_order_id:?} venue_order_id={venue_order_id:?} (already cancelled/filled or not found)\"\n    ),\n};","handlingStrategy":"try-catch","validationCode":"let open = client.query_order(instrument_id, Some(cl_id), None).await?;\nif open.is_none() {\n    // order already gone; skip cancel\n}","typeGuard":"fn first_order(orders: Vec<BitmexOrder>) -> Result<BitmexOrder, String> {\n    orders.into_iter().next().ok_or_else(|| \"empty cancel response\".to_string())\n}","tryCatchPattern":"match client.cancel_order(instrument_id, Some(cl_id), None).await {\n    Ok(report) => handle(report),\n    Err(e) if e.to_string().contains(\"No order returned\") => {\n        // treat as already-cancelled: confirm via query_order before alerting\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Check order state via query_order before cancelling to skip already-closed orders.","Make cancel retries idempotent: an empty cancel response usually means the order is already gone.","Verify API key environment (testnet vs mainnet) and account match the orders being cancelled."],"tags":["empty-response","order-not-found","bitmex","http-client"],"backgroundTag":"empty-result-set","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"}