{"record":{"id":"aa61142eec6eeb90","repo":"nautechsystems/nautilus_trader","slug":"python-on-historical-funding-rates-failed-e","errorCode":null,"errorMessage":"Python on_historical_funding_rates failed: {e}","messagePattern":"Python on_historical_funding_rates failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/common/src/python/actor.rs","lineNumber":1241,"sourceCode":"            .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}\"))\n    }\n\n    fn on_historical_index_prices(\n        &mut self,\n        index_prices: &[IndexPriceUpdate],\n    ) -> anyhow::Result<()> {\n        self.dispatch_on_historical_index_prices(index_prices.to_vec())\n            .map_err(|e| anyhow::anyhow!(\"Python on_historical_index_prices failed: {e}\"))","sourceCodeStart":1223,"sourceCodeEnd":1259,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/common/src/python/actor.rs#L1223-L1259","documentation":"Raised by `DataActor::on_historical_funding_rates` (crates/common/src/python/actor.rs:1241) when dispatching a slice of `FundingRateUpdate` historical data to the Python actor's `on_historical_funding_rates` callback fails. The dispatch clones the updates and invokes the Python method via pyo3; Python exceptions in the handler, a missing callback, or conversion failures are wrapped as `Python on_historical_funding_rates failed: {e}`.","triggerScenarios":"Occurs when historical funding-rate updates are delivered (e.g. result of `request_funding_rates`) and the Python `on_historical_funding_rates` callback raises, the Python instance lacks the method, or the FundingRateUpdate list fails to convert to Python objects.","commonSituations":"Perp funding handlers raising on None/zero rates or missing instrument IDs; requesting funding rates without implementing the handler; confusion between funding-rate updates and other historical data types; version drift in FundingRateUpdate fields.","solutions":["Inspect the wrapped `{e}` cause for the original Python exception and fix `on_historical_funding_rates`.","Implement `on_historical_funding_rates(self, funding_rates)` on the Python actor when requesting funding rates.","Validate rate values (None/zero/negative) inside the handler before applying funding logic.","Check FundingRateUpdate field access against your installed nautilus version."],"exampleFix":"# before\ndef on_historical_funding_rates(self, rates):\n    self.position_adjust(rates[-1].rate)  # IndexError on empty list\n\n# after\ndef on_historical_funding_rates(self, rates):\n    if not rates or rates[-1].rate is None:\n        self.log.warning(\"No funding rates received\")\n        return\n    self.position_adjust(rates[-1].rate)","handlingStrategy":"try-catch","validationCode":"assert callable(getattr(actor, 'on_historical_funding_rates', None)), \"actor must implement on_historical_funding_rates\"\n","typeGuard":"def has_funding_rates_handler(obj):\n    return callable(getattr(obj, 'on_historical_funding_rates', None))\n","tryCatchPattern":"try:\n    actor.on_historical_funding_rates(rates)\nexcept Exception as e:\n    log.error(f\"on_historical_funding_rates failed: {e}\", exc_info=True)\n","preventionTips":["Validate rate values (None/zero) before applying funding logic","Check for empty lists before indexing (e.g. rates[-1])","Implement the handler whenever request_funding_rates is used","Confirm FundingRateUpdate field names against the installed nautilus version"],"tags":["python","historical-data","funding-rate","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"}