nautechsystems/nautilus_trader · error
Python on_historical_data failed: {e}
Error message
Python on_historical_data failed: {e} What it means
Raised by `DataActor::on_historical_data` (crates/common/src/python/actor.rs:1212) when converting arbitrary historical data to a Python object or dispatching it to the actor's `on_historical_data` callback fails. Unlike the typed handlers, this path first tries downcasting to `CustomData`/`Vec<CustomData>` and explicitly bails with 'Failed to convert historical data to Python: unsupported type' for anything else; any Python exception in the callback is also wrapped as `Python on_historical_data failed: {e}`.
Source
Thrown at crates/common/src/python/actor.rs:1212
}
#[cfg(feature = "defi")]
fn on_pool_flash(&mut self, flash: &PoolFlash) -> anyhow::Result<()> {
self.dispatch_on_pool_flash(flash.clone())
.map_err(|e| anyhow::anyhow!("Python on_pool_flash failed: {e}"))
}
fn on_historical_data(&mut self, data: &dyn Any) -> anyhow::Result<()> {
Python::attach(|py| {
let py_data: Py<PyAny> = if let Some(custom_data) = data.downcast_ref::<CustomData>() {
Py::new(py, custom_data.clone())?.into_any()
} else if let Some(custom_data) = data.downcast_ref::<Vec<CustomData>>() {
custom_data.clone().into_py_any(py)?
} else {
anyhow::bail!("Failed to convert historical data to Python: unsupported type");
};
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}"))
}
View on GitHub (pinned to 18893faf8b)
Solutions
- Read the wrapped `{e}`; if it is 'unsupported type', register your data type with the data catalog/type registry so it round-trips as CustomData.
- Ensure custom data classes are decorated as pyo3-compatible pyclasses (NautilusCustomData/CustomData) and implement the required conversion methods.
- Request historical data using concrete supported types (bars, quotes, trades) instead of pushing arbitrary Rust objects through the generic historical-data path.
- Fix any exception raised inside the Python `on_historical_data` handler shown in the traceback.
Example fix
# before: unregistered Rust struct pushed as historical data
actor.request_data(MyRustSnapshot {}) # -> unsupported type
# after: use a registered custom data type
from nautilus_trader.model.custom import CustomData
class MySnapshot(CustomData):
...
actor.request_data(MySnapshot(...)) Defensive patterns
Strategy: validation
Validate before calling
# before requesting, confirm the type is registered/convertible
if not issubclass(MyData, CustomData):
raise TypeError("historical data must be a registered CustomData type")
Type guard
def is_convertible_historical_data(data):
return isinstance(data, (CustomData, list)) and all(isinstance(d, CustomData) for d in data) if isinstance(data, list) else isinstance(data, CustomData)
Try / catch
try:
actor.on_historical_data(data)
except Exception as e:
log.error(f"on_historical_data failed: {e}", exc_info=True) # 'unsupported type' means register the data type
Prevention
- Register custom data types with the data catalog/type registry before requesting them
- Use concrete supported types (bars/quotes/trades) instead of pushing arbitrary objects through the generic path
- Make custom data classes proper pyo3-compatible pyclasses
- Read the chained cause: 'unsupported type' always points to registration, not handler bugs
When it happens
Trigger: Fires when historical data that is neither `CustomData` nor `Vec<CustomData>` (and not otherwise matched upstream) reaches `on_historical_data`, causing the anyhow bail; or when the Python `on_historical_data` callback raises; or when `Py::new`/`into_py_any` conversion of CustomData fails.
Common situations: Requesting historical data of a type not registered as CustomData (custom catalog data not registered with the type registry); passing Rust-native types through the generic path; handler code assuming a specific data shape; a CustomData pyclass lacking proper clone/conversion support.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Failed to convert historical data to Python: unsupported typ
- Failed to convert instrument to Python: {e}
- Failed to convert InstrumentAny to Python: {e}
- Failed to convert historical data to Python: unsupported typ
- Hyperliquid does not provide historical quotes via HTTP API
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/8d3369c65c112dcc.
Report an issue: GitHub.