{"record":{"id":"bee3084be9d0bab9","repo":"nautechsystems/nautilus_trader","slug":"order-detail-venue-order-id-mismatch-for-venue-or","errorCode":null,"errorMessage":"Order detail venue order ID mismatch for {venue_order_id}: returned {}","messagePattern":"Order detail venue order ID mismatch for (.+?): returned (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/okx/src/http/client.rs","lineNumber":4407,"sourceCode":"            [] => 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,\n            instrument.id(),\n            instrument.price_precision(),\n            instrument.size_precision(),\n            ts_init,\n        )?;\n        let post_only_rejected = order.state == OKXOrderStatus::Canceled\n            && report.filled_qty.is_zero()\n            && (order.cancel_source == OKX_POST_ONLY_CANCEL_SOURCE\n                || order.cancel_source_reason.contains(\"POST_ONLY\"));","sourceCodeStart":4389,"sourceCodeEnd":4425,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/okx/src/http/client.rs#L4389-L4425","documentation":"If the caller supplied a venue_order_id, the adapter additionally checks that the returned order's ordId equals it. A mismatch means the exchange returned a different order than requested under that identifier, so the adapter bails to prevent fabricating a status report for the wrong order.","triggerScenarios":"request_order_detail called with venue_order_id V, and OKX returns a record whose ord_id != V (e.g. identifier reused/rotated, or exchange-side id aliasing).","commonSituations":"Stale venue_order_id cached from a previous session; OKX changing/renaming ordId after order amendments; copy-paste or mapping bugs in reconciliation code.","solutions":["Refresh the venue_order_id from the exchange (order list / reconciliation) before the detail query","Prefer client_order_id (clOrdId) lookup if the venue order ID is uncertain","Verify the venue_order_id originates from the same instrument/account context as the query"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// confirm the cached venue_order_id is still current via order list before detail lookup","typeGuard":"fn venue_id_matches(returned: &str, requested: &VenueOrderId) -> bool {\n    returned == requested.as_str()\n}","tryCatchPattern":"match client.request_order_detail(instrument_id, None, Some(void)).await {\n    Ok(r) => { /* use */ }\n    Err(e) if e.to_string().contains(\"venue order ID mismatch\") => {\n        // refresh venue_order_id from exchange and retry\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Refresh venue_order_ids from reconciliation instead of caching them across sessions","Prefer client_order_id lookups when venue order IDs may have rotated","Log both requested and returned IDs on mismatch for diagnostics"],"tags":["okx","orders","id-mismatch","validation"],"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"}