{"record":{"id":"50054686e4bef2d5","repo":"nautechsystems/nautilus_trader","slug":"cannot-cancel-lighter-order-venue-order-id-not","errorCode":null,"errorMessage":"cannot cancel Lighter order {}: venue order_id not yet known (await OrderAccepted before issuing cancel)","messagePattern":"cannot cancel Lighter order (.+?): venue order_id not yet known \\(await OrderAccepted before issuing cancel\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/lighter/src/execution.rs","lineNumber":1794,"sourceCode":"        let market_index = self\n            .registry\n            .market_index(&cmd.instrument_id)\n            .ok_or_else(|| {\n                anyhow::anyhow!(\n                    \"no Lighter market_index registered for instrument {}\",\n                    cmd.instrument_id,\n                )\n            })?;\n\n        self.core.cache().try_order(&cmd.client_order_id)?;\n\n        // Lighter cancel_order targets a single order by venue order_id.\n        // The map is populated on the first OrderStatusReport for the cloid.\n        let voi = cmd\n            .venue_order_id\n            .or_else(|| self.dispatch.lookup_venue_order_id(&cmd.client_order_id))\n            .ok_or_else(|| {\n                anyhow::anyhow!(\n                    \"cannot cancel Lighter order {}: venue order_id not yet known \\\n                     (await OrderAccepted before issuing cancel)\",\n                    cmd.client_order_id,\n                )\n            })?;\n\n        let venue_index: i64 = voi\n            .as_str()\n            .parse()\n            .with_context(|| format!(\"Lighter venue_order_id `{voi}` is not an integer index\"))?;\n\n        Ok(CancelOrderPlan {\n            client_order_id: cmd.client_order_id,\n            strategy_id: cmd.strategy_id,\n            instrument_id: cmd.instrument_id,\n            venue_order_id: Some(voi),\n            market_index,\n            venue_index,","sourceCodeStart":1776,"sourceCodeEnd":1812,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/lighter/src/execution.rs#L1776-L1812","documentation":"Lighter cancels target a venue order_id, but neither the command nor the adapter's dispatch map (populated on the first OrderStatusReport/OrderAccepted for the client_order_id) knows it. The order is likely not yet accepted by the venue, so there is nothing addressable to cancel.","triggerScenarios":"dispatch_signed_cancel_order or batch_cancel_orders where cmd.venue_order_id is None AND dispatch.lookup_venue_order_id(&cmd.client_order_id) is None — cancel issued before any status report arrived for the order.","commonSituations":"Flatten/cancel-all logic racing a just-submitted order; cancel sent immediately after submit without awaiting OrderAccepted; WS event latency delaying the first status report; order actually rejected so no venue id ever arrives.","solutions":["Wait for the OrderAccepted event (or a venue_order_id) before issuing the cancel.","Retry the cancel with backoff; the venue order_id may arrive momentarily via WS.","Verify the client_order_id is correct — a typo'd id never maps to a venue order.","Handle the rejected-order case: if no report ever arrives, the order may have been rejected."],"exampleFix":"// before\nexecution.cancel_order(CancelOrder::new(instrument_id, cloid, None))?; // immediately after submit\n// after\nwait_for_event(Event::OrderAccepted(cloid)).await;\nexecution.cancel_order(CancelOrder::new(instrument_id, cloid, None))?;","handlingStrategy":"retry","validationCode":"// Rust\nanyhow::ensure!(\n    cmd.venue_order_id.is_some() || dispatch_has_venue_id(&cmd.client_order_id),\n    \"await OrderAccepted before cancelling {}\",\n    cmd.client_order_id\n);","typeGuard":null,"tryCatchPattern":"match adapter.cancel_order(cmd.clone()) {\n    Err(e) if e.to_string().contains(\"venue order_id not yet known\") => {\n        wait_for_order_accepted(cmd.client_order_id, Duration::from_secs(5)).await?;\n        adapter.cancel_order(cmd)\n    }\n    other => other,\n}","preventionTips":["Wait for OrderAccepted events before canceling freshly submitted orders","Implement cancel retries with backoff in flatten logic","Track order lifecycle state per client_order_id in the strategy"],"tags":["cancel","order-lifecycle","race-condition","trading"],"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-14T05:17:10.506Z"}