Databento¶
Databento market data integration adapter.
This subpackage provides a data client factory, instrument provider, constants, configurations, and data loaders for connecting to and interacting with the Databento API, and decoding Databento Binary Encoding (DBN) format data.
For convenience, the most commonly used symbols are re-exported at the
subpackage’s top level, so downstream code can simply import from
nautilus_trader.adapters.databento.
- class DatabentoDataClientConfig¶
Bases:
LiveDataClientConfigConfiguration for
DatabentoDataClientinstances.- Parameters:
api_key (str, optional) – The Databento API secret key. If
Nonethen will source the DATABENTO_API_KEY environment variable.http_gateway (str, optional) – The historical HTTP client gateway override.
live_gateway (str, optional) – The live client gateway override.
use_exchange_as_venue (bool, default True) – If the exchange field will be used as the venue for instrument IDs.
timeout_initial_load (float, default 15.0) – The timeout (seconds) to wait for instruments to load (concurrently per dataset).
mbo_subscriptions_delay (float, default 3.0) – The timeout (seconds) to wait for MBO/L3 subscriptions (concurrently per dataset). After the timeout the MBO order book feed will start and replay messages from the initial snapshot and then all deltas.
bars_timestamp_on_close (bool, default True) – If bar data should be timestamped on the close (True) or open (False) of the bar period. When True, both ts_event and ts_init are set to the bar close time. When False, both ts_event and ts_init are set to the bar open time.
parent_symbols (dict[str, set[str]], optional) – The Databento parent symbols to subscribe to instrument definitions for on start. This is a map of Databento dataset keys -> to a sequence of the parent symbols, e.g. {‘GLBX.MDP3’, [‘ES.FUT’, ‘ES.OPT’]} (for all E-mini S&P 500 futures and options products).
instrument_ids (list[InstrumentId], optional) – The instrument IDs to request instrument definitions for on start.
venue_dataset_map (dict[str, str], optional) – A dictionary to override the default dataset used for a venue.
reconnect_timeout_mins (int, optional, default 10) – The timeout (minutes) for reconnection attempts when the live connection is lost. Set to
Noneto retry indefinitely (use with caution - see documentation). The client uses rapid initial retries followed by exponential backoff. See the Connection Stability section in the Databento integration guide for details.
- api_key: str | None¶
- http_gateway: str | None¶
- live_gateway: str | None¶
- use_exchange_as_venue: bool¶
- timeout_initial_load: float | None¶
- mbo_subscriptions_delay: float | None¶
- bars_timestamp_on_close: bool¶
- instrument_ids: list[InstrumentId] | None¶
- parent_symbols: dict[str, set[str]] | None¶
- venue_dataset_map: dict[str, str] | None¶
- reconnect_timeout_mins: int | None¶
- dict() dict[str, Any]¶
Return a dictionary representation of the configuration.
- Return type:
dict[str, Any]
- classmethod fully_qualified_name() str¶
Return the fully qualified name for the NautilusConfig class.
- Return type:
str
References
- handle_revised_bars: bool¶
- property id: str¶
Return the hashed identifier for the configuration.
- Return type:
str
- instrument_provider: InstrumentProviderConfig¶
- json() bytes¶
Return serialized JSON encoded bytes.
- Return type:
bytes
- json_primitives() dict[str, Any]¶
Return a dictionary representation of the configuration with JSON primitive types as values.
- Return type:
dict[str, Any]
- classmethod json_schema() dict[str, Any]¶
Generate a JSON schema for this configuration class.
- Return type:
dict[str, Any]
- classmethod parse(raw: bytes | str) Any¶
Return a decoded object of the given cls.
- Parameters:
cls (type) – The type to decode to.
raw (bytes or str) – The raw bytes or JSON string to decode.
- Return type:
Any
- routing: RoutingConfig¶
- validate() bool¶
Return whether the configuration can be represented as valid JSON.
- Return type:
bool
- class DatabentoDataLoader¶
Bases:
objectProvides a data loader for Databento Binary Encoding (DBN) format data.
- Supported schemas:
MBO -> OrderBookDelta
MBP_1 -> (QuoteTick, TradeTick | None)
MBP_10 -> OrderBookDepth10
BBO_1S -> QuoteTick
BBO_1M -> QuoteTick
TBBO -> (QuoteTick, TradeTick)
TRADES -> TradeTick
OHLCV_1S -> Bar
OHLCV_1M -> Bar
OHLCV_1H -> Bar
OHLCV_1D -> Bar
DEFINITION -> Instrument
IMBALANCE -> DatabentoImbalance
STATISTICS -> DatabentoStatistics
STATUS -> InstrumentStatus
- load_publishers(path: PathLike[str] | str) None¶
Load publisher details from the JSON file at the given path.
- Parameters:
path (PathLike[str] | str) – The path for the publishers data to load.
- get_publishers() dict[int, DatabentoPublisher]¶
Return the internal Databento publishers currently held by the loader.
- Return type:
dict[int, DatabentoPublisher]
- get_dataset_for_venue(venue: Venue) str¶
Return a dataset for the given venue.
- Parameters:
venue (Venue) – The venue for the given dataset.
- Return type:
str
- Raises:
ValueError – If venue is not in the map of publishers.
- from_dbn_file(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, skip_on_error: bool = False) list[Data]¶
Return a list of data objects decoded from the DBN file at the given path.
- Parameters:
path (PathLike[str] | str) – The path for the DBN data file.
instrument_id (InstrumentId, optional) – The Nautilus instrument ID for the data. This parameter optimizes performance by overriding the symbology of all records with the specified Nautilus identifier. Use this only if the instrument ID is definitively known (e.g., all records in the file are guaranteed to be for the same instrument).
price_precision (int, optional) – The price precision, if different to the default of 2 for USD. Use this option only if the default precision is problematic The specified precision will apply to all records read by this call.
as_legacy_cython (bool, default True) – If data should be converted to ‘legacy Cython’ objects. You would typically only set this False if passing the objects directly to a data catalog for the data to then be written in Nautilus Parquet format. Note: the imbalance and statistics schemas are only implemented in Rust, and so cannot be loaded as legacy Cython objects (so set this to False).
include_trades (bool, default False) – If separate TradeTick elements will be included in the data for MBO and MBP-1 schemas when applicable (your code will have to handle these two types in the returned list).
use_exchange_as_venue (bool, default False) – Whether to use actual exchanges for instrument ids or GLBX.
bars_timestamp_on_close (bool, default True) – If bar timestamps should be set to close time (True) or open time (False).
skip_on_error (bool, default False) – If True, instruments that fail to decode are skipped with a warning log. If False (default), any decode error is raised as an exception.
- Return type:
list[Data] | list[pyo3.DatabentoImbalance] | list[pyo3.DatabentoStatistics]
- Raises:
ValueError – If there is an error during decoding.
ValueError – If as_legacy_cython is True when schema is imbalance or statistics.
RuntimeError – If a feature is not currently supported.
- class DatabentoImbalance¶
Bases:
objectRepresents an auction imbalance.
This data type includes the populated data fields provided by Databento, excluding publisher_id and instrument_id.
- auct_interest_clr_price¶
- cont_book_clr_price¶
- static from_dict(values)¶
- instrument_id¶
- paired_qty¶
- ref_price¶
- side¶
- significant_imbalance¶
- to_dict()¶
# Errors
Returns a PyErr if generating the Python dictionary fails.
- total_imbalance_qty¶
- ts_event¶
- ts_init¶
- ts_recv¶
- class DatabentoInstrumentProvider¶
Bases:
InstrumentProviderProvides a means of loading Instrument objects from Databento.
- Parameters:
http_client (nautilus_pyo3.DatabentoHistoricalClient) – The Databento historical HTTP client for the provider.
clock (LiveClock) – The clock for the provider.
live_api_key (str, optional) – The specific API secret key for Databento live clients. If not provided then will use the historical HTTP client API key.
live_gateway (str, optional) – The live gateway override for Databento live clients.
loader (DatabentoDataLoader, optional) – The loader for the provider.
config (InstrumentProviderConfig, optional) – The configuration for the provider.
- async load_all_async(filters: dict | None = None) None¶
Load the latest instruments into the provider asynchronously, optionally applying the given filters.
- async load_ids_async(instrument_ids: list[InstrumentId], filters: dict | None = None) None¶
Load the latest instrument definitions for the given instrument IDs into the provider by requesting the latest instrument definition messages from Databento.
You must only request instrument definitions from one dataset at a time. The Databento dataset will be determined from either the filters, or the venues for the instrument IDs.
- Parameters:
instrument_ids (list[InstrumentId]) – The instrument IDs to load.
filters (dict, optional) – The optional filters for the instrument definition request.
- Raises:
ValueError – If all venues in instrument_ids are not equal.
Warning
Calling this method will incur a cost to your Databento account in USD.
- async load_async(instrument_id: InstrumentId, filters: dict | None = None) None¶
Load the instrument for the given ID into the provider asynchronously, optionally applying the given filters.
The default implementation delegates to
load_ids_async. Subclasses with per-instrument fetch capability should override this method.- Parameters:
instrument_id (InstrumentId) – The instrument ID to load.
filters (frozendict[str, Any] or dict[str, Any], optional) – The venue specific instrument loading filters to apply.
- async get_range(instrument_ids: list[InstrumentId], start: Timestamp | date | str | int, end: Timestamp | date | str | int | None = None, filters: dict | None = None) list[Instrument]¶
Request a time series of instrument definitions for the given instrument IDs by making a /timeseries.get_range(…) request from Databento.
- Parameters:
instrument_ids (list[InstrumentId]) – The instrument IDs for the request.
start (pd.Timestamp or date or str or int) – The start datetime of the request time range (inclusive). Assumes UTC as timezone unless passed a tz-aware object. If an integer is passed, then this represents nanoseconds since the UNIX epoch.
end (pd.Timestamp or date or str or int, optional) – The end datetime of the request time range (exclusive). Assumes UTC as timezone unless passed a tz-aware object. If an integer is passed, then this represents nanoseconds since the UNIX epoch. Values are forward-filled based on the resolution provided. Defaults to the same value as start.
filters (dict, optional) – The optional filters for the instrument definition request.
Warning
Calling this method will incur a cost to your Databento account in USD.
- add(instrument: Instrument) None¶
Add the given instrument to the provider.
- Parameters:
instrument (Instrument) – The instrument to add.
- add_bulk(instruments: list[Instrument]) None¶
Add the given instruments bulk to the provider.
- Parameters:
instruments (list[Instrument]) – The instruments to add.
- add_currency(currency: Currency) None¶
Add the given currency to the provider.
- Parameters:
currency (Currency) – The currency to add.
- property count: int¶
Return the count of instruments held by the provider.
- Return type:
int
- currencies() dict[str, Currency]¶
Return all currencies held by the instrument provider.
- Return type:
dict[str, Currency]
- currency(code: str) Currency | None¶
Return the currency with the given code (if found).
- Parameters:
code (str) – The currency code.
- Return type:
Currency or
None- Raises:
ValueError – If code is not a valid string.
- find(instrument_id: InstrumentId) Instrument | None¶
Return the instrument for the given instrument ID (if found).
- Parameters:
instrument_id (InstrumentId) – The ID for the instrument
- Return type:
Instrument or
None
- get_all() dict[InstrumentId, Instrument]¶
Return all loaded instruments as a map keyed by instrument ID.
If no instruments loaded, will return an empty dict.
- Return type:
dict[InstrumentId, Instrument]
- async initialize(reload: bool = False) None¶
Initialize the instrument provider.
- Parameters:
reload (bool, default False) – If True, then will always reload instruments. If False, then will immediately return if already loaded.
- list_all() list[Instrument]¶
Return all loaded instruments.
- Return type:
list[Instrument]
- load(instrument_id: InstrumentId, filters: dict | None = None) None¶
Load the instrument for the given ID into the provider, optionally applying the given filters.
- Parameters:
instrument_id (InstrumentId) – The instrument ID to load.
filters (frozendict[str, Any] or dict[str, Any], optional) – The venue specific instrument loading filters to apply.
- load_all(filters: dict | None = None) None¶
Load the latest instruments into the provider, optionally applying the given filters.
- Parameters:
filters (frozendict[str, Any] or dict[str, Any], optional) – The venue specific instrument loading filters to apply.
- load_ids(instrument_ids: list[InstrumentId], filters: dict | None = None) None¶
Load the instruments for the given IDs into the provider, optionally applying the given filters.
- Parameters:
instrument_ids (list[InstrumentId]) – The instrument IDs to load.
filters (frozendict[str, Any] or dict[str, Any], optional) – The venue specific instrument loading filters to apply.
- class DatabentoLiveDataClientFactory¶
Bases:
LiveDataClientFactoryProvides a Binance live data client factory.
- static create(loop: AbstractEventLoop, name: str, config: DatabentoDataClientConfig, msgbus: MessageBus, cache: Cache, clock: LiveClock) DatabentoDataClient¶
Create a new Databento data client.
- Parameters:
loop (asyncio.AbstractEventLoop) – The event loop for the client.
name (str) – The custom client name.
config (DatabentoDataClientConfig) – The client configuration.
msgbus (MessageBus) – The message bus for the client.
cache (Cache) – The cache for the client.
clock (LiveClock) – The clock for the client.
- Return type:
- class DatabentoStatistics¶
Bases:
objectRepresents a market statistics snapshot.
This data type includes the populated data fields provided by Databento, excluding publisher_id and instrument_id.
- channel_id¶
- static from_dict(values)¶
- instrument_id¶
- price¶
- quantity¶
- sequence¶
- stat_flags¶
- stat_type¶
- to_dict()¶
# Errors
Returns a PyErr if generating the Python dictionary fails.
- ts_event¶
- ts_in_delta¶
- ts_init¶
- ts_recv¶
- ts_ref¶
- update_action¶
- get_cached_databento_http_client(key: str | None = None, gateway: str | None = None, use_exchange_as_venue: bool = True) DatabentoHistoricalClient¶
Cache and return a Databento historical HTTP client with the given key and gateway.
If a cached client with matching parameters already exists, the cached client will be returned.
- Parameters:
key (str, optional) – The Databento API secret key for the client.
gateway (str, optional) – The Databento historical HTTP client gateway override.
use_exchange_as_venue (bool, default True) – If the exchange field will be used as the venue for instrument IDs.
- Return type:
nautilus_pyo3.DatabentoHistoricalClient
- get_cached_databento_instrument_provider(http_client: DatabentoHistoricalClient, clock: LiveClock, live_api_key: str | None = None, live_gateway: str | None = None, loader: DatabentoDataLoader | None = None, config: InstrumentProviderConfig | None = None, use_exchange_as_venue=True) DatabentoInstrumentProvider¶
Cache and return a Databento instrument provider.
If a cached provider already exists, then that provider will be returned.
- Parameters:
http_client (nautilus_pyo3.DatabentoHistoricalClient) – The client for the instrument provider.
clock (LiveClock) – The clock for the instrument provider.
live_api_key (str, optional) – The specific API secret key for Databento live clients. If not provided then will use the historical HTTP client API key.
live_gateway (str, optional) – The live gateway override for Databento live clients.
loader (DatabentoDataLoader, optional) – The loader for the provider.
config (InstrumentProviderConfig) – The configuration for the instrument provider.
use_exchange_as_venue (bool, default True) – If the exchange field will be used as the venue for instrument IDs.
- Return type:
Config¶
- class DatabentoDataClientConfig¶
Bases:
LiveDataClientConfigConfiguration for
DatabentoDataClientinstances.- Parameters:
api_key (str, optional) – The Databento API secret key. If
Nonethen will source the DATABENTO_API_KEY environment variable.http_gateway (str, optional) – The historical HTTP client gateway override.
live_gateway (str, optional) – The live client gateway override.
use_exchange_as_venue (bool, default True) – If the exchange field will be used as the venue for instrument IDs.
timeout_initial_load (float, default 15.0) – The timeout (seconds) to wait for instruments to load (concurrently per dataset).
mbo_subscriptions_delay (float, default 3.0) – The timeout (seconds) to wait for MBO/L3 subscriptions (concurrently per dataset). After the timeout the MBO order book feed will start and replay messages from the initial snapshot and then all deltas.
bars_timestamp_on_close (bool, default True) – If bar data should be timestamped on the close (True) or open (False) of the bar period. When True, both ts_event and ts_init are set to the bar close time. When False, both ts_event and ts_init are set to the bar open time.
parent_symbols (dict[str, set[str]], optional) – The Databento parent symbols to subscribe to instrument definitions for on start. This is a map of Databento dataset keys -> to a sequence of the parent symbols, e.g. {‘GLBX.MDP3’, [‘ES.FUT’, ‘ES.OPT’]} (for all E-mini S&P 500 futures and options products).
instrument_ids (list[InstrumentId], optional) – The instrument IDs to request instrument definitions for on start.
venue_dataset_map (dict[str, str], optional) – A dictionary to override the default dataset used for a venue.
reconnect_timeout_mins (int, optional, default 10) – The timeout (minutes) for reconnection attempts when the live connection is lost. Set to
Noneto retry indefinitely (use with caution - see documentation). The client uses rapid initial retries followed by exponential backoff. See the Connection Stability section in the Databento integration guide for details.
- api_key: str | None¶
- http_gateway: str | None¶
- live_gateway: str | None¶
- use_exchange_as_venue: bool¶
- timeout_initial_load: float | None¶
- mbo_subscriptions_delay: float | None¶
- bars_timestamp_on_close: bool¶
- instrument_ids: list[InstrumentId] | None¶
- parent_symbols: dict[str, set[str]] | None¶
- venue_dataset_map: dict[str, str] | None¶
- reconnect_timeout_mins: int | None¶
- dict() dict[str, Any]¶
Return a dictionary representation of the configuration.
- Return type:
dict[str, Any]
- classmethod fully_qualified_name() str¶
Return the fully qualified name for the NautilusConfig class.
- Return type:
str
References
- handle_revised_bars: bool¶
- property id: str¶
Return the hashed identifier for the configuration.
- Return type:
str
- instrument_provider: InstrumentProviderConfig¶
- json() bytes¶
Return serialized JSON encoded bytes.
- Return type:
bytes
- json_primitives() dict[str, Any]¶
Return a dictionary representation of the configuration with JSON primitive types as values.
- Return type:
dict[str, Any]
- classmethod json_schema() dict[str, Any]¶
Generate a JSON schema for this configuration class.
- Return type:
dict[str, Any]
- classmethod parse(raw: bytes | str) Any¶
Return a decoded object of the given cls.
- Parameters:
cls (type) – The type to decode to.
raw (bytes or str) – The raw bytes or JSON string to decode.
- Return type:
Any
- routing: RoutingConfig¶
- validate() bool¶
Return whether the configuration can be represented as valid JSON.
- Return type:
bool
Factories¶
- get_cached_databento_http_client(key: str | None = None, gateway: str | None = None, use_exchange_as_venue: bool = True) DatabentoHistoricalClient¶
Cache and return a Databento historical HTTP client with the given key and gateway.
If a cached client with matching parameters already exists, the cached client will be returned.
- Parameters:
key (str, optional) – The Databento API secret key for the client.
gateway (str, optional) – The Databento historical HTTP client gateway override.
use_exchange_as_venue (bool, default True) – If the exchange field will be used as the venue for instrument IDs.
- Return type:
nautilus_pyo3.DatabentoHistoricalClient
- get_cached_databento_instrument_provider(http_client: DatabentoHistoricalClient, clock: LiveClock, live_api_key: str | None = None, live_gateway: str | None = None, loader: DatabentoDataLoader | None = None, config: InstrumentProviderConfig | None = None, use_exchange_as_venue=True) DatabentoInstrumentProvider¶
Cache and return a Databento instrument provider.
If a cached provider already exists, then that provider will be returned.
- Parameters:
http_client (nautilus_pyo3.DatabentoHistoricalClient) – The client for the instrument provider.
clock (LiveClock) – The clock for the instrument provider.
live_api_key (str, optional) – The specific API secret key for Databento live clients. If not provided then will use the historical HTTP client API key.
live_gateway (str, optional) – The live gateway override for Databento live clients.
loader (DatabentoDataLoader, optional) – The loader for the provider.
config (InstrumentProviderConfig) – The configuration for the instrument provider.
use_exchange_as_venue (bool, default True) – If the exchange field will be used as the venue for instrument IDs.
- Return type:
- class DatabentoLiveDataClientFactory¶
Bases:
LiveDataClientFactoryProvides a Binance live data client factory.
- static create(loop: AbstractEventLoop, name: str, config: DatabentoDataClientConfig, msgbus: MessageBus, cache: Cache, clock: LiveClock) DatabentoDataClient¶
Create a new Databento data client.
- Parameters:
loop (asyncio.AbstractEventLoop) – The event loop for the client.
name (str) – The custom client name.
config (DatabentoDataClientConfig) – The client configuration.
msgbus (MessageBus) – The message bus for the client.
cache (Cache) – The cache for the client.
clock (LiveClock) – The clock for the client.
- Return type:
Enums¶
- class DatabentoSchema¶
Bases:
EnumRepresents a Databento schema.
- MBO = 'mbo'¶
- MBP_1 = 'mbp-1'¶
- MBP_10 = 'mbp-10'¶
- BBO_1S = 'bbo-1s'¶
- BBO_1M = 'bbo-1m'¶
- CMBP_1 = 'cmbp-1'¶
- CBBO_1S = 'cbbo-1s'¶
- CBBO_1M = 'cbbo-1m'¶
- TCBBO = 'tcbbo'¶
- TBBO = 'tbbo'¶
- TRADES = 'trades'¶
- OHLCV_1S = 'ohlcv-1s'¶
- OHLCV_1M = 'ohlcv-1m'¶
- OHLCV_1H = 'ohlcv-1h'¶
- OHLCV_1D = 'ohlcv-1d'¶
- OHLCV_EOD = 'ohlcv-eod'¶
- DEFINITION = 'definition'¶
- IMBALANCE = 'imbalance'¶
- STATISTICS = 'statistics'¶
- STATUS = 'status'¶
Types¶
- class DatabentoImbalance¶
Bases:
objectRepresents an auction imbalance.
This data type includes the populated data fields provided by Databento, excluding publisher_id and instrument_id.
- auct_interest_clr_price¶
- cont_book_clr_price¶
- static from_dict(values)¶
- instrument_id¶
- paired_qty¶
- ref_price¶
- side¶
- significant_imbalance¶
- to_dict()¶
# Errors
Returns a PyErr if generating the Python dictionary fails.
- total_imbalance_qty¶
- ts_event¶
- ts_init¶
- ts_recv¶
- class DatabentoStatistics¶
Bases:
objectRepresents a market statistics snapshot.
This data type includes the populated data fields provided by Databento, excluding publisher_id and instrument_id.
- channel_id¶
- static from_dict(values)¶
- instrument_id¶
- price¶
- quantity¶
- sequence¶
- stat_flags¶
- stat_type¶
- to_dict()¶
# Errors
Returns a PyErr if generating the Python dictionary fails.
- ts_event¶
- ts_in_delta¶
- ts_init¶
- ts_recv¶
- ts_ref¶
- update_action¶
Loaders¶
- class DatabentoDataLoader¶
Bases:
objectProvides a data loader for Databento Binary Encoding (DBN) format data.
- Supported schemas:
MBO -> OrderBookDelta
MBP_1 -> (QuoteTick, TradeTick | None)
MBP_10 -> OrderBookDepth10
BBO_1S -> QuoteTick
BBO_1M -> QuoteTick
TBBO -> (QuoteTick, TradeTick)
TRADES -> TradeTick
OHLCV_1S -> Bar
OHLCV_1M -> Bar
OHLCV_1H -> Bar
OHLCV_1D -> Bar
DEFINITION -> Instrument
IMBALANCE -> DatabentoImbalance
STATISTICS -> DatabentoStatistics
STATUS -> InstrumentStatus
- load_publishers(path: PathLike[str] | str) None¶
Load publisher details from the JSON file at the given path.
- Parameters:
path (PathLike[str] | str) – The path for the publishers data to load.
- get_publishers() dict[int, DatabentoPublisher]¶
Return the internal Databento publishers currently held by the loader.
- Return type:
dict[int, DatabentoPublisher]
- get_dataset_for_venue(venue: Venue) str¶
Return a dataset for the given venue.
- Parameters:
venue (Venue) – The venue for the given dataset.
- Return type:
str
- Raises:
ValueError – If venue is not in the map of publishers.
- from_dbn_file(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, skip_on_error: bool = False) list[Data]¶
Return a list of data objects decoded from the DBN file at the given path.
- Parameters:
path (PathLike[str] | str) – The path for the DBN data file.
instrument_id (InstrumentId, optional) – The Nautilus instrument ID for the data. This parameter optimizes performance by overriding the symbology of all records with the specified Nautilus identifier. Use this only if the instrument ID is definitively known (e.g., all records in the file are guaranteed to be for the same instrument).
price_precision (int, optional) – The price precision, if different to the default of 2 for USD. Use this option only if the default precision is problematic The specified precision will apply to all records read by this call.
as_legacy_cython (bool, default True) – If data should be converted to ‘legacy Cython’ objects. You would typically only set this False if passing the objects directly to a data catalog for the data to then be written in Nautilus Parquet format. Note: the imbalance and statistics schemas are only implemented in Rust, and so cannot be loaded as legacy Cython objects (so set this to False).
include_trades (bool, default False) – If separate TradeTick elements will be included in the data for MBO and MBP-1 schemas when applicable (your code will have to handle these two types in the returned list).
use_exchange_as_venue (bool, default False) – Whether to use actual exchanges for instrument ids or GLBX.
bars_timestamp_on_close (bool, default True) – If bar timestamps should be set to close time (True) or open time (False).
skip_on_error (bool, default False) – If True, instruments that fail to decode are skipped with a warning log. If False (default), any decode error is raised as an exception.
- Return type:
list[Data] | list[pyo3.DatabentoImbalance] | list[pyo3.DatabentoStatistics]
- Raises:
ValueError – If there is an error during decoding.
ValueError – If as_legacy_cython is True when schema is imbalance or statistics.
RuntimeError – If a feature is not currently supported.
Providers¶
- class DatabentoInstrumentProvider¶
Bases:
InstrumentProviderProvides a means of loading Instrument objects from Databento.
- Parameters:
http_client (nautilus_pyo3.DatabentoHistoricalClient) – The Databento historical HTTP client for the provider.
clock (LiveClock) – The clock for the provider.
live_api_key (str, optional) – The specific API secret key for Databento live clients. If not provided then will use the historical HTTP client API key.
live_gateway (str, optional) – The live gateway override for Databento live clients.
loader (DatabentoDataLoader, optional) – The loader for the provider.
config (InstrumentProviderConfig, optional) – The configuration for the provider.
- async load_all_async(filters: dict | None = None) None¶
Load the latest instruments into the provider asynchronously, optionally applying the given filters.
- async load_ids_async(instrument_ids: list[InstrumentId], filters: dict | None = None) None¶
Load the latest instrument definitions for the given instrument IDs into the provider by requesting the latest instrument definition messages from Databento.
You must only request instrument definitions from one dataset at a time. The Databento dataset will be determined from either the filters, or the venues for the instrument IDs.
- Parameters:
instrument_ids (list[InstrumentId]) – The instrument IDs to load.
filters (dict, optional) – The optional filters for the instrument definition request.
- Raises:
ValueError – If all venues in instrument_ids are not equal.
Warning
Calling this method will incur a cost to your Databento account in USD.
- async load_async(instrument_id: InstrumentId, filters: dict | None = None) None¶
Load the instrument for the given ID into the provider asynchronously, optionally applying the given filters.
The default implementation delegates to
load_ids_async. Subclasses with per-instrument fetch capability should override this method.- Parameters:
instrument_id (InstrumentId) – The instrument ID to load.
filters (frozendict[str, Any] or dict[str, Any], optional) – The venue specific instrument loading filters to apply.
- async get_range(instrument_ids: list[InstrumentId], start: Timestamp | date | str | int, end: Timestamp | date | str | int | None = None, filters: dict | None = None) list[Instrument]¶
Request a time series of instrument definitions for the given instrument IDs by making a /timeseries.get_range(…) request from Databento.
- Parameters:
instrument_ids (list[InstrumentId]) – The instrument IDs for the request.
start (pd.Timestamp or date or str or int) – The start datetime of the request time range (inclusive). Assumes UTC as timezone unless passed a tz-aware object. If an integer is passed, then this represents nanoseconds since the UNIX epoch.
end (pd.Timestamp or date or str or int, optional) – The end datetime of the request time range (exclusive). Assumes UTC as timezone unless passed a tz-aware object. If an integer is passed, then this represents nanoseconds since the UNIX epoch. Values are forward-filled based on the resolution provided. Defaults to the same value as start.
filters (dict, optional) – The optional filters for the instrument definition request.
Warning
Calling this method will incur a cost to your Databento account in USD.
- add(instrument: Instrument) None¶
Add the given instrument to the provider.
- Parameters:
instrument (Instrument) – The instrument to add.
- add_bulk(instruments: list[Instrument]) None¶
Add the given instruments bulk to the provider.
- Parameters:
instruments (list[Instrument]) – The instruments to add.
- add_currency(currency: Currency) None¶
Add the given currency to the provider.
- Parameters:
currency (Currency) – The currency to add.
- property count: int¶
Return the count of instruments held by the provider.
- Return type:
int
- currencies() dict[str, Currency]¶
Return all currencies held by the instrument provider.
- Return type:
dict[str, Currency]
- currency(code: str) Currency | None¶
Return the currency with the given code (if found).
- Parameters:
code (str) – The currency code.
- Return type:
Currency or
None- Raises:
ValueError – If code is not a valid string.
- find(instrument_id: InstrumentId) Instrument | None¶
Return the instrument for the given instrument ID (if found).
- Parameters:
instrument_id (InstrumentId) – The ID for the instrument
- Return type:
Instrument or
None
- get_all() dict[InstrumentId, Instrument]¶
Return all loaded instruments as a map keyed by instrument ID.
If no instruments loaded, will return an empty dict.
- Return type:
dict[InstrumentId, Instrument]
- async initialize(reload: bool = False) None¶
Initialize the instrument provider.
- Parameters:
reload (bool, default False) – If True, then will always reload instruments. If False, then will immediately return if already loaded.
- list_all() list[Instrument]¶
Return all loaded instruments.
- Return type:
list[Instrument]
- load(instrument_id: InstrumentId, filters: dict | None = None) None¶
Load the instrument for the given ID into the provider, optionally applying the given filters.
- Parameters:
instrument_id (InstrumentId) – The instrument ID to load.
filters (frozendict[str, Any] or dict[str, Any], optional) – The venue specific instrument loading filters to apply.
- load_all(filters: dict | None = None) None¶
Load the latest instruments into the provider, optionally applying the given filters.
- Parameters:
filters (frozendict[str, Any] or dict[str, Any], optional) – The venue specific instrument loading filters to apply.
- load_ids(instrument_ids: list[InstrumentId], filters: dict | None = None) None¶
Load the instruments for the given IDs into the provider, optionally applying the given filters.
- Parameters:
instrument_ids (list[InstrumentId]) – The instrument IDs to load.
filters (frozendict[str, Any] or dict[str, Any], optional) – The venue specific instrument loading filters to apply.
Data¶
- class DatabentoDataClient¶
Bases:
LiveMarketDataClientProvides a data client for the Databento API.
Both Historical and Live APIs are leveraged to provide historical data for requests, and live data feeds based on subscriptions.
- Parameters:
loop (asyncio.AbstractEventLoop) – The event loop for the client.
http_client (nautilus_pyo3.DatabentoHistoricalClient) – The Databento historical HTTP client.
msgbus (MessageBus) – The message bus for the client.
cache (Cache) – The cache for the client.
clock (LiveClock) – The clock for the client.
instrument_provider (DatabentoInstrumentProvider) – The instrument provider for the client.
loader (DatabentoDataLoader, optional) – The loader for the client.
config (DatabentoDataClientConfig, optional) – The configuration for the client.
name (str, optional) – The custom client ID.
- subscribe_order_book_deltas(self, SubscribeOrderBook command) void¶
Subscribe to OrderBookDeltas data for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The order book instrument to subscribe to.
book_type (BookType {
L1_MBP,L2_MBP,L3_MBO}) – The order book type.depth (int, optional, default None) – The maximum depth for the subscription.
params (dict[str, Any], optional) – Additional params for the subscription.
- subscribe_order_book_snapshots(command: SubscribeOrderBook) None¶
- subscribe_quote_ticks(self, SubscribeQuoteTicks command) void¶
Subscribe to QuoteTick data for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The tick instrument to subscribe to.
params (dict[str, Any], optional) – Additional params for the subscription.
- subscribe_trade_ticks(self, SubscribeTradeTicks command) void¶
Subscribe to TradeTick data for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The tick instrument to subscribe to.
params (dict[str, Any], optional) – Additional params for the subscription.
- subscribe_bars(self, SubscribeBars command) void¶
Subscribe to Bar data for the given bar type.
- Parameters:
bar_type (BarType) – The bar type to subscribe to.
params (dict[str, Any], optional) – Additional params for the subscription.
- subscribe_instrument_status(self, SubscribeInstrumentStatus command) void¶
Subscribe to InstrumentStatus data for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The tick instrument to subscribe to.
params (dict[str, Any], optional) – Additional params for the subscription.
- async cancel_pending_tasks(timeout_secs: float = 5.0) None¶
Cancel all pending tasks and await their cancellation.
- Parameters:
timeout_secs (float, default 5.0) – The timeout in seconds to wait for tasks to cancel.
- connect() None¶
Connect the client.
- create_task(coro: Coroutine, log_msg: str | None = None, actions: Callable | None = None, success_msg: str | None = None, success_color: LogColor = <LogColor.NORMAL: 0>) Task | None¶
Run the given coroutine with error handling and optional callback actions when done.
- Parameters:
coro (Coroutine) – The coroutine to run.
log_msg (str, optional) – The log message for the task.
actions (Callable, optional) – The actions callback to run when the coroutine is done.
success_msg (str, optional) – The log message to write on actions success.
success_color (LogColor, default
NORMAL) – The log message color for actions success.
- Return type:
asyncio.Task
- degrade(self) void¶
Degrade the component.
While executing on_degrade() any exception will be logged and reraised, then the component will remain in a
DEGRADINGstate.Warning
Do not override.
If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.
- disconnect() None¶
Disconnect the client.
- dispose(self) void¶
Dispose of the component.
While executing on_dispose() any exception will be logged and reraised, then the component will remain in a
DISPOSINGstate.Warning
Do not override.
If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.
- fault(self) void¶
Fault the component.
Calling this method multiple times has the same effect as calling it once (it is idempotent). Once called, it cannot be reversed, and no other methods should be called on this instance.
While executing on_fault() any exception will be logged and reraised, then the component will remain in a
FAULTINGstate.Warning
Do not override.
If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.
- classmethod fully_qualified_name(cls) str¶
Return the fully qualified name for the components class.
- Return type:
str
References
- id¶
The components ID.
- Returns:
ComponentId
- is_connected¶
If the client is connected.
- Returns:
bool
- is_degraded¶
bool
Return whether the current component state is
DEGRADED.- Return type:
bool
- Type:
- is_disposed¶
bool
Return whether the current component state is
DISPOSED.- Return type:
bool
- Type:
- is_faulted¶
bool
Return whether the current component state is
FAULTED.- Return type:
bool
- Type:
- is_initialized¶
bool
Return whether the component has been initialized (component.state >=
INITIALIZED).- Return type:
bool
- Type:
- is_running¶
bool
Return whether the current component state is
RUNNING.- Return type:
bool
- Type:
- is_stopped¶
bool
Return whether the current component state is
STOPPED.- Return type:
bool
- Type:
- request(self, RequestData request) void¶
Request data for the given data type.
- Parameters:
request (RequestData) – The message for the data request.
- request_bars(self, RequestBars request) void¶
Request historical Bar data. To load historical data from a catalog, you can pass a list[DataCatalogConfig] to the TradingNodeConfig or the BacktestEngineConfig.
- Parameters:
request (RequestBars) – The message for the data request.
- request_funding_rates(self, RequestFundingRates request) void¶
Request historical FundingRateUpdate data.
- Parameters:
request (RequestFundingRates) – The message for the data request.
- request_instrument(self, RequestInstrument request) void¶
Request Instrument data for the given instrument ID.
- Parameters:
request (RequestInstrument) – The message for the data request.
- request_instruments(self, RequestInstruments request) void¶
Request all Instrument data for the given venue.
- Parameters:
request (RequestInstruments) – The message for the data request.
- request_order_book_deltas(self, RequestOrderBookDeltas request) void¶
Request historical OrderBookDeltas data.
- Parameters:
request (RequestOrderBookDeltas) – The message for the data request.
- request_order_book_depth(request: RequestOrderBookDepth) None¶
- request_order_book_snapshot(self, RequestOrderBookSnapshot request) void¶
Request order book snapshot data.
- Parameters:
request (RequestOrderBookSnapshot) – The message for the data request.
- request_quote_ticks(self, RequestQuoteTicks request) void¶
Request historical QuoteTick data.
- Parameters:
request (RequestQuoteTicks) – The message for the data request.
- request_trade_ticks(self, RequestTradeTicks request) void¶
Request historical TradeTick data.
- Parameters:
request (RequestTradeTicks) – The message for the data request.
- reset(self) void¶
Reset the component.
All stateful fields are reset to their initial value.
While executing on_reset() any exception will be logged and reraised, then the component will remain in a
RESETTINGstate.Warning
Do not override.
If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.
- resume(self) void¶
Resume the component.
While executing on_resume() any exception will be logged and reraised, then the component will remain in a
RESUMINGstate.Warning
Do not override.
If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.
- async run_after_delay(delay: float, coro: Coroutine) None¶
Run the given coroutine after a delay.
- Parameters:
delay (float) – The delay (seconds) before running the coroutine.
coro (Coroutine) – The coroutine to run after the initial delay.
- shutdown_system(self, str reason=None) void¶
Initiate a system-wide shutdown by generating and publishing a ShutdownSystem command.
The command is handled by the system’s NautilusKernel, which will invoke either stop (synchronously) or stop_async (asynchronously) depending on the execution context and the presence of an active event loop.
- Parameters:
reason (str, optional) – The reason for issuing the shutdown command.
- start(self) void¶
Start the component.
While executing on_start() any exception will be logged and reraised, then the component will remain in a
STARTINGstate.Warning
Do not override.
If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.
- state¶
ComponentState
Return the components current state.
- Return type:
ComponentState
- Type:
- stop(self) void¶
Stop the component.
While executing on_stop() any exception will be logged and reraised, then the component will remain in a
STOPPINGstate.Warning
Do not override.
If the component is not in a valid state from which to execute this method, then the component state will not change, and an error will be logged.
- subscribe(self, SubscribeData command) void¶
Subscribe to data for the given data type.
- Parameters:
data_type (DataType) – The data type for the subscription.
params (dict[str, Any], optional) – Additional params for the subscription.
- subscribe_funding_rates(self, SubscribeFundingRates command) void¶
Subscribe to FundingRateUpdate data for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument to subscribe to.
params (dict[str, Any], optional) – Additional params for the subscription.
- subscribe_index_prices(self, SubscribeIndexPrices command) void¶
Subscribe to IndexPriceUpdate data for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument to subscribe to.
params (dict[str, Any], optional) – Additional params for the subscription.
- subscribe_instrument(self, SubscribeInstrument command) void¶
Subscribe to the Instrument with the given instrument ID.
- Parameters:
params (dict[str, Any], optional) – Additional params for the subscription.
- subscribe_instrument_close(self, SubscribeInstrumentClose command) void¶
Subscribe to InstrumentClose updates for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The tick instrument to subscribe to.
params (dict[str, Any], optional) – Additional params for the subscription.
- subscribe_instruments(self, SubscribeInstruments command) void¶
Subscribe to all Instrument data.
- Parameters:
params (dict[str, Any], optional) – Additional params for the subscription.
- subscribe_mark_prices(self, SubscribeMarkPrices command) void¶
Subscribe to MarkPriceUpdate data for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument to subscribe to.
params (dict[str, Any], optional) – Additional params for the subscription.
- subscribe_order_book_depth(self, SubscribeOrderBook command) void¶
Subscribe to OrderBookDepth10 data for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The order book instrument to subscribe to.
depth (int, optional) – The maximum depth for the order book (defaults to 10).
params (dict[str, Any], optional) – Additional params for the subscription.
- subscribed_custom_data(self) list¶
Return the custom data types subscribed to.
- Return type:
list[DataType]
- subscribed_funding_rates(self) list¶
Return the funding rate update instruments subscribed to.
- Return type:
list[InstrumentId]
- subscribed_index_prices(self) list¶
Return the index price update instruments subscribed to.
- Return type:
list[InstrumentId]
- subscribed_instrument_close(self) list¶
Return the instrument closes subscribed to.
- Return type:
list[InstrumentId]
- subscribed_instrument_status(self) list¶
Return the status update instruments subscribed to.
- Return type:
list[InstrumentId]
- subscribed_instruments(self) list¶
Return the instruments subscribed to.
- Return type:
list[InstrumentId]
- subscribed_mark_prices(self) list¶
Return the mark price update instruments subscribed to.
- Return type:
list[InstrumentId]
- subscribed_order_book_deltas(self) list¶
Return the order book delta instruments subscribed to.
- Return type:
list[InstrumentId]
- subscribed_order_book_depth(self) list¶
Return the order book depth instruments subscribed to.
- Return type:
list[InstrumentId]
- subscribed_quote_ticks(self) list¶
Return the quote tick instruments subscribed to.
- Return type:
list[InstrumentId]
- subscribed_trade_ticks(self) list¶
Return the trade tick instruments subscribed to.
- Return type:
list[InstrumentId]
- trader_id¶
The trader ID associated with the component.
- Returns:
TraderId
- type¶
The components type.
- Returns:
type
- unsubscribe(self, UnsubscribeData command) void¶
Unsubscribe from data for the given data type.
- Parameters:
data_type (DataType) – The data type for the subscription.
params (dict[str, Any], optional) – Additional params for the subscription.
- unsubscribe_bars(self, UnsubscribeBars command) void¶
Unsubscribe from Bar data for the given bar type.
- Parameters:
bar_type (BarType) – The bar type to unsubscribe from.
params (dict[str, Any], optional) – Additional params for the subscription.
- unsubscribe_funding_rates(self, UnsubscribeFundingRates command) void¶
Unsubscribe from FundingRateUpdate data for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument to subscribe to.
params (dict[str, Any], optional) – Additional params for the subscription.
- unsubscribe_index_prices(self, UnsubscribeIndexPrices command) void¶
Unsubscribe from IndexPriceUpdate data for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument to subscribe to.
params (dict[str, Any], optional) – Additional params for the subscription.
- unsubscribe_instrument(self, UnsubscribeInstrument command) void¶
Unsubscribe from Instrument data for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument to unsubscribe from.
params (dict[str, Any], optional) – Additional params for the subscription.
- unsubscribe_instrument_close(self, UnsubscribeInstrumentClose command) void¶
Unsubscribe from InstrumentClose data for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The tick instrument to unsubscribe from.
params (dict[str, Any], optional) – Additional params for the subscription.
- unsubscribe_instrument_status(self, UnsubscribeInstrumentStatus command) void¶
Unsubscribe from InstrumentStatus data for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument status updates to unsubscribe from.
params (dict[str, Any], optional) – Additional params for the subscription.
- unsubscribe_instruments(self, UnsubscribeInstruments command) void¶
Unsubscribe from all Instrument data.
- Parameters:
params (dict[str, Any], optional) – Additional params for the subscription.
- unsubscribe_mark_prices(self, UnsubscribeMarkPrices command) void¶
Unsubscribe from MarkPriceUpdate data for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The instrument to subscribe to.
params (dict[str, Any], optional) – Additional params for the subscription.
- unsubscribe_order_book_deltas(self, UnsubscribeOrderBook command) void¶
Unsubscribe from OrderBookDeltas data for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The order book instrument to unsubscribe from.
params (dict[str, Any], optional) – Additional params for the subscription.
- unsubscribe_order_book_depth(self, UnsubscribeOrderBook command) void¶
Unsubscribe from OrderBookDepth10 data for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The order book instrument to unsubscribe from.
params (dict[str, Any], optional) – Additional params for the subscription.
- unsubscribe_quote_ticks(self, UnsubscribeQuoteTicks command) void¶
Unsubscribe from QuoteTick data for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The tick instrument to unsubscribe from.
params (dict[str, Any], optional) – Additional params for the subscription.
- unsubscribe_trade_ticks(self, UnsubscribeTradeTicks command) void¶
Unsubscribe from TradeTick data for the given instrument ID.
- Parameters:
instrument_id (InstrumentId) – The tick instrument to unsubscribe from.
params (dict[str, Any], optional) – Additional params for the subscription.
- venue¶
The clients venue ID (if applicable).
- Returns:
Venue or
None