{"record":{"id":"ecdebb1fa125b4b1","repo":"nautechsystems/nautilus_trader","slug":"client-order-ids-cannot-be-empty","errorCode":null,"errorMessage":"client_order_ids cannot be empty","messagePattern":"client_order_ids cannot be empty","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/bitmex/src/http/client.rs","lineNumber":1861,"sourceCode":"    ) -> anyhow::Result<Vec<OrderStatusReport>> {\n        let mut params = super::query::DeleteOrderParamsBuilder::default();\n        params.text(NAUTILUS_TRADER);\n\n        // BitMEX API requires either client order IDs or venue order IDs, not both\n        // Prioritize venue order IDs if both are provided\n        if let Some(venue_order_ids) = venue_order_ids {\n            if venue_order_ids.is_empty() {\n                anyhow::bail!(\"venue_order_ids cannot be empty\");\n            }\n            params.order_id(\n                venue_order_ids\n                    .iter()\n                    .map(|id| id.to_string())\n                    .collect::<Vec<_>>(),\n            );\n        } else if let Some(client_order_ids) = client_order_ids {\n            if client_order_ids.is_empty() {\n                anyhow::bail!(\"client_order_ids cannot be empty\");\n            }\n            params.cl_ord_id(\n                client_order_ids\n                    .iter()\n                    .map(|id| id.to_string())\n                    .collect::<Vec<_>>(),\n            );\n        } else {\n            anyhow::bail!(\"Either client_order_ids or venue_order_ids 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\n        let ts_init = self.generate_ts_init();\n        let instrument = self.instrument_from_cache(instrument_id.symbol.inner())?;\n","sourceCodeStart":1843,"sourceCodeEnd":1879,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/bitmex/src/http/client.rs#L1843-L1879","documentation":"Raised by cancel_orders when the caller supplies Some(client_order_ids) with an empty Vec (and no venue_order_ids). BitMEX requires at least one clOrdID to cancel; an empty list would be rejected or cancel nothing. The adapter fails fast locally instead of sending a doomed request.","triggerScenarios":"Calling cancel_orders with client_order_ids=Some(vec![]) and venue_order_ids=None. Common when client order IDs are collected from a filtered order set that yields no matches.","commonSituations":"Cancelling orders by client order ID after a filter (e.g. by instrument or strategy) that removed all entries; migrating code that assumed empty means 'cancel all'.","solutions":["Only pass Some(client_order_ids) when the Vec is non-empty","Validate at the call site and skip the request when the list is empty","Switch to venue_order_ids or use the cancel_all_orders endpoint if the intent was to cancel everything"],"exampleFix":"// before\nclient.cancel_orders(Some(cl_ord_ids), None).await?;\n// after\nif cl_ord_ids.is_empty() { return Ok(()); }\nclient.cancel_orders(Some(cl_ord_ids), None).await?;","handlingStrategy":"validation","validationCode":"if let Some(ids) = &client_order_ids {\n    if ids.is_empty() { return Err(anyhow!(\"client_order_ids must not be empty\")); }\n}\nclient.cancel_orders(client_order_ids, venue_order_ids).await?;","typeGuard":"fn non_empty(ids: &Option<Vec<ClientOrderId>>) -> bool {\n    ids.as_ref().is_some_and(|v| !v.is_empty())\n}","tryCatchPattern":"match client.cancel_orders(client_order_ids, venue_order_ids).await {\n    Ok(reports) => { /* handle */ }\n    Err(e) if e.to_string().contains(\"cannot be empty\") => { /* fix inputs and retry */ }\n    Err(e) => return Err(e),\n}","preventionTips":["Skip the cancel call entirely when the collected ID list is empty","Remember the endpoint is not 'cancel all' — an empty list means nothing","Unit-test ID collection logic to ensure filters do not silently drop all IDs"],"tags":["rust","bitmex","validation","empty-argument"],"backgroundTag":"empty-required-field","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"}