{"record":{"id":"c500366ed3ed3dbe","repo":"nautechsystems/nautilus_trader","slug":"cached-order-instrument-does-not-match-requeste","errorCode":null,"errorMessage":"cached order instrument {} does not match requested instrument {requested_instrument_id}","messagePattern":"cached order instrument (.+?) does not match requested instrument (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/polymarket/src/execution/reports.rs","lineNumber":158,"sourceCode":"                anyhow::ensure!(\n                    cached_venue_order_id == venue_order_id,\n                    \"cached client order {} is associated with venue order {cached_venue_order_id}, not requested venue order {venue_order_id}\",\n                    cached_order.client_order_id(),\n                );\n            } else {\n                anyhow::ensure!(\n                    cached_client_order_id == client_order_id\n                        || self\n                            .order_contexts\n                            .venue_order_id(&cached_order.client_order_id())\n                            == Some(venue_order_id),\n                    \"cached client order {} has no association with requested venue order {venue_order_id}\",\n                    cached_order.client_order_id(),\n                );\n            }\n\n            if let Some(requested_instrument_id) = requested_instrument_id {\n                anyhow::ensure!(\n                    cached_order.instrument_id() == requested_instrument_id,\n                    \"cached order instrument {} does not match requested instrument {requested_instrument_id}\",\n                    cached_order.instrument_id(),\n                );\n            }\n        }\n\n        if let Some(context) = context {\n            if let Some(requested_instrument_id) = requested_instrument_id {\n                anyhow::ensure!(\n                    context.identity.instrument_id == requested_instrument_id,\n                    \"registered order instrument {} does not match requested instrument {requested_instrument_id}\",\n                    context.identity.instrument_id,\n                );\n            }\n\n            if let Some(cached_order) = cached_order.as_ref() {\n                anyhow::ensure!(","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/polymarket/src/execution/reports.rs#L140-L176","documentation":"If an instrument_id was requested, resolve_target_order_authority checks the cached order's instrument matches it. This ensure! fires when the cached order belongs to a different market/instrument than the one requested. It prevents generating an order status or fill report against the wrong market.","triggerScenarios":"Calling query_order_command, generate_order_status_report_impl, or generate_fill_reports_impl with requested_instrument_id set to a market different from the cached order's instrument_id.","commonSituations":"Multi-market strategies passing the wrong instrument id alongside an order id; instrument id formatted differently (case/precision) than at order submission; copy-paste across instruments.","solutions":["Omit requested_instrument_id or pass cached_order.instrument_id()","Correct the instrument id in the calling code to the order's actual market","Normalize instrument id construction so it matches submission-time formatting"],"exampleFix":"// before\nlet report = client.generate_order_status_report(Some(coid), void_id, Some(wrong_instrument)).await?;\n// after\nlet instrument_id = core.cache().order_owned(&coid).map(|o| *o.instrument_id());\nlet report = client.generate_order_status_report(Some(coid), void_id, instrument_id).await?;","handlingStrategy":"validation","validationCode":"let expected = core.cache().order_owned(&coid).map(|o| *o.instrument_id());\nanyhow::ensure!(requested == expected, \"instrument mismatch for order\");","typeGuard":"fn instrument_matches(core: &Cache, coid: &ClientOrderId, iid: &InstrumentId) -> bool {\n    core.order_owned(coid).map(|o| o.instrument_id() == iid).unwrap_or(false)\n}","tryCatchPattern":"match client.generate_order_status_report(Some(coid), void_id, Some(iid)).await {\n    Err(e) if e.to_string().contains(\"does not match requested instrument\") => retry_without_instrument(),\n    other => other?,\n}","preventionTips":["Source instrument ids from the same construction path used at order submission","Store the instrument id alongside order ids in strategy state","In multi-instrument strategies, key all order bookkeeping by (instrument, order id)"],"tags":["rust","instrument-id","validation","id-mismatch"],"backgroundTag":"invalid-argument-value","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"}