{"record":{"id":"f25c54133d8e4956","repo":"nautechsystems/nautilus_trader","slug":"order-detail-instrument-mismatch-for-instrument-i","errorCode":null,"errorMessage":"Order detail instrument mismatch for {instrument_id}: returned {}","messagePattern":"Order detail instrument mismatch for (.+?): returned (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/okx/src/http/client.rs","lineNumber":4398,"sourceCode":"        let params = params_builder\n            .build()\n            .map_err(|e| anyhow::anyhow!(\"Failed to build order detail params: {e}\"))?;\n        let orders = match self.inner.get_order(params).await {\n            Ok(orders) => orders,\n            Err(e) if e.is_order_not_found() => return Ok(None),\n            Err(e) => return Err(e.into()),\n        };\n        let order = match orders.as_slice() {\n            [] => return Ok(None),\n            [order] => order,\n            _ => anyhow::bail!(\n                \"Order detail returned {} records for one identifier\",\n                orders.len(),\n            ),\n        };\n\n        if order.inst_id.as_str() != instrument_id.symbol.inner() {\n            anyhow::bail!(\n                \"Order detail instrument mismatch for {instrument_id}: returned {}\",\n                order.inst_id,\n            );\n        }\n\n        if let Some(venue_order_id) = venue_order_id\n            && order.ord_id.as_str() != venue_order_id.as_str()\n        {\n            anyhow::bail!(\n                \"Order detail venue order ID mismatch for {venue_order_id}: returned {}\",\n                order.ord_id,\n            );\n        }\n\n        let ts_init = self.generate_ts_init();\n        let mut report = parse_order_status_report(\n            order,\n            account_id,","sourceCodeStart":4380,"sourceCodeEnd":4416,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/okx/src/http/client.rs#L4380-L4416","documentation":"When a single order-detail record comes back, the adapter verifies that the returned instId matches the instrument_id the caller requested. A mismatch means OKX returned an order for a different instrument than asked — the identifier resolved to a different market — so the adapter bails rather than produce a wrong report.","triggerScenarios":"request_order_detail called with instrument_id X but OKX returns an order whose inst_id differs (e.g. querying a clOrdId that was reused on another instrument, or a stale/incorrect instrument_id).","commonSituations":"Client order IDs generated without instrument scoping and reused across instruments; cached instrument_id diverging from where the order actually lives; symbol mapping errors between Nautilus InstrumentId and OKX instId.","solutions":["Verify the instrument_id matches the instrument the order was placed on","Use unique client_order_ids per instrument (or query by venue_order_id) to avoid cross-instrument resolution","Check the symbol mapping between Nautilus and OKX (instId formatting) for the instrument"],"exampleFix":"// before\nclient.request_order_detail(wrong_instrument_id, None, Some(venue_order_id)).await?;\n// after\nclient.request_order_detail(order.instrument_id, None, Some(venue_order_id)).await?;","handlingStrategy":"validation","validationCode":"// ensure the instrument matches the one the order was placed on\nif order.instrument_id != instrument_id {\n    return Err(anyhow::anyhow!(\"instrument mismatch before detail request\"));\n}","typeGuard":"fn matches_instrument(report_inst: &str, requested: &InstrumentId) -> bool {\n    report_inst == requested.symbol.inner()\n}","tryCatchPattern":"match client.request_order_detail(instrument_id, coid, void).await {\n    Ok(r) => { /* use */ }\n    Err(e) if e.to_string().contains(\"instrument mismatch\") => {\n        log::error!(\"wrong instrument for order lookup: {e}\");\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Scope client_order_ids per instrument so lookups resolve to the right market","Keep instrument_id and order identifiers sourced from the same order record","Verify Nautilus-to-OKX symbol mapping for every instrument in use"],"tags":["okx","orders","instrument-mismatch","validation"],"backgroundTag":"invalid-identifier","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"}