{"record":{"id":"5f379b20d1320797","repo":"nautechsystems/nautilus_trader","slug":"target-order-venue-order-id-appears-more-than-on","errorCode":null,"errorMessage":"target order {venue_order_id} appears more than once in trade {}","messagePattern":"target order (.+?) appears more than once in trade (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/polymarket/src/execution/reconciliation.rs","lineNumber":165,"sourceCode":"    }\n    Ok(())\n}\n\nfn validate_target_trade_role(\n    trade: &PolymarketTradeReport,\n    venue_order_id: VenueOrderId,\n) -> anyhow::Result<bool> {\n    let target_is_taker = trade.taker_order_id == venue_order_id.as_str();\n    let target_maker_occurrences = trade\n        .maker_orders\n        .iter()\n        .filter(|order| order.order_id == venue_order_id.as_str())\n        .count();\n    let target_is_maker = target_maker_occurrences > 0;\n    if !target_is_taker && !target_is_maker {\n        return Ok(false);\n    }\n    anyhow::ensure!(\n        usize::from(target_is_taker) + target_maker_occurrences == 1,\n        \"target order {venue_order_id} appears more than once in trade {}\",\n        trade.id,\n    );\n    let declared_maker = trade.trader_side == PolymarketLiquiditySide::Maker;\n    anyhow::ensure!(\n        declared_maker == target_is_maker,\n        \"trade {} trader_side {:?} contradicts target order {venue_order_id} participant role\",\n        trade.id,\n        trade.trader_side,\n    );\n    Ok(true)\n}\n\nfn validate_maker_order_side(\n    trade: &PolymarketTradeReport,\n    maker_order: &PolymarketMakerOrder,\n) -> anyhow::Result<OrderSide> {","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/polymarket/src/execution/reconciliation.rs#L147-L183","documentation":"During Polymarket trade reconciliation, the target order (the venue order being reconciled) must appear exactly once in the provider trade: either as the taker, or exactly once in the maker order list. This ensure! fires when the venue_order_id shows up in both roles or multiple times among makers, meaning the trade cannot be unambiguously attributed to one order.","triggerScenarios":"classify_target_trade -> validate_target_trade_role is called with a provider trade whose maker list contains the venue order ID more than once, or the trade lists the venue order as taker AND also as a maker.","commonSituations":"Provider API returning a trade whose maker_orders array includes the same order twice (self-match or duplicate row from the data-api); self-trades where both sides belong to the same trader; a bug in parsing the trade payload duplicating rows.","solutions":["Inspect the provider trade payload (trade.id) and check the maker_orders array for duplicated order IDs before reconciliation.","Skip or deduplicate the trade and re-fetch it from the provider API, since a single order cannot legitimately fill twice in one trade.","If self-matching is possible, configure the venue/strategy to prevent orders crossing against themselves.","File/verify with Polymarket that the trade payload is correct; treat it as corrupt data and abort reconciliation for that trade."],"exampleFix":"// before: reconciling any trade returned by the provider\nfor trade in trades {\n    classify_target_trade(trade, venue_order_id)?;\n}\n// after: pre-filter trades where the order id appears more than once\nfor trade in trades {\n    let roles = count_order_roles(&trade, venue_order_id);\n    if roles != 1 { continue; } // skip ambiguous/corrupt trades\n    classify_target_trade(trade, venue_order_id)?;\n}","handlingStrategy":"validation","validationCode":"fn order_appears_once(trade: &Trade, venue_order_id: &VenueOrderId) -> bool {\n    let maker_count = trade.maker_orders.iter().filter(|o| o.order_id == venue_order_id.as_str()).count();\n    let is_taker = trade.taker_order_id.as_deref() == Some(venue_order_id.as_str());\n    usize::from(is_taker) + maker_count == 1\n}","typeGuard":"fn is_well_formed_trade(trade: &Trade, vid: &str) -> bool {\n    !trade.maker_orders.iter().filter(|o| o.order_id == vid).count() > 1\n}","tryCatchPattern":null,"preventionTips":["Pre-filter provider trades for duplicate order IDs before reconciliation","Configure venue/strategy to avoid self-matching orders","Deduplicate maker_orders rows after parsing the provider payload"],"tags":["rust","reconciliation","polymarket","data-integrity"],"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"}