{"record":{"id":"8da2809fcc111704","repo":"nautechsystems/nautilus_trader","slug":"python-on-quote-failed-e","errorCode":null,"errorMessage":"Python on_quote failed: {e}","messagePattern":"Python on_quote failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/common/src/python/actor.rs","lineNumber":1103,"sourceCode":"    }\n\n    fn on_socket_state(&mut self, event: &SocketStateChanged) -> anyhow::Result<()> {\n        self.dispatch_on_socket_state(event)\n            .map_err(|e| anyhow::anyhow!(\"Python on_socket_state failed: {e}\"))\n    }\n\n    fn on_instrument(&mut self, instrument: &InstrumentAny) -> anyhow::Result<()> {\n        Python::attach(|py| {\n            let py_instrument = instrument_any_to_pyobject(py, instrument.clone())\n                .map_err(|e| anyhow::anyhow!(\"Failed to convert InstrumentAny to Python: {e}\"))?;\n            self.dispatch_on_instrument(py_instrument)\n                .map_err(|e| anyhow::anyhow!(\"Python on_instrument failed: {e}\"))\n        })\n    }\n\n    fn on_quote(&mut self, quote: &QuoteTick) -> anyhow::Result<()> {\n        self.dispatch_on_quote(*quote)\n            .map_err(|e| anyhow::anyhow!(\"Python on_quote failed: {e}\"))\n    }\n\n    fn on_trade(&mut self, tick: &TradeTick) -> anyhow::Result<()> {\n        self.dispatch_on_trade(*tick)\n            .map_err(|e| anyhow::anyhow!(\"Python on_trade failed: {e}\"))\n    }\n\n    fn on_bar(&mut self, bar: &Bar) -> anyhow::Result<()> {\n        self.dispatch_on_bar(*bar)\n            .map_err(|e| anyhow::anyhow!(\"Python on_bar failed: {e}\"))\n    }\n\n    fn on_book_deltas(&mut self, deltas: &OrderBookDeltas) -> anyhow::Result<()> {\n        self.dispatch_on_book_deltas(deltas.clone())\n            .map_err(|e| anyhow::anyhow!(\"Python on_book_deltas failed: {e}\"))\n    }\n\n    fn on_book_depth(&mut self, depth: &OrderBookDepth10) -> anyhow::Result<()> {","sourceCodeStart":1085,"sourceCodeEnd":1121,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/common/src/python/actor.rs#L1085-L1121","documentation":"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.","triggerScenarios":"A quote tick arrives after subscribe_quote_ticks and the Python `on_quote(self, tick)` override raises an exception.","commonSituations":"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.","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"],"exampleFix":"// before\ndef on_quote(self, tick):\n    mid = (tick.bid_price + tick.ask_price) / 2  # raises on NaN\n// after\ndef on_quote(self, tick):\n    if tick.bid_price.is_nan() or tick.ask_price.is_nan():\n        return\n    mid = (tick.bid_price + tick.ask_price) / 2","handlingStrategy":"try-catch","validationCode":"def _valid_quote(tick) -> bool:\n    return (tick.bid_price is not None and tick.ask_price is not None\n            and tick.bid_price > 0 and tick.ask_price > 0)","typeGuard":null,"tryCatchPattern":"try:\n    self.dispatch_on_quote(tick)\nexcept Exception as e:\n    self.log.error(f'Python on_quote failed: {e}', exc_info=True)","preventionTips":["Validate bid/ask sanity before calculations","Keep on_quote hot-path logic minimal","Initialize indicators before subscribing to quotes"],"tags":["python","actor","callback","market-data"],"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-14T00:17:10.932Z"}