nautechsystems/nautilus_trader · error

Python on_historical_quotes failed: {e}

Error message

Python on_historical_quotes failed: {e}

What it means

Raised by `DataActor::on_historical_quotes` (crates/common/src/python/actor.rs:1228) when dispatching a slice of `QuoteTick` historical data to the Python actor's `on_historical_quotes` callback fails. The dispatch clones the quotes into a Vec and calls the Python method via pyo3; a Python exception inside the handler, a missing method, or quote-to-Python conversion failure is reported as `Python on_historical_quotes failed: {e}`.

Source

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

            };
            self.dispatch_on_historical_data(py_data)
                .map_err(|e| anyhow::anyhow!("Python on_historical_data failed: {e}"))
        })
    }

    fn on_historical_book_deltas(&mut self, deltas: &[OrderBookDelta]) -> anyhow::Result<()> {
        self.dispatch_on_historical_book_deltas(deltas.to_vec())
            .map_err(|e| anyhow::anyhow!("Python on_historical_book_deltas failed: {e}"))
    }

    fn on_historical_book_depth(&mut self, depths: &[OrderBookDepth10]) -> anyhow::Result<()> {
        self.dispatch_on_historical_book_depth(depths.to_vec())
            .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}"))

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Inspect the embedded `{e}` cause (Python traceback) and fix the failing `on_historical_quotes` handler code.
  2. Implement `on_historical_quotes(self, quotes)` on the Python actor if quotes are requested.
  3. Guard against empty quote lists before processing (e.g. computing mid from the first quote).
  4. Verify quote field access (bid/ask/bid_size/ask_size) matches your installed nautilus version.

Example fix

# before
def on_historical_quotes(self, quotes):
    mid = (quotes[0].bid_price + quotes[0].ask_price) / 2  # IndexError on empty

# after
def on_historical_quotes(self, quotes):
    if not quotes:
        self.log.warning("No historical quotes received")
        return
    mid = (quotes[0].bid_price + quotes[0].ask_price) / 2
Defensive patterns

Strategy: try-catch

Validate before calling

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

Type guard

def has_quotes_handler(obj):
    return callable(getattr(obj, 'on_historical_quotes', None))

Try / catch

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

Prevention

When it happens

Trigger: Occurs when historical quote ticks are delivered (e.g. result of `request_quotes`) and the Python `on_historical_quotes` callback raises, the Python object lacks the method, or the quotes fail to convert to Python objects.

Common situations: Handler code doing pandas conversions that raise on empty lists or unexpected fields; strategies that request historical quotes without implementing the handler; mixing up on_historical_quotes vs on_quote_tick; version drift in QuoteTick 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/5c87e2604ee48c2c. Report an issue: GitHub.