{"record":{"id":"51f4d3c1dc81271f","repo":"nautechsystems/nautilus_trader","slug":"polymarketfeemodel-requires-a-binary-option-instru","errorCode":null,"errorMessage":"PolymarketFeeModel requires a binary option instrument","messagePattern":"PolymarketFeeModel requires a binary option instrument","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/polymarket/src/models.rs","lineNumber":61,"sourceCode":"    feature = \"python\",\n    pyo3::pyclass(\n        module = \"nautilus_trader.adapters.polymarket\",\n        extends = PyFeeModel,\n        skip_from_py_object\n    )\n)]\npub struct PolymarketFeeModel;\n\nimpl FeeModel for PolymarketFeeModel {\n    fn get_commission(\n        &self,\n        order: &OrderAny,\n        fill_quantity: Quantity,\n        fill_px: Price,\n        instrument: &InstrumentAny,\n    ) -> anyhow::Result<Money> {\n        let InstrumentAny::BinaryOption(binary) = instrument else {\n            anyhow::bail!(\"PolymarketFeeModel requires a binary option instrument\");\n        };\n\n        let liquidity_side = match order.liquidity_side() {\n            Some(LiquiditySide::Maker) => LiquiditySide::Maker,\n            Some(LiquiditySide::Taker) => LiquiditySide::Taker,\n            Some(LiquiditySide::NoLiquiditySide) | None => {\n                anyhow::bail!(\"Liquidity side not set\")\n            }\n        };\n\n        let Some(schedule) = binary\n            .info\n            .as_ref()\n            .and_then(|info| info.get(\"fee_schedule\"))\n            .map(|value| serde_json::from_value::<FeeSchedule>(value.clone()))\n            .transpose()\n            .context(\"invalid Polymarket fee schedule\")?\n        else {","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/polymarket/src/models.rs#L43-L79","documentation":"PolymarketFeeModel::get_commission computes fees only for BinaryOption instruments, since Polymarket's fee schedule applies to binary markets. Passing any other InstrumentAny variant (e.g. a Perpetual or Equity) bails with this error. It is a guard against applying the Polymarket fee formula to unsupported instruments.","triggerScenarios":"Calling get_commission (directly or via the trading engine's commission calculation) with an instrument that is not a BinaryOption while the Polymarket fee model is installed.","commonSituations":"Configuring the PolymarketFeeModel on a venue/portfolio that also holds non-binary instruments; test fixtures passing a generic instrument; instrument lookup returning the wrong instrument for an order.","solutions":["Ensure the instrument associated with the order is a Polymarket BinaryOption.","Only install PolymarketFeeModel on executions for Polymarket binary option markets.","Check the instrument_id on the order maps to an instrument added via parse_gamma_market.","Match on InstrumentAny::BinaryOption in caller code before invoking the fee model."],"exampleFix":"// before\nlet fee = fee_model.get_commission(&order, qty, px, &instrument)?;\n// after\nlet fee = match &instrument {\n    InstrumentAny::BinaryOption(_) => fee_model.get_commission(&order, qty, px, &instrument)?,\n    _ => Money::zero(instrument.quote_currency()),\n};","handlingStrategy":"type-guard","validationCode":"let is_binary = matches!(instrument, InstrumentAny::BinaryOption(_));\nif !is_binary { /* use default fee model or skip */ }","typeGuard":"fn is_binary_option(inst: &InstrumentAny) -> bool {\n    matches!(inst, InstrumentAny::BinaryOption(_))\n}","tryCatchPattern":"match fee_model.get_commission(&order, qty, px, &instrument) {\n    Ok(fee) => fee,\n    Err(e) if e.to_string().contains(\"requires a binary option\") => Money::zero(instrument.quote_currency()),\n    Err(e) => return Err(e),\n}","preventionTips":["Install PolymarketFeeModel only for Polymarket binary option venues.","Resolve instruments via the adapter cache so types are guaranteed.","Assert instrument type in test fixtures."],"tags":["fees","type-mismatch","polymarket"],"backgroundTag":"type-mismatch","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}