{"record":{"id":"f6edb2d972736e13","repo":"nautechsystems/nautilus_trader","slug":"batch-add-requires-at-least-one-order","errorCode":null,"errorMessage":"batch_add requires at least one order","messagePattern":"batch_add requires at least one order","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/kraken/src/execution/spot.rs","lineNumber":935,"sourceCode":"                            ts_event,\n                            due_post_only,\n                        );\n                    }\n                }\n            }\n            Ok(())\n        });\n    }\n\n    fn batch_add_via_ws(&self, orders: &[OrderAny], leverage: Option<u16>) -> anyhow::Result<()> {\n        let token = self\n            .ws\n            .auth_token_blocking()\n            .ok_or_else(|| anyhow::anyhow!(\"missing WS auth token\"))?;\n\n        let first = orders\n            .first()\n            .ok_or_else(|| anyhow::anyhow!(\"batch_add requires at least one order\"))?;\n        let symbol = first.instrument_id().symbol.inner().to_string();\n\n        let mut batch_orders = Vec::with_capacity(orders.len());\n        let mut client_order_ids = Vec::with_capacity(orders.len());\n        for order in orders {\n            batch_orders.push(build_batch_order(order, leverage)?);\n            client_order_ids.push(order.client_order_id());\n        }\n        let venue_order_ids = vec![None; orders.len()];\n\n        let params = KrakenWsBatchAddParams {\n            symbol,\n            orders: batch_orders,\n            token,\n        };\n        let identity = PendingRequest {\n            operation: PendingOperation::BatchAdd,\n            client_order_ids,","sourceCodeStart":917,"sourceCodeEnd":953,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/kraken/src/execution/spot.rs#L917-L953","documentation":"Raised in `batch_add_via_ws` when the caller passes an empty order list: `orders.first()` is `None`, so the client rejects the batch with \"batch_add requires at least one order\". Kraken's batch add WS operation is only meaningful with at least one order, and the symbol is derived from the first order.","triggerScenarios":"Calling `submit_order_list` with an empty slice/empty `OrderList` — e.g. a strategy that builds batches conditionally and submits an empty batch when no orders qualify.","commonSituations":"Batching logic with off-by-one or filtering that removes all orders; passing an uninitialized order collection during strategy warm-up; a data-driven flow where a signal produces zero orders.","solutions":["Guard the caller: skip `submit_order_list` entirely when the order collection is empty.","Fix batch-building logic so it either collects at least one order or does not submit.","Filter out invalid/duplicate orders before batching and check the resulting count.","If empty batches are expected, fall back to per-order submission only when non-empty."],"exampleFix":"// before\nexec_client.submit_order_list(batch)?; // batch may be empty\n\n// after\nif !batch.is_empty() {\n    exec_client.submit_order_list(batch)?;\n}","handlingStrategy":"validation","validationCode":"// Rust\nif orders.is_empty() {\n    log::debug!(\"no orders in batch; skipping submit_order_list\");\n    return Ok(());\n}","typeGuard":null,"tryCatchPattern":"if !batch.orders.is_empty() {\n    exec_client.submit_order_list(batch)?;\n} else {\n    log::debug!(\"empty batch suppressed\");\n}","preventionTips":["Never call submit_order_list with an empty collection; early-return instead.","Assert batch non-emptiness in strategy tests that exercise batching paths.","Fix batch builders that filter out all orders yet still submit.","Treat zero-order signals as legitimate no-ops in event handlers."],"tags":["kraken","batch-orders","validation","empty-input"],"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"}