nautechsystems/nautilus_trader · error · anyhow::Error
command venue order ID {command_venue_order_id} does not mat
Error message
command venue order ID {command_venue_order_id} does not match cached order {target_venue_order_id} What it means
Third check in `validate_cancel_order_target`: when BOTH the command and the cached order carry a venue order ID, they must match. Only command actor IDs are ignored (requester identity is not ownership evidence). A mismatch of venue order IDs indicates the command was resolved against the wrong venue order, so the cancel is refused to avoid cancelling the wrong IB order.
Source
Thrown at crates/adapters/interactive_brokers/src/execution/core.rs:2123
) -> anyhow::Result<()> {
anyhow::ensure!(
cmd.client_order_id == target_order.client_order_id(),
"command client order ID {} does not match cached order {}",
cmd.client_order_id,
target_order.client_order_id()
);
anyhow::ensure!(
cmd.instrument_id == target_order.instrument_id(),
"command instrument ID {} does not match cached order {}",
cmd.instrument_id,
target_order.instrument_id()
);
// Command actor IDs identify the requester and are not ownership evidence
if let (Some(command_venue_order_id), Some(target_venue_order_id)) =
(cmd.venue_order_id.as_ref(), target_order.venue_order_id())
{
anyhow::ensure!(
command_venue_order_id == &target_venue_order_id,
"command venue order ID {command_venue_order_id} does not match cached order {target_venue_order_id}"
);
}
Ok(())
}
/// Handles cancel order asynchronously.
///
/// # Errors
///
/// Returns an error if broker order resolution or identity caching fails.
async fn handle_cancel_order_async(
cmd: &CancelOrder,
target_order: &OrderAny,
client: &Arc<Client>,
order_id_map: &Arc<Mutex<AHashMap<ClientOrderId, i32>>>,View on GitHub (pinned to 18893faf8b)
Solutions
- Refresh the venue order ID from reconciliation/latest execution reports before issuing the cancel.
- Cancel by client order ID (omit venue_order_id) when the venue ID may be stale, letting the adapter resolve the current one.
- After a modify/replace, wait for the OrderUpdated event confirming the new venue order ID before sending cancels.
Example fix
// before
let cmd = CancelOrderBuilder::default()
.venue_order_id(old_venue_order_id)
...
// after (cancel by client order id, let adapter resolve venue id)
let cmd = CancelOrderBuilder::default()
.client_order_id(cmd_client_order_id)
... Defensive patterns
Strategy: validation
Validate before calling
// Refresh venue order ID before issuing a cancel
if let (Some(cmd_vo), Some(order_vo)) = (cmd.venue_order_id.as_ref(), order.venue_order_id()) {
anyhow::ensure!(cmd_vo == &order_vo, "stale venue_order_id: cmd={} order={}", cmd_vo, order_vo);
} Type guard
fn venue_order_id_current(cmd: &CancelOrder, order: &OrderAny) -> bool {
match (cmd.venue_order_id.as_ref(), order.venue_order_id()) {
(Some(a), Some(b)) => a == &b,
_ => true, // absent IDs are not compared by the adapter
}
} Try / catch
match cancel_order(&cmd).await {
Err(e) if e.to_string().contains("does not match cached order") => {
// refresh from latest execution report, then retry once
refresh_venue_order_id(&cmd.client_order_id).await?;
cancel_order(&cmd).await?;
}
other => other?,
} Prevention
- Wait for the OrderUpdated event after modify/replace before sending cancels with a venue order ID.
- Prefer cancelling by client order ID when venue IDs may be stale.
- Run reconciliation after every reconnect so cached venue IDs are current.
When it happens
Trigger: `cmd.venue_order_id` is Some but differs from `target_order.venue_order_id()` — e.g. an order was replaced (modify producing a new venue ID) and a stale cancel referencing the old venue ID resolves to the new cached order.
Common situations: Cancel racing an order modify where IB assigned a new venue order ID; reconciliation updated the cached venue ID while an external component still held the old one; reconnection reassigning venue IDs.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- command client order ID {} does not match cached order {}
- command instrument ID {} does not match cached order {}
- {e}
- {FAILED}: {e}
- {FAILED}: {e}
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/de8a34565b39e8d2.
Report an issue: GitHub.