nautechsystems/nautilus_trader · error · anyhow::Error
cancel algo orders failed
Error message
cancel algo orders failed
What it means
The batch cancel of regular (non-advance) algo orders over OKX REST failed. dispatch_algo_cancels partitions algo cancels into regular and advance groups; this context wraps an Err from http_client.cancel_algo_orders for the regular group. Per-item rejections within a successful HTTP response are handled separately (emit_algo_cancel_rejections); this error is the whole-request failure.
Source
Thrown at crates/adapters/okx/src/execution.rs:1227
drop(cache);
if !regular_requests.is_empty() {
let client = self.http_client.clone();
let emitter = self.emitter.clone();
let clock = self.clock;
self.spawn_task("cancel_algo_orders", async move {
match client.cancel_algo_orders(regular_requests).await {
Ok(responses) => {
emit_algo_cancel_rejections(&responses, ®ular_contexts, &emitter, clock);
}
Err(e) => {
log_algo_batch_cancel_failure(
classify_okx_http_failure(&e),
®ular_contexts,
);
return Err(anyhow::Error::new(e).context("cancel algo orders failed"));
}
}
Ok(())
});
}
if !advance_requests.is_empty() {
let client = self.http_client.clone();
let emitter = self.emitter.clone();
let clock = self.clock;
self.spawn_task("cancel_advance_algo_orders", async move {
match client.cancel_advance_algo_orders(advance_requests).await {
Ok(responses) => {
emit_algo_cancel_rejections(&responses, &advance_contexts, &emitter, clock);
}
Err(e) => {
log_algo_batch_cancel_failure(View on GitHub (pinned to 18893faf8b)
Solutions
- Inspect the chained cause/log classification (classify_okx_http_failure) for the failure class.
- If rate-limited, back off and re-dispatch the remaining algo cancels; the contexts list in the log shows which orders still need canceling.
- Retry individually per algo order to isolate any single bad request.
- Verify credentials and network connectivity to OKX REST.
Defensive patterns
Strategy: retry
Validate before calling
// Filter to algo orders that are actually open before batch cancel
let items: Vec<_> = algo_cids.iter()
.filter(|cid| cache.order(cid).map(|o| !o.is_closed()).unwrap_or(false))
.collect(); Try / catch
// Batch cancel failure: re-dispatch the remaining contexts from the log
if let Err(e) = trader.batch_cancel_orders(batch) {
log::warn!("algo batch cancel failed: {e:?}");
retry_cancels_with_backoff(remaining_contexts);
} Prevention
- Chunk large algo-cancel batches to stay within OKX rate limits.
- Separate regular vs advance algo orders as the adapter does, to hit the right endpoint.
- Retry only the contexts reported in log_algo_batch_cancel_failure.
- Monitor classify_okx_http_failure output for auth vs rate-limit classes.
When it happens
Trigger: cancel_all_orders or batch_cancel_orders containing regular algo orders; http_client.cancel_algo_orders returned Err: transport failure, non-2xx response, auth error, or rate limiting on the algo-cancel endpoint.
Common situations: Bulk cancel of many trigger/conditional orders hitting OKX REST rate limits; API key permission issues; network outage mid-batch; mixed regular+advance orders where only the regular group failed.
Related errors
- cancel algo order failed
- cancel advance algo orders failed
- Batch cancel limit is {endpoint_limit} orders for {product_t
- Conditional order types must use OKXAlgoOrderType
- Batch cancel limit is {call_limit} orders for {}
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/4b4456cc71a5c210.
Report an issue: GitHub.