nautechsystems/nautilus_trader · error
Python on_option_greeks failed: {e}
Error message
Python on_option_greeks failed: {e} What it means
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.
Source
Thrown at crates/common/src/python/actor.rs:1158
fn on_funding_rate(&mut self, funding_rate: &FundingRateUpdate) -> anyhow::Result<()> {
self.dispatch_on_funding_rate(*funding_rate)
.map_err(|e| anyhow::anyhow!("Python on_funding_rate failed: {e}"))
}
fn on_instrument_status(&mut self, data: &InstrumentStatus) -> anyhow::Result<()> {
self.dispatch_on_instrument_status(*data)
.map_err(|e| anyhow::anyhow!("Python on_instrument_status failed: {e}"))
}
fn on_instrument_close(&mut self, update: &InstrumentClose) -> anyhow::Result<()> {
self.dispatch_on_instrument_close(*update)
.map_err(|e| anyhow::anyhow!("Python on_instrument_close failed: {e}"))
}
fn on_option_greeks(&mut self, greeks: &OptionGreeks) -> anyhow::Result<()> {
self.dispatch_on_option_greeks(*greeks)
.map_err(|e| anyhow::anyhow!("Python on_option_greeks failed: {e}"))
}
fn on_option_chain(&mut self, slice: &OptionChainSlice) -> anyhow::Result<()> {
self.dispatch_on_option_chain(slice.clone())
.map_err(|e| anyhow::anyhow!("Python on_option_chain failed: {e}"))
}
#[cfg(feature = "defi")]
fn on_block(&mut self, block: &Block) -> anyhow::Result<()> {
self.dispatch_on_block(block.clone())
.map_err(|e| anyhow::anyhow!("Python on_block failed: {e}"))
}
#[cfg(feature = "defi")]
fn on_pool(&mut self, pool: &Pool) -> anyhow::Result<()> {
self.dispatch_on_pool(pool.clone())
.map_err(|e| anyhow::anyhow!("Python on_pool failed: {e}"))
}View on GitHub (pinned to 18893faf8b)
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.
Example fix
// before
def on_option_greeks(self, greeks):
self.portfolio_delta += self.positions[greeks.instrument_id.value] * greeks.delta
// after
def on_option_greeks(self, greeks):
if greeks.delta is None or greeks.delta != greeks.delta:
return
pos = self.positions.get(str(greeks.instrument_id), 0)
self.portfolio_delta += pos * greeks.delta Defensive patterns
Strategy: type-guard
Validate before calling
import math
d = getattr(greeks, "delta", None)
if d is None or (isinstance(d, float) and math.isnan(d)):
return Type guard
def has_usable_greeks(g):
def ok(v):
return v is not None and not (isinstance(v, float) and math.isnan(v))
return ok(getattr(g, "delta", None)) and ok(getattr(g, "gamma", None)) Try / catch
def on_option_greeks(self, greeks):
try:
self._aggregate_greeks(greeks)
except Exception as e:
self.log.error(f"on_option_greeks failed: {e}", exc_info=True) Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Python on_book failed: {e}
- Python on_mark_price failed: {e}
- Python on_index_price failed: {e}
- Python on_funding_rate failed: {e}
- Python on_instrument_status failed: {e}
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/3b6902ef21c3f185.
Report an issue: GitHub.