nautechsystems/nautilus_trader · error
expected Polymarket BinaryOption instrument, found {instrume
Error message
expected Polymarket BinaryOption instrument, found {instrument:?} What it means
validate_instrument_binding expects the instrument bound to a Polymarket condition to be a BinaryOption whose metadata carries condition_id and outcome info; if the caller passes any other InstrumentAny variant, it bails with a debug dump of what was actually found. It is an internal binding/type contract check during order-report and trade reconciliation.
Source
Thrown at crates/adapters/polymarket/src/execution/reconciliation.rs:244
.with_context(|| format!("maker trade {} has invalid trade ID source", trade.id))?;
let composite_trade_id = composite_trade_id_value(&trade.id, &maker_order.order_id);
let trade_id = checked_trade_id(
&composite_trade_id,
&format!("maker trade {} composite", trade.id),
)?;
Ok(ValidatedMakerReportIdentifiers {
venue_order_id,
trade_id,
})
}
fn validate_instrument_binding(
instrument: &InstrumentAny,
condition_id: &str,
outcome: PolymarketOutcome,
) -> anyhow::Result<()> {
let InstrumentAny::BinaryOption(binary) = instrument else {
anyhow::bail!("expected Polymarket BinaryOption instrument, found {instrument:?}");
};
let instrument_condition = binary
.info
.as_ref()
.and_then(|info| info.get_str("condition_id"))
.context("Polymarket instrument is missing condition_id metadata")?;
anyhow::ensure!(
instrument_condition.eq_ignore_ascii_case(condition_id),
"provider condition {condition_id} does not match instrument condition {instrument_condition}",
);
let instrument_outcome = binary
.outcome
.context("Polymarket instrument is missing outcome metadata")?;
anyhow::ensure!(
instrument_outcome == outcome.as_str(),
"provider outcome {outcome} does not match instrument outcome {instrument_outcome}",
);View on GitHub (pinned to 18893faf8b)
Solutions
- Ensure the instrument for this condition_id was created as a Polymarket BinaryOption via the Polymarket instrument provider/factory.
- Check that reconciliation inputs come from Polymarket order/fill events, not another adapter's instrument cache.
- Log/inspect the instrument debug output in the message to see which variant was actually passed and where it originated.
- Add an up-front assert or filter that only BinaryOption instruments reach the Polymarket reconciliation path.
Example fix
// before
let report = build_order_report_from_order(&any_instrument, &order)?;
// after
if !matches!(any_instrument, InstrumentAny::BinaryOption(_)) {
eprintln!("skipping non-BinaryOption instrument in Polymarket reconciliation");
return Ok(None);
}
let report = build_order_report_from_order(&any_instrument, &order)?; Defensive patterns
Strategy: type-guard
Validate before calling
let InstrumentAny::BinaryOption(binary) = instrument else {
return Err(format!("Polymarket reconciliation requires BinaryOption, got {instrument:?}"));
}; Type guard
fn is_polymarket_binary(instrument: &InstrumentAny) -> bool {
matches!(instrument, InstrumentAny::BinaryOption(_))
} Prevention
- Register instruments through the Polymarket provider so they are BinaryOption
- Keep other venues' instruments out of the Polymarket reconciliation path
- Check the instrument's condition_id metadata at registration time
- Use matches!/let-else narrowing before any condition-specific logic
When it happens
Trigger: Calling build_order_report_from_order, classify_target_trade, or build_fill_reports_from_trades with an instrument registered as a non-BinaryOption type (e.g. a generic equity or crypto perpetual) that is not a Polymarket binary market, or with an incorrectly-registered instrument.
Common situations: Registering instruments with the wrong factory during adapter setup; feeding orders/fills from another venue into the Polymarket reconciliation path; a version change where instrument construction defaults changed.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Binance Futures position has unresolved instrument {instrume
- unmapped_in_scope_message("open order", instrument_id, Some(
- unmapped_in_scope_message("position", instrument_id, None, c
- provider venue order {} is not owned by the account
- unmapped in-scope open order instrument {instrument_id} (tok
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/5f821271b9594254.
Report an issue: GitHub.