{"record":{"id":"6ffa103c16283652","repo":"nautechsystems/nautilus_trader","slug":"python-on-historical-book-deltas-failed-e","errorCode":null,"errorMessage":"Python on_historical_book_deltas failed: {e}","messagePattern":"Python on_historical_book_deltas failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/common/src/python/actor.rs","lineNumber":1218,"sourceCode":"    }\n\n    fn on_historical_data(&mut self, data: &dyn Any) -> anyhow::Result<()> {\n        Python::attach(|py| {\n            let py_data: Py<PyAny> = if let Some(custom_data) = data.downcast_ref::<CustomData>() {\n                Py::new(py, custom_data.clone())?.into_any()\n            } else if let Some(custom_data) = data.downcast_ref::<Vec<CustomData>>() {\n                custom_data.clone().into_py_any(py)?\n            } else {\n                anyhow::bail!(\"Failed to convert historical data to Python: unsupported type\");\n            };\n            self.dispatch_on_historical_data(py_data)\n                .map_err(|e| anyhow::anyhow!(\"Python on_historical_data failed: {e}\"))\n        })\n    }\n\n    fn on_historical_book_deltas(&mut self, deltas: &[OrderBookDelta]) -> anyhow::Result<()> {\n        self.dispatch_on_historical_book_deltas(deltas.to_vec())\n            .map_err(|e| anyhow::anyhow!(\"Python on_historical_book_deltas failed: {e}\"))\n    }\n\n    fn on_historical_book_depth(&mut self, depths: &[OrderBookDepth10]) -> anyhow::Result<()> {\n        self.dispatch_on_historical_book_depth(depths.to_vec())\n            .map_err(|e| anyhow::anyhow!(\"Python on_historical_book_depth failed: {e}\"))\n    }\n\n    fn on_historical_quotes(&mut self, quotes: &[QuoteTick]) -> anyhow::Result<()> {\n        self.dispatch_on_historical_quotes(quotes.to_vec())\n            .map_err(|e| anyhow::anyhow!(\"Python on_historical_quotes failed: {e}\"))\n    }\n\n    fn on_historical_trades(&mut self, trades: &[TradeTick]) -> anyhow::Result<()> {\n        self.dispatch_on_historical_trades(trades.to_vec())\n            .map_err(|e| anyhow::anyhow!(\"Python on_historical_trades failed: {e}\"))\n    }\n\n    fn on_historical_funding_rates(","sourceCodeStart":1200,"sourceCodeEnd":1236,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/common/src/python/actor.rs#L1200-L1236","documentation":"Raised by `DataActor::on_historical_book_deltas` (crates/common/src/python/actor.rs:1218) when dispatching a slice of `OrderBookDeltas` to the Python actor's `on_historical_book_deltas` callback fails. The dispatch clones the deltas into a Vec and calls the Python method via pyo3; Python exceptions in the handler or conversion failures of the deltas list become `Python on_historical_book_deltas failed: {e}`.","triggerScenarios":"Occurs when historical order-book deltas are delivered (e.g. from a historical request) and the Python callback raises an exception, the Python object lacks a callable `on_historical_book_deltas`, or the deltas fail to convert into Python objects.","commonSituations":"Handlers rebuilding book state from deltas raising on malformed/empty delta batches; treating historical deltas like live incremental updates; version drift in OrderBookDelta fields; missing handler after subscribing to historical book data.","solutions":["Inspect the wrapped `{e}` cause (Python traceback) and fix the code in `on_historical_book_deltas`.","Verify the Python actor implements `on_historical_book_deltas(self, deltas)`.","Handle empty delta lists and book-status/reset records defensively before applying deltas.","Confirm delta field access matches OrderBookDelta in your installed nautilus version."],"exampleFix":"# before: assumes every record is an update\ndef on_historical_book_deltas(self, deltas):\n    for d in deltas:\n        self.book.apply(d)\n\n# after\ndef on_historical_book_deltas(self, deltas):\n    if not deltas:\n        return\n    for d in deltas:\n        if d.action == BookAction.CLEAR:\n            self.book.clear(d.instrument_id)\n        else:\n            self.book.apply(d)","handlingStrategy":"try-catch","validationCode":"assert callable(getattr(actor, 'on_historical_book_deltas', None)), \"actor must implement on_historical_book_deltas\"\n","typeGuard":"def has_book_deltas_handler(obj):\n    return callable(getattr(obj, 'on_historical_book_deltas', None))\n","tryCatchPattern":"try:\n    actor.on_historical_book_deltas(deltas)\nexcept Exception as e:\n    log.error(f\"on_historical_book_deltas failed: {e}\", exc_info=True)\n","preventionTips":["Handle empty delta batches and CLEAR/reset actions before applying","Do not assume historical deltas behave like live incremental updates","Unit-test book rebuilding from recorded historical deltas","Verify OrderBookDelta field names after each nautilus upgrade"],"tags":["python","orderbook","historical-data","callback","rust"],"backgroundTag":"api-request-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"}