{"record":{"id":"3b6902ef21c3f185","repo":"nautechsystems/nautilus_trader","slug":"python-on-option-greeks-failed-e","errorCode":null,"errorMessage":"Python on_option_greeks failed: {e}","messagePattern":"Python on_option_greeks failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/common/src/python/actor.rs","lineNumber":1158,"sourceCode":"\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\")]\n    fn on_block(&mut self, block: &Block) -> anyhow::Result<()> {\n        self.dispatch_on_block(block.clone())\n            .map_err(|e| anyhow::anyhow!(\"Python on_block failed: {e}\"))\n    }\n\n    #[cfg(feature = \"defi\")]\n    fn on_pool(&mut self, pool: &Pool) -> anyhow::Result<()> {\n        self.dispatch_on_pool(pool.clone())\n            .map_err(|e| anyhow::anyhow!(\"Python on_pool failed: {e}\"))\n    }","sourceCodeStart":1140,"sourceCodeEnd":1176,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/common/src/python/actor.rs#L1140-L1176","documentation":"This error wraps any Python exception raised inside the actor's `on_option_greeks` callback when an `OptionGreeks` update is dispatched to the Python subclass. The Rust `PyDataActor` calls the Python method via `call_method1`; the resulting `PyErr` becomes an anyhow error with this message. The underlying exception originates in the user's Python override or the Rust-to-Python conversion of the greeks data.","triggerScenarios":"Any exception raised by the user's `on_option_greeks(self, greeks)` override — e.g. arithmetic on None/NaN delta or IV, portfolio-greeks aggregation keyed by a missing option_id, or a raising Rust-to-Python conversion of the OptionGreeks struct.","commonSituations":"Options market-making/hedging strategies that receive greeks before the corresponding option position is registered; NaN greeks from the provider on illiquid strikes; version upgrades changing OptionGreeks fields.","solutions":["Read the appended Python traceback after 'Python on_option_greeks failed:' to locate the raising line.","Validate greeks fields (None/NaN) before aggregating into portfolio risk.","Register option instruments before subscribing to greeks so lookups succeed.","Confirm OptionGreeks attribute names for the installed nautilus_trader version."],"exampleFix":"// before\ndef on_option_greeks(self, greeks):\n    self.portfolio_delta += self.positions[greeks.instrument_id.value] * greeks.delta\n\n// after\ndef on_option_greeks(self, greeks):\n    if greeks.delta is None or greeks.delta != greeks.delta:\n        return\n    pos = self.positions.get(str(greeks.instrument_id), 0)\n    self.portfolio_delta += pos * greeks.delta","handlingStrategy":"type-guard","validationCode":"import math\nd = getattr(greeks, \"delta\", None)\nif d is None or (isinstance(d, float) and math.isnan(d)):\n    return","typeGuard":"def has_usable_greeks(g):\n    def ok(v):\n        return v is not None and not (isinstance(v, float) and math.isnan(v))\n    return ok(getattr(g, \"delta\", None)) and ok(getattr(g, \"gamma\", None))","tryCatchPattern":"def on_option_greeks(self, greeks):\n    try:\n        self._aggregate_greeks(greeks)\n    except Exception as e:\n        self.log.error(f\"on_option_greeks failed: {e}\", exc_info=True)","preventionTips":["Skip NaN/None greeks (common on illiquid strikes) before risk aggregation","Ensure option instruments are registered before greeks arrive","Use .get() with 0 defaults for per-option positions","Review OptionGreeks bindings after each nautilus_trader upgrade"],"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"}