nautechsystems/nautilus_trader · error

resolves to instrument , not requested instrument

Error message

{evidence} resolves to instrument {}, not requested instrument {requested_instrument_id}

What it means

resolve_target_instrument maps reconciliation evidence (e.g. a token id or market slug) to a domain instrument. When the caller supplies a requested_instrument_id, the resolver verifies the resolved instrument matches; a mismatch means the evidence points at a different market than the one requested, and this anyhow error names both instruments.

Solutions

  1. Reload the instrument catalog so the evidence resolves to the instrument matching the requested ID.
  2. Verify the token id / evidence actually belongs to the requested market and outcome slot.
  3. Re-register or recreate the instrument with the correct provider instrument id, then retry reconciliation.
  4. Check for neg-risk vs standard market id divergence and normalize the requested id accordingly.

Example fix

// before
let inst = resolve_target_instrument(Some(&cached_token_id), Some(&requested_id))?;
// cached_token_id belongs to old market
// after
let catalog = catalog.reload()?; // refresh instruments from provider
let inst = resolve_target_instrument(Some(&fresh_token_id), Some(&requested_id))?;
Defensive patterns

Strategy: validation

Validate before calling

fn matches_request(resolved: InstrumentId, requested: InstrumentId) -> bool {
    resolved == requested
}
// pre-check evidence ownership before resolving:
anyhow::ensure!(evidence_token_belongs_to_market(&token_id, &market_slug), "token/market mismatch");

Try / catch

match resolve_target_instrument(Some(&evidence), Some(&requested_id)) {
    Err(e) if e.to_string().contains("resolves to instrument") => {
        instrument_catalog.reload()?; // stale cache: refresh and retry once
        resolve_target_instrument(Some(&evidence), Some(&requested_id))?"
    }
    other => other?,
}

Prevention

When it happens

Trigger: build_order_report_from_order or classify_target_trade calls resolve_target_instrument with a requested instrument id, but the evidence (token_id/market data) resolves to another instrument id — typically because the cached token belongs to a different Polymarket market or the neg_risk/conditional-id variant.

Common situations: Stale local instrument cache after a market was re-created on Polymarket; using a token id from a different outcome/outcome-slot; instrument ID string built with a different venue/symbol format than the registered instrument; mixing neg-risk and standard market IDs.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at crates/adapters/polymarket/src/execution/reconciliation.rs:459

fn resolve_target_instrument(
    instruments: &AtomicMap<Ustr, InstrumentAny>,
    token_id: Ustr,
    requested_instrument_id: Option<InstrumentId>,
    evidence: &str,
) -> anyhow::Result<InstrumentAny> {
    let instrument = instruments.get_cloned(&token_id).with_context(|| {
        requested_instrument_id.map_or_else(
            || format!("{evidence} token {token_id} has no loaded Polymarket instrument"),
            |requested_instrument_id| {
                format!(
                    "{evidence} token {token_id} has no loaded Polymarket instrument for requested instrument {requested_instrument_id}"
                )
            },
        )
    })?;

    if let Some(requested_instrument_id) = requested_instrument_id {
        anyhow::ensure!(
            instrument.id() == requested_instrument_id,
            "{evidence} resolves to instrument {}, not requested instrument {requested_instrument_id}",
            instrument.id(),
        );
    }
    Ok(instrument)
}

pub(super) fn validate_client_bound_order_quantity(
    provider_order: &PolymarketOpenOrder,
    expected_quantity: Quantity,
) -> anyhow::Result<()> {
    anyhow::ensure!(
        expected_quantity.as_decimal() == provider_order.original_size,
        "provider order quantity {} does not match cached order quantity {}",
        provider_order.original_size,
        expected_quantity,
    );

View on GitHub (pinned to 18893faf8b)