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

  1. Check the returned msg for the exact exchange reason (e.g. 'Unknown order sent') and treat unknown-order as already-closed
  2. Verify the algo order is still active via an algo order status query before canceling
  3. Ensure the symbol and algo ID match the original algo order
  4. 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

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


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(&params).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)