Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Nautechsystems Nautilus trader DatabentoDataLoader From Dbn

From Leeroopedia


Field Value
Sources GitHub: adapters/databento/loaders.py, GitHub: adapters/tardis/loaders.py, NautilusTrader Documentation
Domains Market Data Ingestion, Databento, Tardis, Data Format Conversion
Last Updated 2026-02-10 12:00 GMT

Overview

Concrete tool for loading market data from Databento Binary Encoding (DBN) files and Tardis CSV files provided by NautilusTrader.

Description

The DatabentoDataLoader class decodes DBN-format files into NautilusTrader's canonical data types. It supports all major Databento schemas including MBO (order book deltas), MBP-1 (top-of-book quotes with optional trades), MBP-10 (depth-10 snapshots), TRADES, OHLCV bars at various intervals, instrument DEFINITION, STATUS, IMBALANCE, and STATISTICS. The loader delegates to a Rust-backed pyo3 implementation for high-performance deserialization and optionally converts results to legacy Cython objects for compatibility with the backtesting engine.

The TardisCSVDataLoader provides a complementary loader for Tardis-format CSV files (with optional GZip decompression), supporting order book deltas, depth-10 snapshots, quote ticks, trade ticks, and funding rate updates.

Usage

Import the loader when you need to:

  • Convert Databento DBN files into typed NautilusTrader data objects for backtesting or catalog ingestion.
  • Load Tardis CSV market data into the NautilusTrader type system.
  • Prepare historical data for writing to a ParquetDataCatalog.

Code Reference

Source Location

Item Value
File (Databento) nautilus_trader/adapters/databento/loaders.py
Lines (Databento) L31-431
Class (Databento) DatabentoDataLoader
File (Tardis) nautilus_trader/adapters/tardis/loaders.py
Lines (Tardis) L31-666
Class (Tardis) TardisCSVDataLoader

Signature (DatabentoDataLoader)

class DatabentoDataLoader:
    def __init__(
        self,
        venue_dataset_map: dict[str, str] | None = None,
    ) -> None: ...

    def from_dbn_file(
        self,
        path: PathLike[str] | str,
        instrument_id: InstrumentId | None = None,
        price_precision: int | None = None,
        as_legacy_cython: bool = True,
        include_trades: bool = False,
        use_exchange_as_venue: bool = False,
        bars_timestamp_on_close: bool = True,
    ) -> list[Data]: ...

Signature (TardisCSVDataLoader)

class TardisCSVDataLoader:
    def __init__(
        self,
        price_precision: int | None = None,
        size_precision: int | None = None,
        instrument_id: InstrumentId | None = None,
    ) -> None: ...

    def load_deltas(
        self,
        filepath: PathLike[str] | str,
        as_legacy_cython: bool = True,
        limit: int | None = None,
    ) -> list[OrderBookDelta]: ...

    def load_depth10(
        self,
        filepath: PathLike[str] | str,
        as_legacy_cython: bool = True,
        limit: int | None = None,
    ) -> list[OrderBookDepth10]: ...

    def load_quotes(
        self,
        filepath: PathLike[str] | str,
        as_legacy_cython: bool = True,
        limit: int | None = None,
    ) -> list[QuoteTick]: ...

    def load_trades(
        self,
        filepath: PathLike[str] | str,
        as_legacy_cython: bool = True,
        limit: int | None = None,
    ) -> list[TradeTick]: ...

Import

from nautilus_trader.adapters.databento.loaders import DatabentoDataLoader
from nautilus_trader.adapters.tardis.loaders import TardisCSVDataLoader

I/O Contract

Inputs (DatabentoDataLoader.from_dbn_file)

Parameter Type Default Description
path PathLike[str] ¦ str (required) Path to the DBN-encoded data file
instrument_id InstrumentId ¦ None None Override symbology for all records (optimization for single-instrument files)
price_precision int ¦ None None Override price precision if different from the default of 2 for USD
as_legacy_cython bool True Convert Rust pyo3 objects to legacy Cython objects; set False for catalog ingestion
include_trades bool False Include separate TradeTick elements for MBO and MBP-1 schemas
use_exchange_as_venue bool False Use actual exchange names for instrument IDs instead of GLBX
bars_timestamp_on_close bool True Set bar timestamps to close time (True) or open time (False)

