nautechsystems/nautilus_trader · error
Python on_quote failed: {e}
Error message
Python on_quote failed: {e} What it means
Wraps any failure raised when the Rust core dispatches a QuoteTick into the Python actor's `on_quote` handler. The exception originates in the user's Python `on_quote` implementation (or the dispatch call), and Rust re-raises it with the 'Python on_quote failed' prefix.
Source
Thrown at crates/common/src/python/actor.rs:1103
}
fn on_socket_state(&mut self, event: &SocketStateChanged) -> anyhow::Result<()> {
self.dispatch_on_socket_state(event)
.map_err(|e| anyhow::anyhow!("Python on_socket_state failed: {e}"))
}
fn on_instrument(&mut self, instrument: &InstrumentAny) -> anyhow::Result<()> {
Python::attach(|py| {
let py_instrument = instrument_any_to_pyobject(py, instrument.clone())
.map_err(|e| anyhow::anyhow!("Failed to convert InstrumentAny to Python: {e}"))?;
self.dispatch_on_instrument(py_instrument)
.map_err(|e| anyhow::anyhow!("Python on_instrument failed: {e}"))
})
}
fn on_quote(&mut self, quote: &QuoteTick) -> anyhow::Result<()> {
self.dispatch_on_quote(*quote)
.map_err(|e| anyhow::anyhow!("Python on_quote failed: {e}"))
}
fn on_trade(&mut self, tick: &TradeTick) -> anyhow::Result<()> {
self.dispatch_on_trade(*tick)
.map_err(|e| anyhow::anyhow!("Python on_trade failed: {e}"))
}
fn on_bar(&mut self, bar: &Bar) -> anyhow::Result<()> {
self.dispatch_on_bar(*bar)
.map_err(|e| anyhow::anyhow!("Python on_bar failed: {e}"))
}
fn on_book_deltas(&mut self, deltas: &OrderBookDeltas) -> anyhow::Result<()> {
self.dispatch_on_book_deltas(deltas.clone())
.map_err(|e| anyhow::anyhow!("Python on_book_deltas failed: {e}"))
}
fn on_book_depth(&mut self, depth: &OrderBookDepth10) -> anyhow::Result<()> {View on GitHub (pinned to 18893faf8b)
Solutions
- Read the chained `{e}` traceback and fix the exception in `on_quote`
- Validate tick values before use (e.g. bid_size/ask_size > 0) to avoid math errors
- Keep `on_quote` lightweight and wrap experimental logic in try/except with logging
- Ensure all indicators/state are initialized in on_start before subscribing
Example fix
// before
def on_quote(self, tick):
mid = (tick.bid_price + tick.ask_price) / 2 # raises on NaN
// after
def on_quote(self, tick):
if tick.bid_price.is_nan() or tick.ask_price.is_nan():
return
mid = (tick.bid_price + tick.ask_price) / 2 Defensive patterns
Strategy: try-catch
Validate before calling
def _valid_quote(tick) -> bool:
return (tick.bid_price is not None and tick.ask_price is not None
and tick.bid_price > 0 and tick.ask_price > 0) Try / catch
try:
self.dispatch_on_quote(tick)
except Exception as e:
self.log.error(f'Python on_quote failed: {e}', exc_info=True) Prevention
- Validate bid/ask sanity before calculations
- Keep on_quote hot-path logic minimal
- Initialize indicators before subscribing to quotes
When it happens
Trigger: A quote tick arrives after subscribe_quote_ticks and the Python `on_quote(self, tick)` override raises an exception.
Common situations: Hot-path quote handlers computing indicators on uninitialized state, division by zero on zero bid/ask, wrong handler arity, or heavy logic raising intermittently under high tick rates.
Related errors
- Python on_trade failed: {e}
- Python on_order failed: {e}
- Python on_order_list failed: {e}
- Python on_signal failed: {e}
- Python on_queue_state failed: {e}
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/8da2809fcc111704.
Report an issue: GitHub.