{"record":{"id":"2083d8f7146d10ff","repo":"nautechsystems/nautilus_trader","slug":"python-on-instrument-status-failed-e","errorCode":null,"errorMessage":"Python on_instrument_status failed: {e}","messagePattern":"Python on_instrument_status failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/common/src/python/actor.rs","lineNumber":1148,"sourceCode":"\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<()> {\n        self.dispatch_on_option_greeks(*greeks)\n            .map_err(|e| anyhow::anyhow!(\"Python on_option_greeks failed: {e}\"))\n    }\n\n    fn on_option_chain(&mut self, slice: &OptionChainSlice) -> anyhow::Result<()> {\n        self.dispatch_on_option_chain(slice.clone())\n            .map_err(|e| anyhow::anyhow!(\"Python on_option_chain failed: {e}\"))\n    }\n\n    #[cfg(feature = \"defi\")]","sourceCodeStart":1130,"sourceCodeEnd":1166,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/common/src/python/actor.rs#L1130-L1166","documentation":"This error wraps any Python exception raised inside the actor's `on_instrument_status` callback when an `InstrumentStatus` event (e.g. trading halt/resume) is dispatched to the Python subclass. The Rust `PyDataActor` invokes the Python method via `call_method1`; a resulting `PyErr` is converted to an anyhow error with this message. The exception itself is raised in user Python code or during Rust-to-Python conversion of the event.","triggerScenarios":"Any exception raised by the user's `on_instrument_status(self, data)` override — e.g. comparing data.status against a non-existent enum member, mutating a dict during iteration, or a helper expecting a different status-event type.","commonSituations":"Strategies reacting to exchange trading halts/maintenance windows; venue-specific status events arriving with statuses the handler's enum mapping lacks; brokers pushing unexpected instrument status during volatile sessions.","solutions":["Read the appended Python traceback after 'Python on_instrument_status failed:' to locate the raising line.","Handle unknown status values with a default branch instead of assuming a closed enum.","Match the InstrumentStatus API (event, status action) for your installed nautilus_trader version.","Log the raw event before processing so unexpected statuses are visible in production."],"exampleFix":"// before\ndef on_instrument_status(self, data):\n    if data.status == InstrumentStatusAction.TRADING_HALT:\n        self.cancel_all()\n\n// after\ndef on_instrument_status(self, data):\n    action = getattr(data, \"status\", None)\n    if action == InstrumentStatusAction.TRADING_HALT:\n        self.cancel_all()\n    else:\n        self.log.warning(f\"Unhandled instrument status: {action}\")","handlingStrategy":"validation","validationCode":"action = getattr(data, \"status\", None)\nknown = {s for s in InstrumentStatusAction}\nif action not in known:\n    self.log.warning(f\"unknown status {action!r}\"); return","typeGuard":"def is_known_status(data):\n    action = getattr(data, \"status\", None)\n    try:\n        return action in set(InstrumentStatusAction)\n    except TypeError:\n        return False","tryCatchPattern":"def on_instrument_status(self, data):\n    try:\n        self._handle_status(data)\n    except Exception as e:\n        self.log.error(f\"on_instrument_status failed: {e}\", exc_info=True)","preventionTips":["Treat status enums as open sets — always provide a default branch","Log unexpected status events in production","Avoid mutating shared dicts/lists while iterating in the handler","Test with venue-specific status events (halts, maintenance)"],"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"}