Databento2 - Loren1166/NautilusTrader- GitHub Wiki
Databento
class DatabentoDataLoader Databento 数据加载器
class DatabentoDataLoader
Provides a data loader for Databento Binary Encoding (DBN) format data.
为 Databento 二进制编码 (DBN) 格式数据提供数据加载器。
Supported schemas:
- MBO ->
OrderBookDelta
- MBP_1 -> (
QuoteTick
,TradeTick
|None
)- MBP_10 ->
OrderBookDepth10
- 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
def load_publishers(self, 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.
# 要加载的发布者数据的路径。
"""
...
def get_publishers(self) -> dict[int, DatabentoPublisher]:
"""
Return the internal Databento publishers currently held by the loader.
Returns
-------
dict[int, DatabentoPublisher]
"""
...
def get_dataset_for_venue(self, venue: Venue) -> str:
"""
Return a dataset for the given venue.
Parameters
----------
venue : Venue
The venue for the given dataset.
# 给定数据集的交易平台。
Returns
-------
str
Raises
------
ValueError
If venue is not in the map of publishers.
"""
...
def from_dbn_file(self, path: PathLike[str] | str, instrument_id: InstrumentId | None = None, as_legacy_cython: bool = True, include_trades: bool = False) -> list[Data] | list:
"""
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.
# DBN 数据文件的路径。
instrument_id : InstrumentId, optional
The Nautilus instrument ID for the data. This is a parameter to optimize
performance, as all records will have their symbology overridden with the
given Nautilus identifier. This option should only be used if the instrument
ID is definitely know (for instance if all records in a file are guarantted
to be for the same instrument).
# 数据的 Nautilus Instrument ID。这是一个用于优化性能的参数,因为所有记录的符号都将被
# 给定的 Nautilus 标识符覆盖。仅当Instrument ID确定已知时才应使用此选项(例如,如果文件中
# 的所有记录都保证用于同一Instrument)。
as_legacy_cython : bool, 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).
# 是否应将数据转换为“旧 Cython”对象。如果您将对象直接传递给数据目录以将数据写入
# Nautilus Parquet 格式,则通常只将此设置为 False。注意:不平衡和统计架构仅在 Rust
# 中实现,因此无法作为旧 Cython 对象加载(因此将其设置为 False)。
include_trades : bool, 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).
# 如果适用,是否将在 MBO 和 MBP-1 架构的数据中包含单独的 TradeTick 元素(您的代码
# 必须处理返回列表中的这两种类型)。
Returns
-------
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 DatabentoDataClientConfig Databento 数据客户端配置
class DatabentoDataClientConfig(LiveDataClientConfig)
Configuration for
DatabentoDataClient
instances.
DatabentoDataClient
实例的配置。
Parameters:
api_key
(str
, optional): The Databento API secret key. IfNone
then will source theDATABENTO_API_KEY
environment variable.api_key
(str
,可选):Databento API 密钥。如果为None
,则将获取DATABENTO_API_KEY
环境变量。http_gateway
(str
, optional): The historical HTTP client gateway override.http_gateway
(str
,可选):历史 HTTP 客户端网关覆盖。live_gateway
(str
, optional): The live client gateway override.live_gateway
(str
,可选):实时客户端网关覆盖。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).parent_symbols
(dict[*str, set[*str]]
,可选):启动时订阅Instrument定义的 Databento 父符号。这是 Databento 数据集键 -> 到父符号序列的映射,例如{'GLBX.MDP3', ['ES.FUT', 'ES.OPT']}
(适用于所有 E-mini S&P 500 期货和期权产品)。instrument_ids
(list[InstrumentId]
, optional): The instrument IDs to request instrument definitions for on start.instrument_ids
(list[InstrumentId]
,可选):启动时请求Instrument定义的Instrument ID。timeout_initial_load
(float
, default10.0
): The timeout (seconds) to wait for instruments to load (concurrently per dataset).timeout_initial_load
(float
,默认值10.0
):等待Instrument加载的超时时间(以秒为单位)(每个数据集并发)。mbo_subscriptions_delay
(float
, default3.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 start of the week which encompasses the initial snapshot and then all deltas.mbo_subscriptions_delay
(float
,默认值3.0
):等待 MBO/L3 订阅的超时时间(以秒为单位)(每个数据集并发)。超时后,MBO 订单簿馈送将启动并从包含初始快照和所有增量的星期一开始重放消息。
api_key: str | None
http_gateway: str | None
live_gateway: str | None
instrument_ids: list[InstrumentId] | None
parent_symbols: dict[str, set[str]] | None
timeout_initial_load: float | None
mbo_subscriptions_delay: float | None
def __dict__(self) -> dict[str, Any]:
"""
Return a dictionary representation of the configuration.
Returns
-------
dict[str, Any]
"""
...
@classmethod
def fully_qualified_name() -> str:
"""
Return the fully qualified name for the NautilusConfig class.
Returns
-------
str
"""
...
@property
def handle_revised_bars(self) -> bool:
...
@property
def id(self) -> str:
"""
Return the hashed identifier for the configuration.
Returns
-------
str
"""
...
@property
def instrument_provider(self) -> InstrumentProviderConfig:
...
def json(self) -> bytes:
"""
Return serialized JSON encoded bytes.
Returns
-------
bytes
"""
...
def json_primitives(self) -> dict[str, Any]:
"""
Return a dictionary representation of the configuration with JSON primitive types as values.
Returns
-------
dict[str, Any]
"""
...
@classmethod
def 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.
Returns
-------
Any
"""
...
@property
def routing(self) -> RoutingConfig:
...
def validate(self) -> bool:
"""
Return whether the configuration can be represented as valid JSON.
Returns
-------
bool
"""
...
class DatabentoLiveDataClientFactory Databento 实时数据客户端工厂
class DatabentoLiveDataClientFactory(LiveDataClientFactory)
Provides a Binance live data client factory.
提供币安实时数据客户端工厂。
@staticmethod
def 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.
Returns
-------
DatabentoDataClient
"""
...
class DatabentoStatistics Databento 统计数据
class DatabentoStatistics
Represents a market statistics snapshot.
表示市场统计快照。
This data type includes the populated data fields provided by Databento, excluding
publisher_id
andinstrument_id
.此数据类型包括 Databento 提供的已填充数据字段,不包括
publisher_id
和instrument_id
。
channel_id
instrument_id
price
quantity
sequence
stat_flags
stat_type
ts_event
ts_in_delta
ts_init
ts_recv
ts_ref
update_action
@staticmethod
def from_dict(values):
...
def to_dict(self):
...
class DatabentoImbalance Databento 不平衡
class DatabentoImbalance
Represents an auction imbalance.
表示拍卖不平衡。
This data type includes the populated data fields provided by Databento, excluding
publisher_id
andinstrument_id
.此数据类型包括 Databento 提供的已填充数据字段,不包括
publisher_id
和instrument_id
。
auct_interest_clr_price
cont_book_clr_price
instrument_id
paired_qty
ref_price
side
significant_imbalance
total_imbalance_qty
ts_event
ts_init
ts_recv
@staticmethod
def from_dict(values):
...
def to_dict(self):
...
Config 配置
class DatabentoDataClientConfig Databento 数据客户端配置
class DatabentoDataClientConfig(LiveDataClientConfig)
Configuration for
DatabentoDataClient
instances.
DatabentoDataClient
实例的配置。
Parameters:
api_key
(str
, optional): The Databento API secret key. IfNone
then will source theDATABENTO_API_KEY
environment variable.api_key
(str
,可选):Databento API 密钥。如果为None
,则将获取DATABENTO_API_KEY
环境变量。http_gateway
(str
, optional): The historical HTTP client gateway override.http_gateway
(str
,可选):历史 HTTP 客户端网关覆盖。live_gateway
(str
, optional): The live client gateway override.live_gateway
(str
,可选):实时客户端网关覆盖。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).parent_symbols
(dict[*str, set[*str]]
,可选):启动时订阅Instrument定义的 Databento 父符号。这是 Databento 数据集键 -> 到父符号序列的映射,例如{'GLBX.MDP3', ['ES.FUT', 'ES.OPT']}
(适用于所有 E-mini S&P 500 期货和期权产品)。instrument_ids
(list[InstrumentId]
, optional): The instrument IDs to request instrument definitions for on start.instrument_ids
(list[InstrumentId]
,可选):启动时请求Instrument定义的Instrument ID。timeout_initial_load
(float
, default10.0
): The timeout (seconds) to wait for instruments to load (concurrently per dataset).timeout_initial_load
(float
,默认值10.0
):等待Instrument加载的超时时间(以秒为单位)(每个数据集并发)。mbo_subscriptions_delay
(float
, default3.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 start of the week which encompasses the initial snapshot and then all deltas.mbo_subscriptions_delay
(float
,默认值3.0
):等待 MBO/L3 订阅的超时时间(以秒为单位)(每个数据集并发)。超时后,MBO 订单簿馈送将启动并从包含初始快照和所有增量的星期一开始重放消息。
api_key: str | None
http_gateway: str | None
live_gateway: str | None
instrument_ids: list[InstrumentId] | None
parent_symbols: dict[str, set[str]] | None
timeout_initial_load: float | None
mbo_subscriptions_delay: float | None
def __dict__(self) -> dict[str, Any]:
"""
Return a dictionary representation of the configuration.
Returns
-------
dict[str, Any]
"""
...
@classmethod
def fully_qualified_name() -> str:
"""
Return the fully qualified name for the NautilusConfig class.
Returns
-------
str
"""
...
@property
def handle_revised_bars(self) -> bool:
...
@property
def id(self) -> str:
"""
Return the hashed identifier for the configuration.
Returns
-------
str
"""
...
@property
def instrument_provider(self) -> InstrumentProviderConfig:
...
def json(self) -> bytes:
"""
Return serialized JSON encoded bytes.
Returns
-------
bytes
"""
...
def json_primitives(self) -> dict[str, Any]:
"""
Return a dictionary representation of the configuration with JSON primitive types as values.
Returns
-------
dict[str, Any]
"""
...
@classmethod
def 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.
Returns
-------
Any
"""
...
@property
def routing(self) -> RoutingConfig:
...
def validate(self) -> bool:
"""
Return whether the configuration can be represented as valid JSON.
Returns
-------
bool
"""
...
Factories 工厂
def get_cached_databento_http_client(key: str | None = None, gateway: str | None = None) -> DatabentoHistoricalClient:
"""
Cache and return a Databento historical HTTP client with the given key and gateway.
If a cached client with matching key and gateway already exists, then that cached client will be returned.
Parameters
----------
key : str, optional
The Databento API secret key for the client.
# 客户端的 Databento API 密钥。
gateway : str, optional
The Databento historical HTTP client gateway override.
# Databento 历史 HTTP 客户端网关覆盖。
Returns
-------
nautilus_pyo3.DatabentoHistoricalClient
"""
...
def 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) -> 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.
# Instrument提供程序的客户端。
clock : LiveClock
The clock for the instrument provider.
# Instrument提供程序的时钟。
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.
# Databento 实时客户端的特定 API 密钥。如果未提供,则将使用历史 HTTP 客户端 API 密钥。
live_gateway : str, optional
The live gateway override for Databento live clients.
# Databento 实时客户端的实时网关覆盖。
loader : DatabentoDataLoader, optional
The loader for the provider.
# 提供程序的加载器。
config : InstrumentProviderConfig
The configuration for the instrument provider.
# Instrument提供程序的配置。
Returns
-------
DatabentoInstrumentProvider
"""
...
class DatabentoLiveDataClientFactory Databento 实时数据客户端工厂
class DatabentoLiveDataClientFactory(LiveDataClientFactory)
Provides a Binance live data client factory.
提供币安实时数据客户端工厂。
@staticmethod
def 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.
Returns
-------
DatabentoDataClient
"""
...
Enums 枚举
class DatabentoSchema Databento 架构
class DatabentoSchema(Enum)
Represents a Databento schema.
表示 Databento 架构。
MBO = "mbo"
MBP_1 = "mbp-1"
MBP_10 = "mbp-10"
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 Databento 不平衡
class DatabentoImbalance
Represents an auction imbalance.
表示拍卖不平衡。
This data type includes the populated data fields provided by Databento, excluding
publisher_id
andinstrument_id
.此数据类型包括 Databento 提供的已填充数据字段,不包括
publisher_id
和instrument_id
。
auct_interest_clr_price
cont_book_clr_price
instrument_id
paired_qty
ref_price
side
significant_imbalance
total_imbalance_qty
ts_event
ts_init
ts_recv
@staticmethod
def from_dict(values):
...
def to_dict(self):
...
class DatabentoStatistics Databento 统计数据
class DatabentoStatistics
Represents a market statistics snapshot.
表示市场统计快照。
This data type includes the populated data fields provided by Databento, excluding
publisher_id
andinstrument_id
.此数据类型包括 Databento 提供的已填充数据字段,不包括
publisher_id
和instrument_id
。
channel_id
instrument_id
price
quantity
sequence
stat_flags
stat_type
ts_event
ts_in_delta
ts_init
ts_recv
ts_ref
update_action
@staticmethod
def from_dict(values):
...
def to_dict(self):
...
Loaders 加载器
class DatabentoDataLoader Databento 数据加载器
class DatabentoDataLoader
Provides a data loader for Databento Binary Encoding (DBN) format data.
为 Databento 二进制编码 (DBN) 格式数据提供数据加载器。
Supported schemas:
- MBO ->
OrderBookDelta
- MBP_1 -> (
QuoteTick
,TradeTick
|None
)- MBP_10 ->
OrderBookDepth10
- 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
def load_publishers(self, 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.
# 要加载的发布者数据的路径。
"""
...
def get_publishers(self) -> dict[int, DatabentoPublisher]:
"""
Return the internal Databento publishers currently held by the loader.
Returns
-------
dict[int, DatabentoPublisher]
"""
...
def get_dataset_for_venue(self, venue: Venue) -> str:
"""
Return a dataset for the given venue.
Parameters
----------
venue : Venue
The venue for the given dataset.
# 给定数据集的交易平台。
Returns
-------
str
Raises
------
ValueError
If venue is not in the map of publishers.
"""
...
def from_dbn_file(self, path: PathLike[str] | str, instrument_id: InstrumentId | None = None, as_legacy_cython: bool = True, include_trades: bool = False) -> list[Data] | list:
"""
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.
# DBN 数据文件的路径。
instrument_id : InstrumentId, optional
The Nautilus instrument ID for the data. This is a parameter to optimize
performance, as all records will have their symbology overridden with the
given Nautilus identifier. This option should only be used if the instrument
ID is definitely know (for instance if all records in a file are guarantted
to be for the same instrument).
# 数据的 Nautilus Instrument ID。这是一个用于优化性能的参数,因为所有记录的符号都将被
# 给定的 Nautilus 标识符覆盖。仅当Instrument ID 确定已知时才应使用此选项(例如,如果文件中
# 的所有记录都保证用于同一Instrument)。
as_legacy_cython : bool, 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).
# 是否应将数据转换为“旧 Cython”对象。如果您将对象直接传递给数据目录以将数据写入
# Nautilus Parquet 格式,则通常只将此设置为 False。注意:不平衡和统计架构仅在 Rust
# 中实现,因此无法作为旧 Cython 对象加载(因此将其设置为 False)。
include_trades : bool, 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).
# 如果适用,是否将在 MBO 和 MBP-1 架构的数据中包含单独的 TradeTick 元素(您的代码
# 必须处理返回列表中的这两种类型)。
Returns
-------
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 Databento Instrument提供程序
class DatabentoInstrumentProvider(InstrumentProvider)
Provides a means of loading
Instrument
objects from Databento.提供从 Databento 加载
Instrument
对象的方法。
Parameters:
http_client
(nautilus_pyo3.DatabentoHistoricalClient
): The Databento historical HTTP client for the provider.http_client
(nautilus_pyo3.DatabentoHistoricalClient
):提供程序的 Databento 历史 HTTP 客户端。clock
(LiveClock
): The clock for the provider.clock
(LiveClock
):提供程序的时钟。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_api_key
(str
,可选):Databento 实时客户端的特定 API 密钥。如果未提供,则将使用历史 HTTP 客户端 API 密钥。live_gateway
(str
, optional): The live gateway override for Databento live clients.live_gateway
(str
,可选):Databento 实时客户端的实时网关覆盖。loader
(DatabentoDataLoader
, optional): The loader for the provider.loader
(DatabentoDataLoader
,可选):提供程序的加载器。config
(InstrumentProviderConfig
, optional): The configuration for the provider.config
(InstrumentProviderConfig
,可选):提供程序的配置。
async def load_all_async(self, filters: dict | None = None) -> None:
"""
Load the latest instruments into the provider asynchronously, optionally applying the given filters.
# 异步加载最新的Instrument到提供程序中,可选地应用给定的过滤器。
"""
...
async def load_ids_async(self, 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.
# 要加载的Instrument ID。
filters : dict, optional
The optional filters for the instrument definition request.
# Instrument定义请求的可选过滤器。
Raises
------
ValueError
If all venues in instrument_ids are not equal.
Warnings
--------
Calling this method will incur a cost to your Databento account in USD.
# 调用此方法将导致您的 Databento 账户产生美元成本。
"""
...
async def load_async(self, instrument_id: InstrumentId, filters: dict | None = None) -> None:
"""
Load the latest instrument definition for the given instrument ID into the provider by requesting
the latest instrument definition message from Databento.
The Databento dataset will be determined from either the filters, or the venue for the instrument ID.
Parameters
----------
instrument_id : InstrumentId
The instrument ID to load.
# 要加载的Instrument ID。
filters : dict, optional
The optional filters for the instrument definition request.
# Instrument定义请求的可选过滤器。
Warnings
--------
Calling this method will incur a cost to your Databento account in USD.
# 调用此方法将导致您的 Databento 账户产生美元成本。
"""
...
async def get_range(self, 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.
# 请求的Instrument ID。
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.
# 请求时间范围的开始日期时间(包括)。除非传递了时区感知对象,否则假定时区为 UTC。
# 如果传递了整数,则表示自 UNIX 纪元以来的纳秒数。
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.
# 请求时间范围的结束日期时间(不包括)。除非传递了时区感知对象,否则假定时区为 UTC。
# 如果传递了整数,则表示自 UNIX 纪元以来的纳秒数。根据提供的分辨率向前填充值。
# 默认为与开始相同的值。
filters : dict, optional
The optional filters for the instrument definition request.
# Instrument定义请求的可选过滤器。
Warnings
--------
Calling this method will incur a cost to your Databento account in USD.
# 调用此方法将导致您的 Databento 账户产生美元成本。
"""
...
def add(self, instrument: Instrument) -> None:
"""
Add the given instrument to the provider.
Parameters
----------
instrument : Instrument
The instrument to add.
# 要添加的Instrument。
"""
...
def add_bulk(self, instruments: list[Instrument]) -> None:
"""
Add the given instruments bulk to the provider.
Parameters
----------
instruments : list[Instrument]
The instruments to add.
# 要添加的Instrument。
"""
...
def add_currency(self, currency: Currency) -> None:
"""
Add the given currency to the provider.
Parameters
----------
currency : Currency
The currency to add.
# 要添加的货币。
"""
...
@property
def count(self) -> int:
"""
Return the count of instruments held by the provider.
Returns
-------
int
"""
...
def currencies(self) -> dict[str, Currency]:
"""
Return all currencies held by the instrument provider.
Returns
-------
dict[str, Currency]
"""
...
def currency(self, code: str) -> Currency | None:
"""
Return the currency with the given code (if found).
Parameters
----------
code : str
The currency code.
# 货币代码。
Returns
-------
Currency or None
Raises
------
ValueError
If code is not a valid string.
"""
...
def find(self, instrument_id: InstrumentId) -> Instrument | None:
"""
Return the instrument for the given instrument ID (if found).
Parameters
----------
instrument_id : InstrumentId
The ID for the instrument
# Instrument的 ID
Returns
-------
Instrument or None
"""
...
def get_all(self) -> dict[InstrumentId, Instrument]:
"""
Return all loaded instruments as a map keyed by instrument ID.
If no instruments loaded, will return an empty dict.
Returns
-------
dict[InstrumentId, Instrument]
"""
...
async def initialize(self) -> None:
"""
Initialize the instrument provider.
If initialize() then will immediately return.
# 如果 initialize() 则将立即返回。
"""
...
def list_all(self) -> list[Instrument]:
"""
Return all loaded instruments.
Returns
-------
list[Instrument]
"""
...
def load(self, 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.
# 要加载的Instrument ID。
filters : frozendict[*str, Any] or dict[*str, Any], optional
The venue specific instrument loading filters to apply.
# 要应用的特定于交易平台的Instrument加载过滤器。
"""
...
def load_all(self, 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.
# 要应用的特定于交易平台的Instrument加载过滤器。
"""
...
def load_ids(self, 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.
# 要加载的Instrument ID。
filters : frozendict[*str, Any] or dict[*str, Any], optional
The venue specific instrument loading filters to apply.
# 要应用的特定于交易平台的Instrument加载过滤器。
"""
...
Data 数据
class DatabentoDataClient Databento 数据客户端
class DatabentoDataClient(LiveMarketDataClient)
Provides a data client for the Databento API.
为 Databento API 提供数据客户端。
Both Historical and Live APIs are leveraged to provide historical data for requests, and live data feeds based on subscriptions.
利用历史和实时 API 来提供请求的历史数据和基于订阅的实时数据馈送。
Parameters:
loop
(asyncio.AbstractEventLoop
): The event loop for the client.loop
(asyncio.AbstractEventLoop
):客户端的事件循环。http_client
(nautilus_pyo3.DatabentoHistoricalClient
): The Databento historical HTTP client.http_client
(nautilus_pyo3.DatabentoHistoricalClient
):Databento 历史 HTTP 客户端。msgbus
(MessageBus
): The message bus for the client.msgbus
(MessageBus
):客户端的消息总线。cache
(Cache
): The cache for the client.cache
(Cache
):客户端的缓存。clock
(LiveClock
): The clock for the client.clock
(LiveClock
):客户端的时钟。instrument_provder
(DatabentoInstrumentProvider
): The instrument provider for the client.instrument_provder
(DatabentoInstrumentProvider
):客户端的Instrument提供程序。loader
(DatabentoDataLoader
, optional): The loader for the client.loader
(DatabentoDataLoader
,可选):客户端的加载器。config
(DatabentoDataClientConfig
, optional): The configuration for the client.config
(DatabentoDataClientConfig
,可选):客户端的配置。name
(str
, optional): The custom client ID.name
(str
,可选):自定义客户端 ID。
def subscribe_order_book_deltas(self, instrument_id: InstrumentId, book_type: BookType, depth: int = 0, kwargs: dict = None) -> void:
"""
Subscribe to OrderBookDeltas data for the given instrument ID.
Parameters
----------
instrument_id : InstrumentId
The order book instrument to subscribe to.
# 要订阅的订单簿Instrument。
book_type : BookType {L1_MBP, L2_MBP, L3_MBO}
The order book type.
# 订单簿类型。
depth : int, optional, default None
The maximum depth for the subscription.
# 订阅的最大深度。
kwargs : dict, optional
The keyword arguments for exchange specific parameters.
# 交易所特定参数的关键字参数。
"""
...
def connect(self) -> None:
"""
Connect the client.
# 连接客户端。
"""
...
def create_task(self, coro: Coroutine, log_msg: str | None = None, actions: Callable | None = None, success_msg: str | None = None, success_color: LogColor = LogColor.NORMAL) -> Task:
"""
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.
# 操作成功的日志消息颜色。
Returns
-------
asyncio.Task
"""
...
def degrade(self) -> void:
"""
Degrade the component.
While executing on_degrade() any exception will be logged and reraised, then the component will remain in a DEGRADING state.
Warnings
--------
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.
"""
...
def disconnect(self) -> None:
"""
Disconnect the client.
# 断开客户端连接。
"""
...
def 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 DISPOSING state.
Warnings
--------
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.
"""
...
def 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 FAULTING state.
Warnings
--------
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
def fully_qualified_name(cls) -> str:
"""
Return the fully qualified name for the components class.
Returns
-------
str
"""
...
@property
def id(self) -> ComponentId:
"""
The components ID.
Returns
-------
ComponentId
"""
...
@property
def is_connected(self) -> bool:
"""
If the client is connected.
Returns
-------
bool
"""
...
@property
def is_degraded(self) -> bool:
"""
bool
Return whether the current component state is DEGRADED.
# 返回当前组件状态是否为 DEGRADED。
Returns
-------
bool
"""
...
@property
def is_disposed(self) -> bool:
"""
bool
Return whether the current component state is DISPOSED.
# 返回当前组件状态是否为 DISPOSED。
Returns
-------
bool
"""
...
@property
def is_faulted(self) -> bool:
"""
bool
Return whether the current component state is FAULTED.
# 返回当前组件状态是否为 FAULTED。
Returns
-------
bool
"""
...
@property
def is_initialized(self) -> bool:
"""
bool
Return whether the component has been initialized (component.state >= INITIALIZED).
# 返回组件是否已初始化 (component.state >= INITIALIZED)。
Returns
-------
bool
"""
...
@property
def is_running(self) -> bool:
"""
bool
Return whether the current component state is RUNNING.
# 返回当前组件状态是否为 RUNNING。
Returns
-------
bool
"""
...
@property
def is_stopped(self) -> bool:
"""
bool
Return whether the current component state is STOPPED.
# 返回当前组件状态是否为 STOPPED。
Returns
-------
bool
"""
...
def request(self, data_type: DataType, correlation_id: UUID4) -> void:
"""
Request data for the given data type.
Parameters
----------
data_type : DataType
The data type for the subscription.
# 订阅的数据类型。
correlation_id : UUID4
The correlation ID for the response.
# 响应的相关性 ID。
"""
...
def request_bars(self, bar_type: BarType, limit: int, correlation_id: UUID4, start: datetime = None, end: datetime = None) -> void:
"""
Request historical Bar data.
Parameters
----------
bar_type : BarType
The bar type for the request.
# 请求的K线类型。
limit : int
The limit for the number of returned bars.
# 返回的K线数量限制。
correlation_id : UUID4
The correlation ID for the request.
# 请求的相关性 ID。
start : datetime, optional
The start datetime (UTC) of request time range (inclusive).
# 请求时间范围的开始日期时间(UTC)(包括)。
end : datetime, optional
The end datetime (UTC) of request time range. The inclusiveness depends on
individual data client implementation.
# 请求时间范围的结束日期时间(UTC)。包含性取决于各个数据客户端的实现。
"""
...
def request_instrument(self, instrument_id: InstrumentId, correlation_id: UUID4, start: datetime = None, end: datetime = None) -> void:
"""
Request Instrument data for the given instrument ID.
Parameters
----------
instrument_id : InstrumentId
The instrument ID for the request.
# 请求的Instrument ID。
correlation_id : UUID4
The correlation ID for the request.
# 请求的相关性 ID。
start : datetime, optional
The start datetime (UTC) of request time range (inclusive).
# 请求时间范围的开始日期时间(UTC)(包括)。
end : datetime, optional
The end datetime (UTC) of request time range. The inclusiveness depends on
individual data client implementation.
# 请求时间范围的结束日期时间(UTC)。包含性取决于各个数据客户端的实现。
"""
...
def request_instruments(self, venue: Venue, correlation_id: UUID4, start: datetime = None, end: datetime = None) -> void:
"""
Request all Instrument data for the given venue.
Parameters
----------
venue : Venue
The venue for the request.
# 请求的交易平台。
correlation_id : UUID4
The correlation ID for the request.
# 请求的相关性 ID。
start : datetime, optional
The start datetime (UTC) of request time range (inclusive).
# 请求时间范围的开始日期时间(UTC)(包括)。
end : datetime, optional
The end datetime (UTC) of request time range. The inclusiveness depends on
individual data client implementation.
# 请求时间范围的结束日期时间(UTC)。包含性取决于各个数据客户端的实现。
"""
...
def request_order_book_snapshot(self, instrument_id: InstrumentId, limit: int, correlation_id: UUID4) -> void:
"""
Request order book snapshot data.
Parameters
----------
instrument_id : InstrumentId
The instrument ID for the order book snapshot request.
# 订单簿快照请求的Instrument ID。
limit : int
The limit on the depth of the order book snapshot.
# 订单簿快照的深度限制。
correction_id : UUID4
The correlation ID for the request.
# 请求的相关性 ID。
"""
...
def request_quote_ticks(self, instrument_id: InstrumentId, limit: int, correlation_id: UUID4, start: datetime = None, end: datetime = None) -> void:
"""
Request historical QuoteTick data.
Parameters
----------
instrument_id : InstrumentId
The tick instrument ID for the request.
# 请求的报价Instrument ID。
limit : int
The limit for the number of returned ticks.
# 返回的报价数量限制。
correlation_id : UUID4
The correlation ID for the request.
# 请求的相关性 ID。
start : datetime, optional
The start datetime (UTC) of request time range (inclusive).
# 请求时间范围的开始日期时间(UTC)(包括)。
end : datetime, optional
The end datetime (UTC) of request time range. The inclusiveness depends on
individual data client implementation.
# 请求时间范围的结束日期时间(UTC)。包含性取决于各个数据客户端的实现。
"""
...
def request_trade_ticks(self, instrument_id: InstrumentId, limit: int, correlation_id: UUID4, start: datetime = None, end: datetime = None) -> void:
"""
Request historical TradeTick data.
Parameters
----------
instrument_id : InstrumentId
The tick instrument ID for the request.
# 请求的交易Instrument ID。
limit : int
The limit for the number of returned ticks.
# 返回的交易数量限制。
correlation_id : UUID4
The correlation ID for the request.
# 请求的相关性 ID。
start : datetime, optional
The start datetime (UTC) of request time range (inclusive).
# 请求时间范围的开始日期时间(UTC)(包括)。
end : datetime, optional
The end datetime (UTC) of request time range. The inclusiveness depends on
individual data client implementation.
# 请求时间范围的结束日期时间(UTC)。包含性取决于各个数据客户端的实现。
"""
...
def 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 RESETTING state.
Warnings
--------
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.
"""
...
def resume(self) -> void:
"""
Resume the component.
While executing on_resume() any exception will be logged and reraised, then the component will remain in a RESUMING state.
Warnings
--------
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 def 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.
# 初始延迟后要运行的协程。
"""
...
def start(self) -> void:
"""
Start the component.
While executing on_start() any exception will be logged and reraised, then the component will remain in a STARTING state.
Warnings
--------
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.
"""
...
@property
def state(self) -> ComponentState:
"""
ComponentState
Return the components current state.
# 返回组件的当前状态。
Returns
-------
ComponentState
"""
...
def stop(self) -> void:
"""
Stop the component.
While executing on_stop() any exception will be logged and reraised, then the component will remain in a STOPPING state.
Warnings
--------
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.
"""
...
def subscribe(self, data_type: DataType) -> void:
"""
Subscribe to data for the given data type.
Parameters
----------
data_type : DataType
The data type for the subscription.
# 订阅的数据类型。
"""
...
def subscribe_bars(self, bar_type: BarType) -> void:
"""
Subscribe to Bar data for the given bar type.
Parameters
----------
bar_type : BarType
The bar type to subscribe to.
# 要订阅的K线类型。
"""
...
def subscribe_instrument(self, instrument_id: InstrumentId) -> void:
"""
Subscribe to the Instrument with the given instrument ID.
# 订阅具有给定Instrument ID 的Instrument。
"""
...
def subscribe_instrument_close(self, instrument_id: InstrumentId) -> void:
"""
Subscribe to InstrumentClose updates for the given instrument ID.
Parameters
----------
instrument_id : InstrumentId
The tick instrument to subscribe to.
# 要订阅的报价Instrument。
"""
...
def subscribe_instrument_status(self, instrument_id: InstrumentId) -> void:
"""
Subscribe to InstrumentStatus data for the given instrument ID.
Parameters
----------
instrument_id : InstrumentId
The tick instrument to subscribe to.
# 要订阅的报价Instrument。
"""
...
def subscribe_instruments(self) -> void:
"""
Subscribe to all Instrument data.
# 订阅所有Instrument数据。
"""
...
def subscribe_order_book_snapshots(self, instrument_id: InstrumentId, book_type: BookType, depth: int = 0, kwargs: dict = None) -> void:
"""
Subscribe to OrderBook snapshots data for the given instrument ID.
Parameters
----------
instrument_id : InstrumentId
The order book instrument to subscribe to.
# 要订阅的订单簿Instrument。
book_type : BookType {L1_MBP, L2_MBP, L3_MBO}
The order book level.
# 订单簿级别。
depth : int, optional
The maximum depth for the order book. A depth of 0 is maximum depth.
# 订单簿的最大深度。深度为 0 表示最大深度。
kwargs : dict, optional
The keyword arguments for exchange specific parameters.
# 交易所特定参数的关键字参数。
"""
...
def subscribe_quote_ticks(self, instrument_id: InstrumentId) -> void:
"""
Subscribe to QuoteTick data for the given instrument ID.
Parameters
----------
instrument_id : InstrumentId
The tick instrument to subscribe to.
# 要订阅的报价Instrument。
"""
...
def subscribe_trade_ticks(self, instrument_id: InstrumentId) -> void:
"""
Subscribe to TradeTick data for the given instrument ID.
Parameters
----------
instrument_id : InstrumentId
The tick instrument to subscribe to.
# 要订阅的交易Instrument。
"""
...
def subscribed_bars(self) -> list:
"""
Return the bar types subscribed to.
Returns
-------
list[BarType]
"""
...
def subscribed_custom_data(self) -> list:
"""
Return the custom data types subscribed to.
Returns
-------
list[DataType]
"""
...
def subscribed_instrument_close(self) -> list:
"""
Return the instrument closes subscribed to.
Returns
-------
list[InstrumentId]
"""
...
def subscribed_instrument_status(self) -> list:
"""
Return the status update instruments subscribed to.
Returns
-------
list[InstrumentId]
"""
...
def subscribed_instruments(self) -> list:
"""
Return the instruments subscribed to.
Returns
-------
list[InstrumentId]
"""
...
def subscribed_order_book_deltas(self) -> list:
"""
Return the order book delta instruments subscribed to.
Returns
-------
list[InstrumentId]
"""
...
def subscribed_order_book_snapshots(self) -> list:
"""
Return the order book snapshot instruments subscribed to.
Returns
-------
list[InstrumentId]
"""
...
def subscribed_quote_ticks(self) -> list:
"""
Return the quote tick instruments subscribed to.
Returns
-------
list[InstrumentId]
"""
...
def subscribed_trade_ticks(self) -> list:
"""
Return the trade tick instruments subscribed to.
Returns
-------
list[InstrumentId]
"""
...
@property
def trader_id(self) -> TraderId:
"""
The trader ID associated with the component.
Returns
-------
TraderId
"""
...
@property
def type(self) -> type:
"""
The components type.
Returns
-------
type
"""
...
def unsubscribe(self, data_type: DataType) -> void:
"""
Unsubscribe from data for the given data type.
Parameters
----------
data_type : DataType
The data type for the subscription.
# 订阅的数据类型。
"""
...
def unsubscribe_bars(self, bar_type: BarType) -> void:
"""
Unsubscribe from Bar data for the given bar type.
Parameters
----------
bar_type : BarType
The bar type to unsubscribe from.
# 要取消订阅的K线类型。
"""
...
def unsubscribe_instrument(self, instrument_id: InstrumentId) -> void:
"""
Unsubscribe from Instrument data for the given instrument ID.
Parameters
----------
instrument_id : InstrumentId
The instrument to unsubscribe from.
# 要取消订阅的Instrument。
"""
...
def unsubscribe_instrument_close(self, instrument_id: InstrumentId) -> void:
"""
Unsubscribe from InstrumentClose data for the given instrument ID.
Parameters
----------
instrument_id : InstrumentId
The tick instrument to unsubscribe from.
# 要取消订阅的报价Instrument。
"""
...
def unsubscribe_instrument_status(self, instrument_id: InstrumentId) -> void:
"""
Unsubscribe from InstrumentStatus data for the given instrument ID.
Parameters
----------
instrument_id : InstrumentId
The instrument status updates to unsubscribe from.
# 要取消订阅的Instrument状态更新。
"""
...
def unsubscribe_instruments(self) -> void:
"""
Unsubscribe from all Instrument data.
# 取消订阅所有Instrument数据。
"""
...
def unsubscribe_order_book_deltas(self, instrument_id: InstrumentId) -> void:
"""
Unsubscribe from OrderBookDeltas data for the given instrument ID.
Parameters
----------
instrument_id : InstrumentId
The order book instrument to unsubscribe from.
# 要取消订阅的订单簿Instrument。
"""
...
def unsubscribe_order_book_snapshots(self, instrument_id: InstrumentId) -> void:
"""
Unsubscribe from OrderBook snapshots data for the given instrument ID.
Parameters
----------
instrument_id : InstrumentId
The order book instrument to unsubscribe from.
# 要取消订阅的订单簿Instrument。
"""
...
def unsubscribe_quote_ticks(self, instrument_id: InstrumentId) -> void:
"""
Unsubscribe from QuoteTick data for the given instrument ID.
Parameters
----------
instrument_id : InstrumentId
The tick instrument to unsubscribe from.
# 要取消订阅的报价Instrument。
"""
...
def unsubscribe_trade_ticks(self, instrument_id: InstrumentId) -> void:
"""
Unsubscribe from TradeTick data for the given instrument ID.
Parameters
----------
instrument_id : InstrumentId
The tick instrument to unsubscribe from.
# 要取消订阅的交易Instrument。
"""
...
@property
def venue(self) -> Venue | None:
"""
The clients venue ID (if applicable).
Returns
-------
Venue or None
"""
...