{"record":{"id":"67eacc3467fadb6c","repo":"nautechsystems/nautilus_trader","slug":"python-on-historical-trades-failed-e","errorCode":null,"errorMessage":"Python on_historical_trades failed: {e}","messagePattern":"Python on_historical_trades failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/common/src/python/actor.rs","lineNumber":1233,"sourceCode":"\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}\"))\n    }\n\n    fn on_historical_bars(&mut self, bars: &[Bar]) -> anyhow::Result<()> {\n        self.dispatch_on_historical_bars(bars.to_vec())\n            .map_err(|e| anyhow::anyhow!(\"Python on_historical_bars failed: {e}\"))\n    }\n\n    fn on_historical_mark_prices(&mut self, mark_prices: &[MarkPriceUpdate]) -> anyhow::Result<()> {\n        self.dispatch_on_historical_mark_prices(mark_prices.to_vec())\n            .map_err(|e| anyhow::anyhow!(\"Python on_historical_mark_prices failed: {e}\"))","sourceCodeStart":1215,"sourceCodeEnd":1251,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/common/src/python/actor.rs#L1215-L1251","documentation":"Raised by `DataActor::on_historical_trades` (crates/common/src/python/actor.rs:1233) when dispatching a slice of `TradeTick` historical data to the Python actor's `on_historical_trades` callback fails. The dispatch copies the trades and calls the Python method through pyo3; exceptions raised in the Python handler, an absent callback method, or trade-to-Python conversion failures are wrapped as `Python on_historical_trades failed: {e}`.","triggerScenarios":"Fires when historical trade ticks are delivered (e.g. result of `request_trades`) and the Python `on_historical_trades` callback raises an exception, the Python object lacks a callable `on_historical_trades`, or the TradeTick list fails conversion.","commonSituations":"Handler analysis code (VWAP, aggregation) raising on empty input or bad price/size fields; requesting historical trades without implementing the handler; confusion between live on_trade_tick and historical variant; schema changes after upgrades.","solutions":["Read the wrapped `{e}` cause to get the original Python exception and fix the `on_historical_trades` handler.","Ensure the Python actor implements `on_historical_trades(self, trades)`.","Handle empty trade lists and validate price/size fields before aggregation math.","Confirm TradeTick field names against your installed nautilus version."],"exampleFix":"# before\ndef on_historical_trades(self, trades):\n    vwap = sum(t.price * t.size for t in trades) / sum(t.size for t in trades)  # ZeroDivisionError\n\n# after\ndef on_historical_trades(self, trades):\n    total_size = sum(t.size for t in trades)\n    if not trades or total_size == 0:\n        return\n    vwap = sum(t.price * t.size for t in trades) / total_size","handlingStrategy":"try-catch","validationCode":"assert callable(getattr(actor, 'on_historical_trades', None)), \"actor must implement on_historical_trades\"\n","typeGuard":"def has_trades_handler(obj):\n        return callable(getattr(obj, 'on_historical_trades', None))\n","tryCatchPattern":"try:\n    actor.on_historical_trades(trades)\nexcept Exception as e:\n    log.error(f\"on_historical_trades failed: {e}\", exc_info=True)\n","preventionTips":["Guard aggregation math (VWAP, sums) against empty lists and zero totals","Implement the handler on any actor that calls request_trades","Validate price/size fields before computing","Unit-test the handler with recorded historical TradeTick data"],"tags":["python","historical-data","trades","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-14T05:17:10.506Z"}