nautechsystems/nautilus_trader · error

Python on_historical_funding_rates failed: {e}

Error message

Python on_historical_funding_rates failed: {e}

What it means

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}`.

Source

Thrown at crates/common/src/python/actor.rs:1241

            .map_err(|e| anyhow::anyhow!("Python on_historical_book_depth failed: {e}"))
    }

    fn on_historical_quotes(&mut self, quotes: &[QuoteTick]) -> anyhow::Result<()> {
        self.dispatch_on_historical_quotes(quotes.to_vec())
            .map_err(|e| anyhow::anyhow!("Python on_historical_quotes failed: {e}"))
    }

    fn on_historical_trades(&mut self, trades: &[TradeTick]) -> anyhow::Result<()> {
        self.dispatch_on_historical_trades(trades.to_vec())
            .map_err(|e| anyhow::anyhow!("Python on_historical_trades failed: {e}"))
    }

    fn on_historical_funding_rates(
        &mut self,
        funding_rates: &[FundingRateUpdate],
    ) -> anyhow::Result<()> {
        self.dispatch_on_historical_funding_rates(funding_rates.to_vec())
            .map_err(|e| anyhow::anyhow!("Python on_historical_funding_rates failed: {e}"))
    }

    fn on_historical_bars(&mut self, bars: &[Bar]) -> anyhow::Result<()> {
        self.dispatch_on_historical_bars(bars.to_vec())
            .map_err(|e| anyhow::anyhow!("Python on_historical_bars failed: {e}"))
    }

    fn on_historical_mark_prices(&mut self, mark_prices: &[MarkPriceUpdate]) -> anyhow::Result<()> {
        self.dispatch_on_historical_mark_prices(mark_prices.to_vec())
            .map_err(|e| anyhow::anyhow!("Python on_historical_mark_prices failed: {e}"))
    }

    fn on_historical_index_prices(
        &mut self,
        index_prices: &[IndexPriceUpdate],
    ) -> anyhow::Result<()> {
        self.dispatch_on_historical_index_prices(index_prices.to_vec())
            .map_err(|e| anyhow::anyhow!("Python on_historical_index_prices failed: {e}"))

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Inspect the wrapped `{e}` cause for the original Python exception and fix `on_historical_funding_rates`.
  2. Implement `on_historical_funding_rates(self, funding_rates)` on the Python actor when requesting funding rates.
  3. Validate rate values (None/zero/negative) inside the handler before applying funding logic.
  4. Check FundingRateUpdate field access against your installed nautilus version.

Example fix

# before
def on_historical_funding_rates(self, rates):
    self.position_adjust(rates[-1].rate)  # IndexError on empty list

# after
def on_historical_funding_rates(self, rates):
    if not rates or rates[-1].rate is None:
        self.log.warning("No funding rates received")
        return
    self.position_adjust(rates[-1].rate)
Defensive patterns

Strategy: try-catch

Validate before calling

assert callable(getattr(actor, 'on_historical_funding_rates', None)), "actor must implement on_historical_funding_rates"

Type guard

def has_funding_rates_handler(obj):
    return callable(getattr(obj, 'on_historical_funding_rates', None))

Try / catch

try:
    actor.on_historical_funding_rates(rates)
except Exception as e:
    log.error(f"on_historical_funding_rates failed: {e}", exc_info=True)

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/aa61142eec6eeb90. Report an issue: GitHub.