{"record":{"id":"c4829db136fcc1de","repo":"nautechsystems/nautilus_trader","slug":"query-order-state-failed-e","errorCode":null,"errorMessage":"Query order state failed: {e}","messagePattern":"Query order state failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/deribit/src/execution.rs","lineNumber":818,"sourceCode":"        let trader_id = cmd.trader_id;\n        let strategy_id = cmd.strategy_id;\n        let instrument_id = cmd.instrument_id;\n\n        log::debug!(\"Querying order state: order_id={order_id}, client_order_id={client_order_id}\");\n\n        // Spawn async task to query order state via WebSocket\n        // Response will be dispatched through the WebSocket stream handler as OrderStatusReport\n        self.spawn_task(\"query_order\", async move {\n            ws_client\n                .query_order(\n                    &order_id,\n                    client_order_id,\n                    trader_id,\n                    strategy_id,\n                    instrument_id,\n                )\n                .await\n                .map_err(|e| anyhow::anyhow!(\"Query order state failed: {e}\"))?;\n            Ok(())\n        });\n\n        Ok(())\n    }\n\n    fn submit_order(&self, cmd: SubmitOrder) -> anyhow::Result<()> {\n        let order = self.core.cache().try_order_owned(&cmd.client_order_id)?;\n        self.submit_single_order(&order, \"submit_order\");\n        Ok(())\n    }\n\n    fn submit_order_list(&self, cmd: SubmitOrderList) -> anyhow::Result<()> {\n        if cmd.order_list.client_order_ids.is_empty() {\n            log::debug!(\"submit_order_list called with empty order list\");\n            return Ok(());\n        }\n","sourceCodeStart":800,"sourceCodeEnd":836,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/deribit/src/execution.rs#L800-L836","documentation":"Raised in `DeribitExecutionClient::query_order` when the actual `get_order_state` RPC to Deribit fails after the venue_order_id was successfully extracted. The adapter wraps the underlying ws-client error with `anyhow!(\"Query order state failed: {e}\")`, so the root cause (rejected request, unknown order id, timeout, transport failure) is inside `{e}`.","triggerScenarios":"Calling `query_order` with a valid `venue_order_id` where the subsequent Deribit `private/get_order_state` call returns Err — unknown/cancelled-long-ago order id purged by the venue, session/auth failure, network drop or ws reconnect in progress, or RPC timeout.","commonSituations":"Querying orders older than Deribit's `get_order_state` retention; querying on testnet with a mainnet order id (or vice versa); transient disconnects; expired API credentials; malformed instrument context causing the wrong request.","solutions":["Inspect the wrapped `{e}` to distinguish auth vs unknown-order vs transport causes.","Verify the `venue_order_id` exists on the connected environment and within Deribit's order-state lookup window.","Reconnect/re-authenticate if the ws session dropped, then retry the query.","Check API key validity and permissions for `private/get_order_state`.","Add retry-with-backoff around query_order for transient transport errors."],"exampleFix":"// before\nclient.query_order(cmd).await?; // panics pipeline on transient ws error\n\n// after\nmatch client.query_order(cmd).await {\n    Ok(()) => {},\n    Err(e) if is_retryable(&e) => retry_with_backoff(3, || client.query_order(cmd.clone())).await?,\n    Err(e) => return Err(e),\n}","handlingStrategy":"try-catch","validationCode":"// Before querying, confirm the order id is from the same environment and recent enough\nassert_eq!(order.venue.as_str(), \"DERIBIT\");\nassert!(order.is_recent(DERIBIT_ORDER_STATE_RETENTION));","typeGuard":null,"tryCatchPattern":"// Rust\nmatch client.query_order(cmd).await {\n    Ok(()) => {}\n    Err(e) if format!(\"{e:#}\").contains(\"Query order state failed\") => {\n        // check inner error: re-auth / reconnect on transport errors, skip on unknown-order\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Verify the venue_order_id belongs to the connected environment (testnet vs mainnet).","Query only within Deribit's order-state retention window; use the trade/reporting API for historical orders.","Reconnect and re-authenticate the ws client after disconnects before retrying queries.","Apply bounded retry with backoff for transient transport errors."],"tags":["deribit","query-order","rpc-failure","network","execution-client"],"backgroundTag":"api-error-response","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"}