nautechsystems/nautilus_trader · error · anyhow::Error

Cannot cancel orders: not connected

Error message

Cannot cancel orders: not connected

What it means

`cancel_all_orders` checks connectivity before gathering open orders and broadcasting partitioned cancels. If the client is disconnected it bails immediately because mass-cancellation requires a live chain link.

Source

Thrown at crates/adapters/dydx/src/execution/mod.rs:2047

                        ts_event,
                    );
                }
                Err(e) => {
                    log::warn!(
                        "Ambiguous dYdX cancel failure for {client_order_id}, awaiting reconciliation: {e:?}"
                    );
                }
            }

            Ok(())
        });

        Ok(())
    }

    fn cancel_all_orders(&self, cmd: CancelAllOrders) -> anyhow::Result<()> {
        if !self.is_connected() {
            anyhow::bail!("Cannot cancel orders: not connected");
        }

        let instrument_id = cmd.instrument_id;
        let order_side_filter = cmd.order_side;

        let order_data: Vec<CancelAllOrderData> = {
            let cache = self.core.cache();
            let side_filter = order_side_filter;
            cache
                .orders_open(None, Some(&instrument_id), None, None, side_filter)
                .into_iter()
                .map(|order| {
                    (
                        order.strategy_id(),
                        order.client_order_id(),
                        order.venue_order_id(),
                        order.time_in_force(),
                        order.expire_time(),

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Reconnect the client, then retry cancel_all_orders
  2. Check network/dYdX endpoint health
  3. Verify order state via reconciliation once reconnected — orders may have expired already

Example fix

// before
client.cancel_all_orders(cmd)?;
// after
if !client.is_connected() {
    client.connect().await?;
}
client.cancel_all_orders(cmd)?;
Defensive patterns

Strategy: validation

Validate before calling

if !client.is_connected() { return Err(anyhow!("client not connected")); }

Try / catch

if let Err(e) = client.cancel_all_orders(cmd) {
    if e.to_string().contains("not connected") { /* defer until reconnected */ }
}

Prevention

When it happens

Trigger: Calling `cancel_all_orders` when `is_connected()` is false — before connect completes, after disconnect, or during reconnect.

Common situations: Emergency flatten during a network outage; market-close routines racing an already-dropped connection; adapter shutdown ordering.

Understand the failure class

Background: ECONNREFUSED and "connection refused" / "could not connect to server" errors: what they mean and how to fix them — this error's family across 44 libraries.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/76c6084f8162bdf6. Report an issue: GitHub.