{"record":{"id":"ae85eedf2254436c","repo":"nautechsystems/nautilus_trader","slug":"idempotent-duplicate","errorCode":"IDEMPOTENT_DUPLICATE","errorMessage":"IDEMPOTENT_DUPLICATE: Order likely exists but confirmation was lost","messagePattern":"IDEMPOTENT_DUPLICATE: Order likely exists but confirmation was lost","errorType":"error_code","errorClass":"anyhow::Error","httpStatus":null,"severity":"warning","filePath":"crates/adapters/bitmex/src/broadcast/submitter.rs","lineNumber":640,"sourceCode":"                    all_duplicate_clordid = false;\n                    all_definitive_refusals = false;\n                    log::warn!(\"{operation} task join error: {e:?}\");\n                    errors.push(format!(\"Task panicked: {e:?}\"));\n                }\n            }\n        }\n\n        // All tasks failed\n        self.failed_submits.fetch_add(1, Ordering::Relaxed);\n\n        // If all errors were \"Duplicate clOrdID\", this is likely an idempotent scenario\n        // where the order exists but the success response was lost\n        if all_duplicate_clordid && !errors.is_empty() {\n            log::warn!(\n                \"All {} requests returned 'Duplicate clOrdID' - order likely exists {params}\",\n                operation.to_lowercase(),\n            );\n            anyhow::bail!(\"IDEMPOTENT_DUPLICATE: Order likely exists but confirmation was lost\");\n        }\n\n        if all_definitive_refusals && !errors.is_empty() {\n            log::error!(\n                \"All {} requests were refused by BitMEX: {errors:?} {params}\",\n                operation.to_lowercase(),\n            );\n            anyhow::bail!(\n                \"{DEFINITIVE_SUBMIT_REJECTION}: All {} requests were refused by BitMEX: {errors:?}\",\n                operation.to_lowercase(),\n            );\n        }\n\n        log::error!(\n            \"All {} requests failed: {errors:?} {params}\",\n            operation.to_lowercase(),\n        );\n        Err(anyhow::anyhow!(","sourceCodeStart":622,"sourceCodeEnd":658,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/bitmex/src/broadcast/submitter.rs#L622-L658","documentation":"In process_submit_results, when every request in a broadcast submit returned BitMEX's 'Duplicate clOrdID' error, the library concludes the order most likely already exists on the exchange but the original success acknowledgment was lost (e.g. a dropped response after the order was accepted). It bails with a message prefixed IDEMPOTENT_DUPLICATE so callers can distinguish this idempotency case from genuine submission failures.","triggerScenarios":"Re-broadcasting a submit (retry path) whose clientOrderID already exists on BitMEX; all transport replicas answer 'Duplicate clOrdID' and errors is non-empty, so all_duplicate_clordid is true.","commonSituations":"Retrying a submit after a websocket disconnect or timeout where the first request actually succeeded; running redundant transport connections where the same order reached BitMEX twice; replaying a submit log after a crash.","solutions":["Treat the IDEMPOTENT_DUPLICATE prefix specially: query the open-order state by clOrdID instead of resubmitting with the same ID","On retry, fetch order status first (or use amend/query) rather than blind resubmit","If the order should be new, generate a fresh clOrdID only after confirming the original is truly absent","Deduplicate in-flight submits so the same clOrdID is not broadcast twice concurrently"],"exampleFix":"// before\nmatch submitter.broadcast_submit(order).await {\n    Err(e) if e.to_string().contains(\"IDEMPOTENT_DUPLICATE\") => {\n        // order probably exists — reconcile instead of failing\n        let existing = query_order_by_clordid(&order.cl_ord_id()).await?;\n    }\n    other => other?,\n}\n// after (avoid the case): reconcile before retry\nif query_order_by_clordid(&cl_ord_id).await?.is_some() {\n    return Ok(OrderStatus::Existing);\n}\nsubmitter.broadcast_submit(order).await?;","handlingStrategy":"try-catch","validationCode":"// before resubmitting, check if the order already exists\nlet exists = query_order_by_clordid(&cl_ord_id).await?.is_some();","typeGuard":"fn is_idempotent_duplicate(err: &anyhow::Error) -> bool {\n    err.to_string().starts_with(\"IDEMPOTENT_DUPLICATE\")\n}","tryCatchPattern":"match submitter.broadcast_submit(&order).await {\n    Err(e) if is_idempotent_duplicate(&e) => {\n        // reconcile: the order likely exists on the exchange\n        let status = query_order_by_clordid(&order.cl_ord_id()).await?;\n        adopt_existing_order(status);\n    }\n    other => other?,\n}","preventionTips":["Never blindly resubmit with the same clOrdID; query order state first","Use unique, deterministic clOrdIDs to make retries idempotent","Deduplicate in-flight submits across redundant transports","Reconcile local order state with the exchange after disconnects"],"tags":["bitmex","idempotency","order-submit","duplicate"],"backgroundTag":"duplicate-clordid","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"}