nautechsystems/nautilus_trader · error
cached client order {} is associated with venue order {cache
Error message
cached client order {} is associated with venue order {cached_venue_order_id}, not requested venue order {venue_order_id} What it means
resolve_target_order_authority looks up the order cached in the Nautilus core cache for the given client_order_id and verifies that its associated venue_order_id equals the requested venue order id. This ensure! fires when the cached order points at a different venue order. It protects against generating reports that mix state from two distinct venue orders.
Source
Thrown at crates/adapters/polymarket/src/execution/reports.rs:140
client_order_id = Some(candidate);
}
}
if let Some(client_order_id) = client_order_id
&& let Some(registered_venue_order_id) =
self.order_contexts.venue_order_id(&client_order_id)
{
anyhow::ensure!(
registered_venue_order_id == venue_order_id,
"client order {client_order_id} is registered to venue order {registered_venue_order_id}, not requested venue order {venue_order_id}",
);
}
let cached_order = client_order_id.and_then(|value| self.core.cache().order_owned(&value));
if let Some(cached_order) = cached_order.as_ref() {
let cached_venue_order_id = cached_order.venue_order_id();
if let Some(cached_venue_order_id) = cached_venue_order_id {
anyhow::ensure!(
cached_venue_order_id == venue_order_id,
"cached client order {} is associated with venue order {cached_venue_order_id}, not requested venue order {venue_order_id}",
cached_order.client_order_id(),
);
} else {
anyhow::ensure!(
cached_client_order_id == client_order_id
|| self
.order_contexts
.venue_order_id(&cached_order.client_order_id())
== Some(venue_order_id),
"cached client order {} has no association with requested venue order {venue_order_id}",
cached_order.client_order_id(),
);
}
if let Some(requested_instrument_id) = requested_instrument_id {
anyhow::ensure!(View on GitHub (pinned to 18893faf8b)
Solutions
- Pass the venue order id recorded on the cached order instead of the stale one
- Confirm the order was not replaced; if it was, use the replacement's venue order id
- Check strategy code for reusing client order ids across orders
- Clear and re-sync the cache with current venue state
Example fix
// before
let report = client.generate_order_status_report(Some(coid), old_void_id).await?;
// after
let cached = core.cache().order_owned(&coid).context("order not cached")?;
let void_id = cached.venue_order_id().context("cached order has no venue id")?;
let report = client.generate_order_status_report(Some(coid), void_id).await?; Defensive patterns
Strategy: validation
Validate before calling
let cached = core.cache().order_owned(&client_order_id).context("order not in cache")?;
let cached_void = cached.venue_order_id().context("no venue id yet")?;
anyhow::ensure!(cached_void == venue_order_id, "stale venue id"); Type guard
fn cache_matches(core: &Cache, coid: &ClientOrderId, void_id: &VenueOrderId) -> bool {
core.order_owned(coid).and_then(|o| o.venue_order_id().map(|v| v == *void_id)).unwrap_or(false)
} Try / catch
match exec.generate_order_status_report_impl(...).await {
Err(e) if e.to_string().contains("cached client order") => warn!("cache/registry diverged for {coid}"),
other => other?,
} Prevention
- Do not cache venue order ids locally in strategies; read them from the Nautilus cache
- After any modify/replace, confirm the cache reflects the new venue order id before querying
- Avoid reusing client_order_id values across separate orders
When it happens
Trigger: query_order_command, generate_order_status_report_impl, or generate_fill_reports_impl called with a venue_order_id that disagrees with cache.order_owned(client_order_id).venue_order_id().
Common situations: Order was modified/replaced so the cache now holds the new venue order id, but the caller still passes the old one; multiple live orders sharing a client_order_id due to a strategy bug; a restart repopulated the cache differently.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- cached client order {} has no association with requested ven
- client order {client_order_id} is registered to venue order
- Cannot cancel order: {e}
- DataActor {} must be registered before calling `cache()` - t
- Order {client_order_id} not found
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/d3f474cbd06aa1a8.
Report an issue: GitHub.