{"record":{"id":"a6574b2a5004e1e1","repo":"nautechsystems/nautilus_trader","slug":"python-on-historical-book-depth-failed-e","errorCode":null,"errorMessage":"Python on_historical_book_depth failed: {e}","messagePattern":"Python on_historical_book_depth failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/common/src/python/actor.rs","lineNumber":1223,"sourceCode":"                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(\n        &mut self,\n        funding_rates: &[FundingRateUpdate],\n    ) -> anyhow::Result<()> {\n        self.dispatch_on_historical_funding_rates(funding_rates.to_vec())\n            .map_err(|e| anyhow::anyhow!(\"Python on_historical_funding_rates failed: {e}\"))","sourceCodeStart":1205,"sourceCodeEnd":1241,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/common/src/python/actor.rs#L1205-L1241","documentation":"Raised by `DataActor::on_historical_book_depth` (crates/common/src/python/actor.rs:1223) when dispatching a slice of `OrderBookDepth10` snapshots to the Python actor's `on_historical_book_depth` callback fails. The dispatch copies the depths and invokes the Python method via pyo3 `call_method1`; exceptions raised in the Python handler or conversion failures of the depth list are wrapped as `Python on_historical_book_depth failed: {e}`.","triggerScenarios":"Fires when historical L2/L3 depth snapshots are delivered to the actor and the Python callback raises, the Python instance has no callable `on_historical_book_depth`, or the `OrderBookDepth10` entries fail Python conversion.","commonSituations":"Handlers iterating depth levels with assumptions about fixed 10-level shape (None levels on thin books) causing TypeErrors; mixing up depth vs deltas handling; missing handler implementation; schema changes across nautilus versions.","solutions":["Read the wrapped `{e}` cause for the original Python exception and fix `on_historical_book_depth`.","Ensure the Python actor defines `on_historical_book_depth(self, depth)`.","Handle None/partial depth levels instead of assuming all 10 levels are populated.","Recheck depth field access against OrderBookDepth10 for your nautilus version."],"exampleFix":"# before: crashes on thin books with None levels\ndef on_historical_book_depth(self, depth):\n    best = depth.bids[0].price\n\n# after\ndef on_historical_book_depth(self, depth):\n    levels = [lvl for lvl in depth.bids if lvl is not None]\n    if not levels:\n        return\n    best = levels[0].price","handlingStrategy":"try-catch","validationCode":"assert callable(getattr(actor, 'on_historical_book_depth', None)), \"actor must implement on_historical_book_depth\"\n","typeGuard":"def has_book_depth_handler(obj):\n    return callable(getattr(obj, 'on_historical_book_depth', None))\n","tryCatchPattern":"try:\n    actor.on_historical_book_depth(depth)\nexcept Exception as e:\n    log.error(f\"on_historical_book_depth failed: {e}\", exc_info=True)\n","preventionTips":["Filter out None depth levels instead of assuming a full 10-level book","Guard against empty bids/asks before reading best prices","Keep depth handling separate from delta handling logic","Test handlers on thin/one-sided books"],"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"}