{"record":{"id":"0150284b3240cfb3","repo":"nautechsystems/nautilus_trader","slug":"maker-order-appears-more-than-once-in-trade","errorCode":null,"errorMessage":"maker order {} appears more than once in trade {}","messagePattern":"maker order (.+?) appears more than once in trade (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/polymarket/src/execution/reconciliation.rs","lineNumber":1171,"sourceCode":"                    }\n                };\n                let instrument_id = instrument.id();\n\n                if scope\n                    .instrument_id\n                    .is_some_and(|requested| instrument_id != requested)\n                {\n                    continue;\n                }\n\n                if !instrument_in_load_ids_scope(instrument_id, load_ids) {\n                    log::debug!(\n                        \"Dropping loaded out-of-scope historical instrument {instrument_id}\",\n                    );\n                    continue;\n                }\n\n                anyhow::ensure!(\n                    !selected_maker_orders\n                        .iter()\n                        .any(|(selected, _, _, _)| selected.order_id == mo.order_id),\n                    \"maker order {} appears more than once in trade {}\",\n                    mo.order_id,\n                    trade.id,\n                );\n\n                let identifiers = validate_maker_report_identifiers(trade, mo)?;\n\n                validate_instrument_binding(&instrument, trade.market.as_str(), mo.outcome)?;\n                validate_maker_order_side(trade, mo)?;\n                let last_px = validate_trade_values(\n                    mo.matched_amount,\n                    mo.price,\n                    instrument.size_precision(),\n                    &format!(\"maker order {} matched amount\", mo.order_id),\n                    &format!(\"maker order {} price\", mo.order_id),","sourceCodeStart":1153,"sourceCodeEnd":1189,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/polymarket/src/execution/reconciliation.rs#L1153-L1189","documentation":"While rebuilding trades from provider maker-order data, reconciliation asserts that each maker order (by order_id) appears in at most one trade. Seeing the same maker order id in two trades means the provider data is self-contradictory, so the reconciliation fails fast via `anyhow::ensure!` rather than double-counting a fill.","triggerScenarios":"Running Polymarket trade/fill reconciliation (the code path that iterates `selected_maker_orders` for a trade) when the provider response contains the same maker order_id attributed to two distinct trade ids, or duplicated within one trade's maker list.","commonSituations":"Provider API returning overlapping trade records across paginated queries; venue self-trade or merger of two fills causing one maker order to span records; mixing trades fetched at different times where one was later corrected/merged; buggy local grouping that inserts the same maker order into multiple trade buckets.","solutions":["Log the offending mo.order_id and the two trade ids, then query the Polymarket Data API directly to determine which trade attribution is correct.","Deduplicate maker orders by order_id across all fetched trades before reconciliation, dropping later duplicates whose payloads are identical.","Ensure trade fetches use a consistent snapshot (single request window) so a maker order is not attributed under both a pre- and post-correction record.","Upgrade the nautilus_polymarket adapter if the venue legitimately reattributes maker orders and newer reconciliation logic handles it."],"exampleFix":"// before: hard failure when a maker order spans two trades\nanyhow::ensure!(\n    !selected_maker_orders.iter().any(|(selected, _, _, _)| selected.order_id == mo.order_id),\n    \"maker order {} appears more than once in trade {}\",\n    mo.order_id,\n    trade.id,\n);\n// after: pre-deduplicate maker orders by order_id so each appears once\nlet mut seen_maker_orders: AHashSet<Uuid> = AHashSet::new();\nfor mo in maker_orders {\n    if !seen_maker_orders.insert(mo.order_id) {\n        log::warn!(\"Skipping duplicate maker order {}\", mo.order_id);\n        continue;\n    }\n    // ... admit maker order\n}","handlingStrategy":"validation","validationCode":"let mut seen: AHashSet<Uuid> = AHashSet::new();\nfor mo in all_maker_orders() {\n    if !seen.insert(mo.order_id) {\n        return Err(anyhow::anyhow!(\n            \"maker order {} pre-attributed to multiple trades; resolve before reconciling\",\n            mo.order_id,\n        ));\n    }\n}","typeGuard":"fn is_unique_maker_order(seen: &mut AHashSet<Uuid>, mo: &PolymarketMakerOrder) -> bool {\n    seen.insert(mo.order_id)\n}","tryCatchPattern":"match reconciliation_result {\n    Err(e) if e.to_string().contains(\"appears more than once in trade\") => {\n        log::warn!(\"duplicate maker order attribution; re-fetching trades from provider\");\n        retry_with_fresh_snapshot();\n    }\n    other => other?,\n}","preventionTips":["Group maker orders into trades once, from one provider snapshot","Deduplicate maker orders by order_id before trade reconciliation","Avoid merging trades fetched at different times when venue corrections may have occurred","Verify ambiguous attributions directly against the Polymarket Data API"],"tags":["reconciliation","data-integrity","polymarket","duplicate-data"],"backgroundTag":"internal-invariant-violation","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}