Outputs

Vendor Schema Return Type Description
MBO list[OrderBookDelta] Order book delta events from message-by-order data
MBP_1 / TBBO list[QuoteTick] (+ optional TradeTick) Top-of-book quotes with optional trade events
MBP_10 list[OrderBookDepth10] Full depth-10 order book snapshots
BBO_1S / BBO_1M list[QuoteTick] Best-bid-offer snapshots at 1s or 1min intervals
TRADES list[TradeTick] Individual trade events
OHLCV_1S/1M/1H/1D list[Bar] OHLCV bar data at specified intervals
DEFINITION list[Instrument] Instrument definition records
STATUS list[InstrumentStatus] Instrument status change events
IMBALANCE list[DatabentoImbalance] Auction imbalance data (Rust-only, requires as_legacy_cython=False)
STATISTICS list[DatabentoStatistics] Exchange statistics (Rust-only, requires as_legacy_cython=False)

Usage Examples

Loading Databento Trade Data from a DBN File

from nautilus_trader.adapters.databento.loaders import DatabentoDataLoader

loader = DatabentoDataLoader()

# Load trades from a DBN file
trades = loader.from_dbn_file(
    path="data/AAPL_trades.dbn.zst",
    instrument_id=None,       # Let loader resolve symbology from file
    as_legacy_cython=True,    # Convert to Cython objects for backtest engine
)

print(f"Loaded {len(trades)} trade ticks")
print(trades[0])  # First TradeTick object

Loading Databento Quotes with Trades

from nautilus_trader.adapters.databento.loaders import DatabentoDataLoader
from nautilus_trader.model.identifiers import InstrumentId

loader = DatabentoDataLoader()

# Load MBP-1 data with both quotes and trades
data = loader.from_dbn_file(
    path="data/ESM4_mbp1.dbn.zst",
    instrument_id=InstrumentId.from_str("ESM4.GLBX"),
    include_trades=True,
)

# data will contain interleaved QuoteTick and TradeTick objects
quotes = [d for d in data if isinstance(d, QuoteTick)]
trades = [d for d in data if isinstance(d, TradeTick)]
print(f"Quotes: {len(quotes)}, Trades: {len(trades)}")

Loading for Catalog Ingestion (Rust pyo3 Objects)

from nautilus_trader.adapters.databento.loaders import DatabentoDataLoader

loader = DatabentoDataLoader()

# Load as pyo3 objects for writing to catalog
data = loader.from_dbn_file(
    path="data/BTCUSDT_ohlcv_1h.dbn.zst",
    as_legacy_cython=False,  # Keep as pyo3 objects for catalog write
)

Loading Tardis CSV Trade Data

from nautilus_trader.adapters.tardis.loaders import TardisCSVDataLoader
from nautilus_trader.model.identifiers import InstrumentId

loader = TardisCSVDataLoader(
    instrument_id=InstrumentId.from_str("BTCUSDT-PERP.BINANCE"),
)

# Load trades from a Tardis CSV (supports .gz files)
trades = loader.load_trades(
    filepath="data/binance_btcusdt_trades.csv.gz",
    as_legacy_cython=True,
)

print(f"Loaded {len(trades)} trade ticks from Tardis")

Using a Venue-Dataset Map

from nautilus_trader.adapters.databento.loaders import DatabentoDataLoader

# Map venue names to Databento dataset identifiers
loader = DatabentoDataLoader(
    venue_dataset_map={
        "GLBX": "GLBX.MDP3",
        "XNAS": "XNAS.ITCH",
    },
)

dataset = loader.get_dataset_for_venue(Venue("GLBX"))
print(dataset)  # "GLBX.MDP3"

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment