{"record":{"id":"1cd846fc31228cb2","repo":"nautechsystems/nautilus_trader","slug":"modify-order-failed-e-1cd846","errorCode":null,"errorMessage":"Modify order failed: {e}","messagePattern":"Modify order failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/deribit/src/execution.rs","lineNumber":928,"sourceCode":"\n        // Spawn async task to send modify via WebSocket\n        self.spawn_task(\"modify_order\", async move {\n            if let Err(e) = ws_client\n                .modify_order(\n                    &order_id,\n                    quantity,\n                    price,\n                    client_order_id,\n                    trader_id,\n                    strategy_id,\n                    instrument_id,\n                )\n                .await\n            {\n                log::error!(\n                    \"Modify order failed: order_id={order_id}, client_order_id={client_order_id}, error={e}\"\n                );\n                anyhow::bail!(\"Modify order failed: {e}\");\n            }\n            Ok(())\n        });\n\n        Ok(())\n    }\n\n    fn cancel_order(&self, cmd: CancelOrder) -> anyhow::Result<()> {\n        let ws_client = self.ws_client.clone();\n\n        // Extract venue order ID (Deribit's order_id)\n        let order_id = match cmd.venue_order_id.as_ref() {\n            Some(venue_order_id) => venue_order_id.to_string(),\n            None => {\n                log::warn!(\n                    \"Cannot cancel order {} - no venue_order_id\",\n                    cmd.client_order_id\n                );","sourceCodeStart":910,"sourceCodeEnd":946,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/deribit/src/execution.rs#L910-L946","documentation":"The modify_order command is executed asynchronously via a spawned task; if the underlying ws_client modify-order request to Deribit fails, the error is logged with both order and client order IDs and re-raised as 'Modify order failed: {e}'. Note modify_order itself returns Ok(()) immediately — the failure surfaces in the spawned task.","triggerScenarios":"Calling modify_order with an order_id/client_order_id that does not exist on the venue, an invalid price/size adjustment, an already-filled or cancelled order, or when Deribit rejects the edit request (auth, rate limit, connection drop).","commonSituations":"Race where the order is filled/cancelled between submit and modify; stale venue_order_id; modifying an order on a disconnected WebSocket; Deribit rate limiting on order management calls.","solutions":["Check the inner error (logged with order_id/client_order_id) to determine the venue rejection reason","Verify the order is still open on Deribit before modifying (not filled or cancelled)","Confirm the WebSocket connection is alive and authenticated before issuing the modify","Handle Deribit rate limits by spacing out order-management calls"],"exampleFix":"// before\nif let Err(e) = ws_client.modify_order(order_id, client_order_id, price, size).await {\n    anyhow::bail!(\"Modify order failed: {e}\");\n}\n// after\nif let Err(e) = ws_client.modify_order(order_id, client_order_id, price, size).await {\n    log::warn!(\"modify rejected, refreshing order state before retry: {e}\");\n    let state = query_order_state(order_id).await?;\n    if state.is_open() {\n        ws_client.modify_order(order_id, client_order_id, price, size).await?;\n    }\n}","handlingStrategy":"try-catch","validationCode":"// Before modifying, confirm the order is still open\nlet open = live_orders.contains_key(&venue_order_id);\nif !open { log::warn!(\"skip modify: order not open\"); return Ok(()); }","typeGuard":null,"tryCatchPattern":"match client.modify_order(cmd).await {\n    Ok(()) => {} // note: failures surface asynchronously in the spawned task\n    Err(e) => log::error!(\"modify dispatch failed: {e}\"),\n}\n// watch the ModifyOrderRejected event / spawned-task error for the venue reason","preventionTips":["Track order state and only modify orders known to be open on the venue","Use client_order_id consistently so rejections are traceable","Throttle order-management calls to stay under Deribit rate limits","Re-check connectivity after any WebSocket drop before issuing modifies"],"tags":["order-management","websocket","deribit","async"],"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"}