{"record":{"id":"4cb22f0081316b22","repo":"nautechsystems/nautilus_trader","slug":"cancel-order-failed-4cb22f","errorCode":null,"errorMessage":"cancel order failed","messagePattern":"cancel order failed","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/polymarket/src/execution/cancellations.rs","lineNumber":271,"sourceCode":"                        CommandFailure::VenueRejected(reason)\n                        | CommandFailure::NotSent(reason) => {\n                            let ts_now = clock.get_time_ns();\n                            emitter.emit_order_cancel_rejected(\n                                &order_clone,\n                                Some(venue_order_id),\n                                &reason,\n                                ts_now,\n                            );\n                        }\n                        CommandFailure::Ambiguous(reason) => {\n                            log::warn!(\n                                \"Cancel outcome unknown for {} ({}), awaiting reconciliation: {reason}\",\n                                order_clone.client_order_id(),\n                                venue_order_id,\n                            );\n                        }\n                    }\n                    return Err(anyhow::Error::new(e).context(\"cancel order failed\"));\n                }\n            }\n            Ok(())\n        });\n    }\n\n    pub(super) fn cancel_all_orders_command(&self, cmd: &CancelAllOrders) -> anyhow::Result<()> {\n        let cache = self.core.cache();\n        let side = cmd.order_side;\n        let asset_id = if side.is_none() {\n            let instrument = cache.instrument(&cmd.instrument_id).ok_or_else(|| {\n                anyhow::anyhow!(\n                    \"Cannot cancel all orders: instrument not found in cache for {}\",\n                    cmd.instrument_id\n                )\n            })?;\n            Some(instrument.raw_symbol().to_string())\n        } else {","sourceCodeStart":253,"sourceCodeEnd":289,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/polymarket/src/execution/cancellations.rs#L253-L289","documentation":"The Polymarket execution client's cancel_order_command issues a cancel over HTTP/WebSocket and, when the cancel request itself errors, wraps it with \"cancel order failed\". If the outcome is merely unknown, it logs and defers to reconciliation; this error means the cancel API call definitively failed.","triggerScenarios":"Calling cancel_order for an order on Polymarket when the CLOB API rejects the request: order already matched/canceled, invalid order id, authentication failure (bad API key/nonce), or network/HTTP error from the CLOB endpoint.","commonSituations":"Racing a fill so the order is gone and the cancel 4xx's; expired or out-of-sync Polymarket API credentials (nonce mismatch); a stale venue_order_id after a session restart; CLOB service outage.","solutions":["Check the underlying anyhow chain / logs for the CLOB error code (already-canceled vs auth vs network).","If order already filled/canceled, treat as success and skip re-canceling.","Verify Polymarket API credentials and that the signer nonce is current; re-derive API keys if needed.","Retry the cancel with fresh order state after reconciliation, not before.","Confirm the venue_order_id/client_order_id being canceled is still live."],"exampleFix":"// before\nlet _ = client.cancel_order(&instrument_id, &client_order_id);\n// after\nif let Err(e) = client.cancel_order(&instrument_id, &client_order_id) {\n    if !order_is_terminal(order.status()) {\n        return Err(e);\n    } // already filled/canceled: safe to ignore\n}","handlingStrategy":"try-catch","validationCode":"// check the order is still live before canceling\nif order.status() != OrderStatus::Accepted { return Ok(()); }","typeGuard":null,"tryCatchPattern":"match client.cancel_order(&instrument_id, &client_order_id) {\n    Ok(()) => {}\n    Err(e) if order_is_terminal(order.status()) => { /* raced with fill: safe */ }\n    Err(e) => return Err(e),\n}","preventionTips":["Check local order status before issuing cancels to avoid fill races","Keep Polymarket API credentials and nonces synchronized","Handle 'already canceled/matched' responses as success","Reconcile order state after any cancel failure before retrying"],"tags":["polymarket","cancel-order","http","clob"],"backgroundTag":"http-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"}