nautechsystems/nautilus_trader · error

Polymarket Data API returned trade for condition {} while re

Error message

Polymarket Data API returned trade for condition {} while requesting {expected_condition_id}

What it means

validate_trade_page_scope checks that every trade row returned by a Data API page matches the condition_id that was requested. If any row's condition_id differs (case-insensitively), the API violated the request scope and the adapter bails instead of emitting ticks for the wrong market.

Source

Thrown at crates/adapters/polymarket/src/http/data_api.rs:120

            encode_decimal(&mut descriptor, trade.price);
            encode_decimal(&mut descriptor, trade.size);
            descriptor.extend_from_slice(&trade.timestamp.to_be_bytes());
            descriptor
        })
        .collect();
    fingerprint_multiset(2, descriptors)
}

fn validate_trade_page_scope(
    rows: Vec<DataApiTrade>,
    expected_condition_id: &str,
) -> anyhow::Result<Vec<DataApiTrade>> {
    match rows.iter().find(|trade| {
        !trade
            .condition_id
            .eq_ignore_ascii_case(expected_condition_id)
    }) {
        Some(trade) => anyhow::bail!(
            "Polymarket Data API returned trade for condition {} while requesting {expected_condition_id}",
            trade.condition_id
        ),
        None => Ok(rows),
    }
}

fn encode_decimal(output: &mut Vec<u8>, value: Decimal) {
    let normalized = value.normalize();
    output.extend_from_slice(&normalized.mantissa().to_be_bytes());
    output.extend_from_slice(&normalized.scale().to_be_bytes());
}

#[derive(Clone, Debug, Eq, PartialEq)]
enum TradeTickStop {
    CallerCapped,
    VenueOffsetCeiling(OffsetCeilingSource),
}

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Retry the fetch — a transient upstream bug may return the correct scope on a subsequent request.
  2. Verify the expected_condition_id used in the request is correct (copy it from the market's gamma metadata).
  3. Check for a misconfigured Data API base URL or proxy returning data for the wrong market.
  4. Report/inspect the offending trade's condition_id (it is included in the message) to identify the scope violation source.

Example fix

// before: trusting API pages blindly
let trades = data_api.fetch_trades_page(&condition_id, offset).await?;
// after: the library already validates; handle the failure explicitly
match data_api.fetch_trades_page(&condition_id, offset).await {
    Ok(trades) => process(trades),
    Err(e) if e.to_string().contains("while requesting") => retry_with_backoff(&condition_id, offset),
    Err(e) => return Err(e),
}
Defensive patterns

Strategy: retry

Try / catch

// Rust
match fetch_page(&condition_id, offset).await {
    Ok(rows) => Ok(rows),
    Err(e) if e.to_string().contains("while requesting") => {
        warn!("scope violation from Data API, retrying");
        retry_with_backoff(|| fetch_page(&condition_id, offset)).await
    }
    Err(e) => Err(e),
}

Prevention

When it happens

Trigger: Fetching trade ticks via FetchOutcome::Page when the Polymarket Data API returns a page containing a trade whose condition_id does not equal the expected_condition_id of the request.

Common situations: Upstream API behavior changes or bugs returning cross-market rows; condition ids differing only in case are tolerated, so this fires only on genuinely different conditions; stale or manipulated cached API responses; proxy/mirror endpoints serving aggregated data.

Understand the failure class

Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.

Related errors


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