{"record":{"id":"5f6ad593802381b3","repo":"nautechsystems/nautilus_trader","slug":"evidence-resolves-to-instrument-not-requeste","errorCode":null,"errorMessage":"{evidence} resolves to instrument {}, not requested instrument {requested_instrument_id}","messagePattern":"(.+?) resolves to instrument (.+?), not requested instrument (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/polymarket/src/execution/reconciliation.rs","lineNumber":459,"sourceCode":"fn resolve_target_instrument(\n    instruments: &AtomicMap<Ustr, InstrumentAny>,\n    token_id: Ustr,\n    requested_instrument_id: Option<InstrumentId>,\n    evidence: &str,\n) -> anyhow::Result<InstrumentAny> {\n    let instrument = instruments.get_cloned(&token_id).with_context(|| {\n        requested_instrument_id.map_or_else(\n            || format!(\"{evidence} token {token_id} has no loaded Polymarket instrument\"),\n            |requested_instrument_id| {\n                format!(\n                    \"{evidence} token {token_id} has no loaded Polymarket instrument for requested instrument {requested_instrument_id}\"\n                )\n            },\n        )\n    })?;\n\n    if let Some(requested_instrument_id) = requested_instrument_id {\n        anyhow::ensure!(\n            instrument.id() == requested_instrument_id,\n            \"{evidence} resolves to instrument {}, not requested instrument {requested_instrument_id}\",\n            instrument.id(),\n        );\n    }\n    Ok(instrument)\n}\n\npub(super) fn validate_client_bound_order_quantity(\n    provider_order: &PolymarketOpenOrder,\n    expected_quantity: Quantity,\n) -> anyhow::Result<()> {\n    anyhow::ensure!(\n        expected_quantity.as_decimal() == provider_order.original_size,\n        \"provider order quantity {} does not match cached order quantity {}\",\n        provider_order.original_size,\n        expected_quantity,\n    );","sourceCodeStart":441,"sourceCodeEnd":477,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/polymarket/src/execution/reconciliation.rs#L441-L477","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Reload the instrument catalog so the evidence resolves to the instrument matching the requested ID.","Verify the token id / evidence actually belongs to the requested market and outcome slot.","Re-register or recreate the instrument with the correct provider instrument id, then retry reconciliation.","Check for neg-risk vs standard market id divergence and normalize the requested id accordingly."],"exampleFix":"// before\nlet inst = resolve_target_instrument(Some(&cached_token_id), Some(&requested_id))?;\n// cached_token_id belongs to old market\n// after\nlet catalog = catalog.reload()?; // refresh instruments from provider\nlet inst = resolve_target_instrument(Some(&fresh_token_id), Some(&requested_id))?;","handlingStrategy":"validation","validationCode":"fn matches_request(resolved: InstrumentId, requested: InstrumentId) -> bool {\n    resolved == requested\n}\n// pre-check evidence ownership before resolving:\nanyhow::ensure!(evidence_token_belongs_to_market(&token_id, &market_slug), \"token/market mismatch\");","typeGuard":null,"tryCatchPattern":"match resolve_target_instrument(Some(&evidence), Some(&requested_id)) {\n    Err(e) if e.to_string().contains(\"resolves to instrument\") => {\n        instrument_catalog.reload()?; // stale cache: refresh and retry once\n        resolve_target_instrument(Some(&evidence), Some(&requested_id))?\"\n    }\n    other => other?,\n}","preventionTips":["Keep the instrument catalog refreshed from the provider (markets get re-created)","Verify token-id -> market/outcome mapping before reconciliation runs","Normalize instrument id format (neg-risk vs standard) consistently across cache and requests"],"tags":["polymarket","reconciliation","instrument-resolution","id-mismatch"],"backgroundTag":"record-not-found","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}