{"record":{"id":"a5c1bd1bb918b8a4","repo":"nautechsystems/nautilus_trader","slug":"command-instrument-id-does-not-match-cached-ord","errorCode":null,"errorMessage":"command instrument ID {} does not match cached order {}","messagePattern":"command instrument ID (.+?) does not match cached order (.+?)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/interactive_brokers/src/execution/core.rs","lineNumber":2112,"sourceCode":"            order_id = exec_data.execution.order_id,\n            order_ref = exec_data.execution.order_reference.as_str(),\n            execution_id = exec_data.execution.execution_id.as_str(),\n            error = %error,\n            \"Failed to parse IBKR historical fill report\",\n        );\n    }\n\n    fn validate_cancel_order_target(\n        cmd: &CancelOrder,\n        target_order: &OrderAny,\n    ) -> anyhow::Result<()> {\n        anyhow::ensure!(\n            cmd.client_order_id == target_order.client_order_id(),\n            \"command client order ID {} does not match cached order {}\",\n            cmd.client_order_id,\n            target_order.client_order_id()\n        );\n        anyhow::ensure!(\n            cmd.instrument_id == target_order.instrument_id(),\n            \"command instrument ID {} does not match cached order {}\",\n            cmd.instrument_id,\n            target_order.instrument_id()\n        );\n\n        // Command actor IDs identify the requester and are not ownership evidence\n        if let (Some(command_venue_order_id), Some(target_venue_order_id)) =\n            (cmd.venue_order_id.as_ref(), target_order.venue_order_id())\n        {\n            anyhow::ensure!(\n                command_venue_order_id == &target_venue_order_id,\n                \"command venue order ID {command_venue_order_id} does not match cached order {target_venue_order_id}\"\n            );\n        }\n\n        Ok(())\n    }","sourceCodeStart":2094,"sourceCodeEnd":2130,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/interactive_brokers/src/execution/core.rs#L2094-L2130","documentation":"Companion check in `validate_cancel_order_target`: the `CancelOrder` command's `instrument_id` must equal the cached order's `instrument_id`. A mismatch means the cancel command targets an order resolved on a different instrument, which would route the cancel to the wrong IB contract, so `ensure!` aborts with this error.","triggerScenarios":"A `CancelOrder` whose `cmd.instrument_id` differs from `target_order.instrument_id()` — typically a cache lookup that returned an order from another instrument, or a command built with the wrong/synthetic instrument ID.","commonSituations":"Instrument ID symbol/venue suffix mismatches after symbol mapping changes; cache keyed incorrectly; using a continuation/rolled contract ID while the cached order carries the original ID.","solutions":["Verify the instrument ID (symbol and venue) on the command matches the order's instrument, including suffix conventions.","Re-resolve the cached order by `cmd.client_order_id` instead of by instrument to avoid cross-instrument lookups.","If instrument IDs legitimately changed (contract roll), update cached orders via reconciliation before cancelling."],"exampleFix":"// before\nanyhow::ensure!(cmd.instrument_id == target_order.instrument_id(), ...);\n// after (fix at call site: resolve by client_order_id)\nlet target_order = cache.order(&cmd.client_order_id)?;\nanyhow::ensure!(cmd.instrument_id == target_order.instrument_id(), ...);","handlingStrategy":"validation","validationCode":"// Ensure instrument IDs match before cancelling\nanyhow::ensure!(\n    cmd.instrument_id == order.instrument_id(),\n    \"instrument mismatch: cmd={} order={}\", cmd.instrument_id, order.instrument_id()\n);","typeGuard":"fn same_instrument(cmd: &CancelOrder, order: &OrderAny) -> bool {\n    cmd.instrument_id == order.instrument_id()\n}","tryCatchPattern":"if !same_instrument(&cmd, &order) {\n    return Err(anyhow::anyhow!(\n        \"cancel {} refused: instrument {} != order instrument {}\",\n        cmd.client_order_id, cmd.instrument_id, order.instrument_id()\n    ));\n}","preventionTips":["Standardize instrument ID formatting (symbol + venue suffix) across command construction and cache writes.","Handle contract rolls by updating cached orders before cancelling.","Resolve orders by client order ID rather than by instrument to prevent cross-instrument hits."],"tags":["rust","validation","order-management","instrument-id"],"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-14T05:17:10.506Z"}