nautechsystems/nautilus_trader · error

target order {venue_order_id} appears more than once in trad

Error message

target order {venue_order_id} appears more than once in trade {}

What it means

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.

Source

Thrown at crates/adapters/polymarket/src/execution/reconciliation.rs:165

    }
    Ok(())
}

fn validate_target_trade_role(
    trade: &PolymarketTradeReport,
    venue_order_id: VenueOrderId,
) -> anyhow::Result<bool> {
    let target_is_taker = trade.taker_order_id == venue_order_id.as_str();
    let target_maker_occurrences = trade
        .maker_orders
        .iter()
        .filter(|order| order.order_id == venue_order_id.as_str())
        .count();
    let target_is_maker = target_maker_occurrences > 0;
    if !target_is_taker && !target_is_maker {
        return Ok(false);
    }
    anyhow::ensure!(
        usize::from(target_is_taker) + target_maker_occurrences == 1,
        "target order {venue_order_id} appears more than once in trade {}",
        trade.id,
    );
    let declared_maker = trade.trader_side == PolymarketLiquiditySide::Maker;
    anyhow::ensure!(
        declared_maker == target_is_maker,
        "trade {} trader_side {:?} contradicts target order {venue_order_id} participant role",
        trade.id,
        trade.trader_side,
    );
    Ok(true)
}

fn validate_maker_order_side(
    trade: &PolymarketTradeReport,
    maker_order: &PolymarketMakerOrder,
) -> anyhow::Result<OrderSide> {

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Inspect the provider trade payload (trade.id) and check the maker_orders array for duplicated order IDs before reconciliation.
  2. Skip or deduplicate the trade and re-fetch it from the provider API, since a single order cannot legitimately fill twice in one trade.
  3. If self-matching is possible, configure the venue/strategy to prevent orders crossing against themselves.
  4. File/verify with Polymarket that the trade payload is correct; treat it as corrupt data and abort reconciliation for that trade.

Example fix

// before: reconciling any trade returned by the provider
for trade in trades {
    classify_target_trade(trade, venue_order_id)?;
}
// after: pre-filter trades where the order id appears more than once
for trade in trades {
    let roles = count_order_roles(&trade, venue_order_id);
    if roles != 1 { continue; } // skip ambiguous/corrupt trades
    classify_target_trade(trade, venue_order_id)?;
}
Defensive patterns

Strategy: validation

Validate before calling

fn order_appears_once(trade: &Trade, venue_order_id: &VenueOrderId) -> bool {
    let maker_count = trade.maker_orders.iter().filter(|o| o.order_id == venue_order_id.as_str()).count();
    let is_taker = trade.taker_order_id.as_deref() == Some(venue_order_id.as_str());
    usize::from(is_taker) + maker_count == 1
}

Type guard

fn is_well_formed_trade(trade: &Trade, vid: &str) -> bool {
    !trade.maker_orders.iter().filter(|o| o.order_id == vid).count() > 1
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/5f379b20d1320797. Report an issue: GitHub.