nautechsystems/nautilus_trader · error

client order {client_order_id} is registered to venue order

Error message

client order {client_order_id} is registered to venue order {registered_venue_order_id}, not requested venue order {venue_order_id}

What it means

This error is thrown by resolve_target_order_authority in the Polymarket execution report generator when a client_order_id is supplied and the adapter's order_contexts registry maps that client order id to a different venue order id than the one requested. It is a consistency guard ensuring the caller does not query or generate reports for a venue order that is not the one registered under the given client order id. The adapter refuses to proceed rather than returning a report for the wrong venue order.

Source

Thrown at crates/adapters/polymarket/src/execution/reports.rs:130

        ]
        .into_iter()
        .flatten()
        {
            if let Some(known) = client_order_id {
                anyhow::ensure!(
                    candidate == known,
                    "venue order {venue_order_id} has contradictory client associations {known} and {candidate}",
                );
            } else {
                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

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Verify the client_order_id/venue_order_id pair with self.order_contexts.venue_order_id(&client_order_id) before calling
  2. Fetch the correct venue order id registered for the client order id and use that instead
  3. If the order was replaced, query using the current (new) venue order id
  4. Clear stale id caches in the calling strategy and re-derive ids from the cache

Example fix

// before
let report = exec_client.generate_order_status_report(client_order_id, stale_venue_order_id).await?;
// after
let venue_order_id = order_contexts.venue_order_id(&client_order_id)
    .context("no venue order registered for client order")?;
let report = exec_client.generate_order_status_report(Some(client_order_id), venue_order_id).await?;
Defensive patterns

Strategy: validation

Validate before calling

let registered = order_contexts.venue_order_id(&client_order_id);
anyhow::ensure!(registered == Some(venue_order_id), "id pair mismatch: {:?} vs {}", registered, venue_order_id);

Type guard

fn is_registered_pair(ctxs: &OrderContexts, coid: ClientOrderId, void_id: VenueOrderId) -> bool {
    ctxs.venue_order_id(&coid).as_ref() == Some(&void_id)
}

Try / catch

match client.generate_order_status_report(Some(coid), void_id).await {
    Ok(r) => r,
    Err(e) if e.to_string().contains("is registered to venue order") => {
        // re-derive void_id from registry and retry once
        ...
    }
}

Prevention

When it happens

Trigger: Calling query_order_command, generate_order_status_report_impl, or generate_fill_reports_impl with a (client_order_id, venue_order_id) pair whose mapping in order_contexts does not match — e.g. passing a stale or swapped id after a modify/replace assigned a new venue order id.

Common situations: Reusing an old client_order_id after an order amendment created a new venue order id; copy-paste mixing ids between orders; bot logic caching ids from a previous session while the adapter registry was rebuilt.

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


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