{"record":{"id":"dfbc0348897a2610","repo":"nautechsystems/nautilus_trader","slug":"cannot-claim-venue-order-id-for-settlement-orde","errorCode":null,"errorMessage":"cannot claim venue order ID {} for settlement order {client_order_id}: {e}","messagePattern":"cannot claim venue order ID (.+?) for settlement order (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/execution/src/matching_engine/settlement.rs","lineNumber":188,"sourceCode":"            self.dispatch_order_event(OrderEventAny::Filled(leg.fill));\n        }\n\n        Ok(())\n    }\n\n    fn option_register_settlement_plan(&self, plan: &OptionSettlementPlan) -> anyhow::Result<()> {\n        for leg in &plan.legs {\n            let client_order_id = leg.order.client_order_id();\n            let mut cache = self.cache.borrow_mut();\n            cache\n                .add_order(leg.order.clone(), leg.fill.position_id, None, false)\n                .map_err(|e| {\n                    anyhow::anyhow!(\"cannot add settlement order {client_order_id}: {e}\")\n                })?;\n            cache\n                .add_venue_order_id(&client_order_id, &leg.fill.venue_order_id, false)\n                .map_err(|e| {\n                    anyhow::anyhow!(\n                        \"cannot claim venue order ID {} for settlement order {client_order_id}: {e}\",\n                        leg.fill.venue_order_id\n                    )\n                })?;\n        }\n        Ok(())\n    }\n\n    fn option_should_exercise(&self, underlying_price: Price) -> bool {\n        let strike = match self.instrument.strike_price() {\n            Some(p) => p.as_decimal(),\n            None => return false,\n        };\n        let spot = underlying_price.as_decimal();\n        match self.instrument.option_kind() {\n            Some(OptionKind::Call) => spot > strike,\n            Some(OptionKind::Put) => strike > spot,\n            None => false,","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/execution/src/matching_engine/settlement.rs#L170-L206","documentation":"NautilusTrader's option settlement plan executor claims the venue order ID for each settlement leg in the execution cache. This error means `cache.add_venue_order_id` returned an error, so the venue order ID could not be associated with the settlement order's client order ID (typically because the client order ID is unknown to the cache or the venue order ID is already claimed by another order).","triggerScenarios":"Calling `option_apply_settlement_plan` (via `option_register_settlement_plan`) when a leg's client_order_id is not registered in the cache, or when `leg.fill.venue_order_id` was already claimed by a different client order ID.","commonSituations":"Replaying or restarting a settlement flow with cached/duplicate venue order IDs; registering a settlement plan whose client order IDs were never added to the cache; concurrent settlement of the same expired option position from two processes.","solutions":["Ensure each settlement leg's client order ID exists in the cache before applying the plan (the settlement order must have been added first).","Check for duplicate venue order IDs across legs or against previously settled orders; regenerate unique venue order IDs per fill.","Log the underlying cache error `{e}` to identify whether it is a missing order or an ID conflict, and fix the registration sequence accordingly."],"exampleFix":"// before: applying plan without registering the settlement order first\napply_settlement_plan(plan);\n// after: register each leg's client order and venue order ID in order\nfor leg in &plan.legs {\n    cache.add_order(...)?:\n    cache.add_venue_order_id(&leg.client_order_id, &leg.fill.venue_order_id, false)?;\n}","handlingStrategy":"try-catch","validationCode":"if cache.client_order_id(&leg.fill.venue_order_id).is_some() {\n    return Err(anyhow!(\"venue order ID {} already claimed\", leg.fill.venue_order_id));\n}","typeGuard":null,"tryCatchPattern":"match cache.add_venue_order_id(&client_order_id, &leg.fill.venue_order_id, false) {\n    Ok(_) => {},\n    Err(e) => log::error!(\"settlement claim failed: {e}\"),\n}","preventionTips":["Register the settlement order in the cache before claiming its venue order ID.","Guarantee venue order ID uniqueness across settlement legs and runs.","Avoid running concurrent settlement flows for the same instrument."],"tags":["cache","settlement","venue-order-id","rust"],"backgroundTag":"invalid-state-transition","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"}