{"record":{"id":"5ec681b35cf5b206","repo":"nautechsystems/nautilus_trader","slug":"python-on-index-price-failed-e","errorCode":null,"errorMessage":"Python on_index_price failed: {e}","messagePattern":"Python on_index_price failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/common/src/python/actor.rs","lineNumber":1138,"sourceCode":"\n    fn on_book_depth(&mut self, depth: &OrderBookDepth10) -> anyhow::Result<()> {\n        self.dispatch_on_book_depth(depth)\n            .map_err(|e| anyhow::anyhow!(\"Python on_book_depth failed: {e}\"))\n    }\n\n    fn on_book(&mut self, order_book: &OrderBook) -> anyhow::Result<()> {\n        self.dispatch_on_book(order_book)\n            .map_err(|e| anyhow::anyhow!(\"Python on_book failed: {e}\"))\n    }\n\n    fn on_mark_price(&mut self, mark_price: &MarkPriceUpdate) -> anyhow::Result<()> {\n        self.dispatch_on_mark_price(*mark_price)\n            .map_err(|e| anyhow::anyhow!(\"Python on_mark_price failed: {e}\"))\n    }\n\n    fn on_index_price(&mut self, index_price: &IndexPriceUpdate) -> anyhow::Result<()> {\n        self.dispatch_on_index_price(*index_price)\n            .map_err(|e| anyhow::anyhow!(\"Python on_index_price failed: {e}\"))\n    }\n\n    fn on_funding_rate(&mut self, funding_rate: &FundingRateUpdate) -> anyhow::Result<()> {\n        self.dispatch_on_funding_rate(*funding_rate)\n            .map_err(|e| anyhow::anyhow!(\"Python on_funding_rate failed: {e}\"))\n    }\n\n    fn on_instrument_status(&mut self, data: &InstrumentStatus) -> anyhow::Result<()> {\n        self.dispatch_on_instrument_status(*data)\n            .map_err(|e| anyhow::anyhow!(\"Python on_instrument_status failed: {e}\"))\n    }\n\n    fn on_instrument_close(&mut self, update: &InstrumentClose) -> anyhow::Result<()> {\n        self.dispatch_on_instrument_close(*update)\n            .map_err(|e| anyhow::anyhow!(\"Python on_instrument_close failed: {e}\"))\n    }\n\n    fn on_option_greeks(&mut self, greeks: &OptionGreeks) -> anyhow::Result<()> {","sourceCodeStart":1120,"sourceCodeEnd":1156,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/common/src/python/actor.rs#L1120-L1156","documentation":"This error wraps any Python exception raised inside the actor's `on_index_price` callback when an `IndexPriceUpdate` is delivered to the Python subclass. The Rust `PyDataActor` invokes the Python method via `call_method1`; a `PyErr` is converted to an anyhow error with this message. The actual exception origin is in user Python handler code (or the Rust-to-Python conversion), not the dispatch itself.","triggerScenarios":"Any exception raised by the user's `on_index_price(self, index_price)` override — e.g. referencing index_price.price when the conversion produced a different attribute, dict lookups on an unseen instrument_id, or helper functions that raise on the first index-price tick.","commonSituations":"Index-arbitrage strategies consuming index prices whose handler assumes an attribute layout from an older nautilus_trader version; strategies receiving index prices for instruments they didn't expect due to misconfigured subscriptions.","solutions":["Inspect the Python traceback appended after 'Python on_index_price failed:' to locate the raising line.","Validate index_price fields (None/NaN) before computing anything in the handler.","Confirm the callback signature matches on_index_price(self, index_price) for the installed version.","Filter subscriptions so only expected instruments reach this handler."],"exampleFix":"// before\ndef on_index_price(self, index_price):\n    self.last_index[index_price.instrument_id.value] = index_price.price\n\n// after\ndef on_index_price(self, index_price):\n    if index_price.price is None:\n        return\n    self.last_index[str(index_price.instrument_id)] = index_price.price","handlingStrategy":"type-guard","validationCode":"if index_price.price is None or index_price.price != index_price.price:\n    return  # None or NaN","typeGuard":"def is_usable_index_price(update):\n    px = getattr(update, \"price\", None)\n    return isinstance(px, (int, float)) and px == px and px != 0","tryCatchPattern":"def on_index_price(self, index_price):\n    try:\n        self._on_index(index_price)\n    except Exception as e:\n        self.log.error(f\"on_index_price failed: {e}\", exc_info=True)","preventionTips":["Validate index price values before storing or computing spreads","Keep handler signatures in sync with the installed version's API docs","Filter subscriptions to expected instrument IDs","Use .get() with defaults for per-instrument state lookups"],"tags":["python","rust-bridge","callback-exception","actor"],"backgroundTag":"python-callback-failed","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"}