nautechsystems/nautilus_trader · error · anyhow::Error
Cancel algo order failed: code=
Error message
Cancel algo order failed: code={}, msg={} What it means
The Binance Futures algo-order cancel endpoint returns a response with a code and msg; success is code == 200. Any other code (exchange rejects the cancel) causes this error with the exchange's code and message.
Solutions
- Check the returned msg for the exact exchange reason (e.g. 'Unknown order sent') and treat unknown-order as already-closed
- Verify the algo order is still active via an algo order status query before canceling
- Ensure the symbol and algo ID match the original algo order
- Refresh local algo-order state via reconciliation if IDs are stale
Example fix
// before
client.cancel_algo_order(symbol, algo_id)?; // hard fail on unknown order
// after
match client.cancel_algo_order(symbol, algo_id) {
Ok(_) => {},
Err(e) if e.to_string().contains("Unknown order") => log::info!("algo order already gone"),
Err(e) => return Err(e),
} Defensive patterns
Strategy: try-catch
Validate before calling
let active = client.query_algo_order_status(symbol, algo_id)?;
if !active { return Ok(()); } // nothing to cancel Try / catch
match client.cancel_algo_order(symbol, algo_id) { Err(e) if e.to_string().contains("Unknown order") => Ok(()), Err(e) => Err(e), _ => Ok(()) } Prevention
- Sync algo order state via periodic reconciliation
- Treat unknown-order cancel errors as idempotent success
- Confirm symbol and algo IDs before cancelling
When it happens
Trigger: Calling cancel_algo_order for a conditional/algo order that does not exist (already filled or canceled), belongs to a different symbol, or when the account lacks permission / the algo ID is wrong.
Common situations: Cancelling a stop that already triggered and executed; stale algo order IDs kept in local state; using the wrong algo ID type (strategy vs order ID).
Related errors
- Cancel all algo orders failed
- Cancel all orders failed
- WS modify order failed
- Binance Futures custom data requires BINANCE venue…
- Binance Futures does not support
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/9ccea5ad0104e119.
Report an issue: GitHub.
Appendix: source
Thrown at crates/adapters/binance/src/futures/http/client.rs:2514
///
/// # Errors
///
/// Returns an error if the request fails.
pub async fn cancel_algo_order(&self, client_order_id: ClientOrderId) -> anyhow::Result<()> {
let params = BinanceAlgoOrderQueryParams {
algo_id: None,
client_algo_id: Some(encode_broker_id(
&client_order_id,
BINANCE_NAUTILUS_FUTURES_BROKER_ID,
)),
recv_window: None,
};
let response = self.inner.cancel_algo_order(¶ms).await?;
if response.code.parse::<i32>().unwrap_or(0) == 200 {
Ok(())
} else {
anyhow::bail!(
"Cancel algo order failed: code={}, msg={}",
response.code,
response.msg
)
}
}
/// Cancels all open orders for a symbol.
///
/// # Errors
///
/// Returns an error if the request fails.
pub async fn cancel_all_orders(
&self,
instrument_id: InstrumentId,
) -> anyhow::Result<Vec<VenueOrderId>> {
let symbol = format_binance_symbol(&instrument_id);
View on GitHub (pinned to 18893faf8b)