Data 数据 - Loren1166/NautilusTrader- GitHub Wiki
Data 数据
The data subpackage groups components relating to the data stack and data tooling for the platform.
数据子包对与平台的数据栈和数据工具相关的组件进行分组。
The layered architecture of the data stack somewhat mirrors the execution stack with a central engine, cache layer beneath, database layer beneath, with alternative implementations able to be written on top.
数据栈的分层架构有点类似于执行栈,它有一个中央引擎,下方是缓存层,下方是数据库层,可以在顶部编写替代实现。
Due to the high-performance, the core components are reusable between both backtest and live implementations - helping to ensure consistent logic for trading operations.
由于高性能,核心组件在回测和实时实现之间可重用 - 有助于确保交易操作的逻辑一致性。
Aggregation 聚合
class BarAggregator 条形聚合器
class BarAggregator(object):
"""
Provides a means of aggregating specified bars and sending to a registered handler.
提供一种聚合指定条形图并将它们发送到注册处理程序的方法。
Parameters:
参数:
instrument (Instrument) – The instrument for the aggregator.
instrument (Instrument) - 聚合器的金融工具。
bar_type (BarType) – The bar type for the aggregator.
bar_type (BarType) - 聚合器的条形图类型。
handler (Callable [ [Bar ] , None ]) – The bar handler for the aggregator.
handler (Callable [[Bar],None]) - 聚合器的条形图处理程序。
await_partial (bool , default False) – If the aggregator should await an initial partial bar prior to aggregating.
await_partial (bool,默认 False) - 聚合器是否应在聚合之前等待初始部分条形图。
Raises: ValueError – If instrument.id != bar_type.instrument_id.
引发:ValueError - 如果 instrument.id != bar_type.instrument_id。
"""
def __init__(self, instrument: Instrument, bar_type: BarType, handler: Callable[[Bar], None], await_partial: bool = False):
...
@property
def bar_type(self) -> BarType:
"""
The aggregators bar type.
聚合器的条形图类型。
Returns:
BarType
"""
...
def handle_bar(self, bar: Bar) -> void:
"""
Update the aggregator with the given bar.
使用给定的条形图更新聚合器。
Parameters: bar (Bar) – The bar for the update.
参数:bar (Bar) - 用于更新的条形图。
"""
...
def handle_quote_tick(self, tick: QuoteTick) -> void:
"""
Update the aggregator with the given tick.
使用给定的报价更新聚合器。
Parameters: tick (QuoteTick) – The tick for the update.
参数:tick (QuoteTick) - 用于更新的报价。
"""
...
def handle_trade_tick(self, tick: TradeTick) -> void:
"""
Update the aggregator with the given tick.
使用给定的交易更新聚合器。
Parameters: tick (TradeTick) – The tick for the update.
参数:tick (TradeTick) - 用于更新的交易。
"""
...
def set_await_partial(self, value: bool):
"""
"""
...
def set_partial(self, partial_bar: Bar) -> void:
"""
Set the initial values for a partially completed bar.
为部分完成的条形图设置初始值。
This method can only be called once per instance.
此方法每个实例只能调用一次。
Parameters: partial_bar (Bar) – The partial bar with values to set.
参数:partial_bar (Bar) - 要设置值的局部条形图。
"""
...
class BarBuilder 条形图构建器
class BarBuilder(object):
"""
Provides a generic bar builder for aggregation.
为聚合提供通用的条形图构建器。
Parameters:
参数:
instrument (Instrument) – The instrument for the builder.
instrument (Instrument) - 构建器的金融工具。
bar_type (BarType) – The bar type for the builder.
bar_type (BarType) - 构建器的条形图类型。
Raises: ValueError – If instrument.id != bar_type.instrument_id.
引发:ValueError - 如果 instrument.id != bar_type.instrument_id。
"""
def __init__(self, instrument: Instrument, bar_type: BarType):
...
@property
def count(self):
"""
The builders current update count.
构建器的当前更新计数。
Returns:
int
"""
...
@property
def initialized(self):
"""
If the builder is initialized.
构建器是否已初始化。
Returns:
bool
"""
...
@property
def price_precision(self):
"""
The price precision for the builders instrument.
构建器金融工具的价格精度。
Returns:
uint8
"""
...
@property
def size_precision(self):
"""
The size precision for the builders instrument.
构建器金融工具的大小精度。
Returns:
uint8
"""
...
@property
def ts_last(self) -> int:
"""
UNIX timestamp (nanoseconds) when the builder last updated.
构建器上次更新时的 UNIX 时间戳(纳秒)。
Returns:
uint64_t
"""
...
def build(self, ts_event: int, ts_init: int) -> Bar:
"""
Return the aggregated bar with the given closing timestamp, and reset.
返回具有给定结束时间戳的聚合条形图,并重置。
Parameters:
参数:
ts_event (uint64_t) – UNIX timestamp (nanoseconds) for the bar event.
ts_event (uint64_t) - 条形图事件的 UNIX 时间戳(纳秒)。
ts_init (uint64_t) – UNIX timestamp (nanoseconds) for the bar initialization.
ts_init (uint64_t) - 条形图初始化的 UNIX 时间戳(纳秒)。
Return type: Bar
"""
...
def build_now(self) -> Bar:
"""
Return the aggregated bar and reset.
返回聚合条形图并重置。
Return type: Bar
"""
...
def reset(self) -> void:
"""
Reset the bar builder.
重置条形图构建器。
All stateful fields are reset to their initial value.
所有有状态字段都重置为其初始值。
"""
...
def set_partial(self, partial_bar: Bar) -> void:
"""
Set the initial values for a partially completed bar.
为部分完成的条形图设置初始值。
This method can only be called once per instance.
此方法每个实例只能调用一次。
Parameters: partial_bar (Bar) – The partial bar with values to set.
参数:partial_bar (Bar) - 要设置值的局部条形图。
"""
...
def update(self, price: Price, size: Quantity, ts_event: int) -> void:
"""
Update the bar builder.
更新条形图构建器。
Parameters:
参数:
price (Price) – The update price.
price (Price) - 更新价格。
size (Decimal) – The update size.
size (Decimal) - 更新大小。
ts_event (uint64_t) – UNIX timestamp (nanoseconds) of the update.
ts_event (uint64_t) - 更新的 UNIX 时间戳(纳秒)。
"""
...
def update_bar(self, bar: Bar, volume: Quantity, ts_init: int) -> void:
"""
Update the bar builder.
更新条形图构建器。
Parameters:
参数:
bar (Bar) – The update Bar.
bar (Bar) - 更新的条形图。
"""
...
class TickBarAggregator 报价条形图聚合器
class TickBarAggregator(BarAggregator):
"""
Provides a means of building tick bars from ticks.
提供一种从报价构建报价条形图的方法。
When received tick count reaches the step threshold of the bar specification, then a bar is created and sent to the handler.
当接收到的报价计数达到条形图规范的步长阈值时,将创建一个条形图并将其发送到处理程序。
Parameters:
参数:
instrument (Instrument) – The instrument for the aggregator.
instrument (Instrument) - 聚合器的金融工具。
bar_type (BarType) – The bar type for the aggregator.
bar_type (BarType) - 聚合器的条形图类型。
handler (Callable [ [Bar ] , None ]) – The bar handler for the aggregator.
handler (Callable [[Bar],None]) - 聚合器的条形图处理程序。
Raises: ValueError – If instrument.id != bar_type.instrument_id.
引发:ValueError - 如果 instrument.id != bar_type.instrument_id。
"""
def __init__(self, instrument: Instrument, bar_type: BarType, handler: Callable[[Bar], None]):
...
@property
def bar_type(self) -> BarType:
"""
The aggregators bar type.
聚合器的条形图类型。
Returns:
BarType
"""
...
def handle_bar(self, bar: Bar) -> void:
"""
Update the aggregator with the given bar.
使用给定的条形图更新聚合器。
Parameters: bar (Bar) – The bar for the update.
参数:bar (Bar) - 用于更新的条形图。
"""
...
def handle_quote_tick(self, tick: QuoteTick) -> void:
"""
Update the aggregator with the given tick.
使用给定的报价更新聚合器。
Parameters: tick (QuoteTick) – The tick for the update.
参数:tick (QuoteTick) - 用于更新的报价。
"""
...
def handle_trade_tick(self, tick: TradeTick) -> void:
"""
Update the aggregator with the given tick.
使用给定的交易更新聚合器。
Parameters: tick (TradeTick) – The tick for the update.
参数:tick (TradeTick) - 用于更新的交易。
"""
...
def set_await_partial(self, value: bool):
"""
"""
...
def set_partial(self, partial_bar: Bar) -> void:
"""
Set the initial values for a partially completed bar.
为部分完成的条形图设置初始值。
This method can only be called once per instance.
此方法每个实例只能调用一次。
Parameters: partial_bar (Bar) – The partial bar with values to set.
参数:partial_bar (Bar) - 要设置值的局部条形图。
"""
...
class TimeBarAggregator 时间条形图聚合器
class TimeBarAggregator(BarAggregator):
"""
Provides a means of building time bars from ticks with an internal timer.
提供一种使用内部计时器从报价构建时间条形图的方法。
When the time reaches the next time interval of the bar specification, then a bar is created and sent to the handler.
当时间达到条形图规范的下一个时间间隔时,将创建一个条形图并将其发送到处理程序。
Parameters:
参数:
instrument (Instrument) – The instrument for the aggregator.
instrument (Instrument) - 聚合器的金融工具。
bar_type (BarType) – The bar type for the aggregator.
bar_type (BarType) - 聚合器的条形图类型。
handler (Callable [ [Bar ] , None ]) – The bar handler for the aggregator.
handler (Callable [[Bar],None]) - 聚合器的条形图处理程序。
clock (Clock) – The clock for the aggregator.
clock (Clock) - 聚合器的时钟。
build_with_no_updates (bool , default True) – If build and emit bars with no new market updates.
build_with_no_updates (bool,默认 True) - 是否在没有新的市场更新的情况下构建和发送条形图。
timestamp_on_close (bool , default True) – If timestamp ts_event will be bar close. If False then timestamp will be bar open.
timestamp_on_close (bool,默认 True) - 时间戳 ts_event 是否为条形图关闭时间。如果为 False,则时间戳将为条形图打开时间。
interval_type (str , default 'left-open') – Determines the type of interval used for time aggregation.
interval_type (str,默认 'left-open') - 确定用于时间聚合的间隔类型。
‘left-open’: start time is excluded and end time is included (default).
'left-open':开始时间不包括在内,结束时间包括在内(默认)。
‘right-open’: start time is included and end time is excluded.
'right-open':开始时间包括在内,结束时间不包括在内。
Raises: ValueError – If instrument.id != bar_type.instrument_id.
引发:ValueError - 如果 instrument.id != bar_type.instrument_id。
"""
def __init__(self, instrument: Instrument, bar_type: BarType, handler: Callable[[Bar], None], clock: Clock, build_with_no_updates: bool = True, timestamp_on_close: bool = True, interval_type: str = 'left-open'):
...
@property
def bar_type(self) -> BarType:
"""
The aggregators bar type.
聚合器的条形图类型。
Returns:
BarType
"""
...
@property
def interval(self) -> timedelta:
"""
The aggregators time interval.
聚合器的时间间隔。
Returns:
timedelta
"""
...
@property
def interval_ns(self) -> int:
"""
The aggregators time interval.
聚合器的时间间隔。
Returns:
uint64_t
"""
...
@property
def next_close_ns(self) -> int:
"""
The aggregators next closing time.
聚合器的下一个结束时间。
Returns:
uint64_t
"""
...
def get_start_time(self) -> datetime:
"""
Return the start time for the aggregators next bar.
返回聚合器下一个条形图的开始时间。
Returns: The timestamp (UTC).
返回值:时间戳 (UTC)。
Return type: datetime
"""
...
def handle_bar(self, bar: Bar) -> void:
"""
Update the aggregator with the given bar.
使用给定的条形图更新聚合器。
Parameters: bar (Bar) – The bar for the update.
参数:bar (Bar) - 用于更新的条形图。
"""
...
def handle_quote_tick(self, tick: QuoteTick) -> void:
"""
Update the aggregator with the given tick.
使用给定的报价更新聚合器。
Parameters: tick (QuoteTick) – The tick for the update.
参数:tick (QuoteTick) - 用于更新的报价。
"""
...
def handle_trade_tick(self, tick: TradeTick) -> void:
"""
Update the aggregator with the given tick.
使用给定的交易更新聚合器。
Parameters: tick (TradeTick) – The tick for the update.
参数:tick (TradeTick) - 用于更新的交易。
"""
...
def set_await_partial(self, value: bool):
"""
"""
...
def set_partial(self, partial_bar: Bar) -> void:
"""
Set the initial values for a partially completed bar.
为部分完成的条形图设置初始值。
This method can only be called once per instance.
此方法每个实例只能调用一次。
Parameters: partial_bar (Bar) – The partial bar with values to set.
参数:partial_bar (Bar) - 要设置值的局部条形图。
"""
...
def stop(self) -> void:
"""
Stop the bar aggregator.
停止条形图聚合器。
"""
...
class ValueBarAggregator 价值条形图聚合器
class ValueBarAggregator(BarAggregator):
"""
Provides a means of building value bars from ticks.
提供一种从报价构建价值条形图的方法。
When received value reaches the step threshold of the bar specification, then a bar is created and sent to the handler.
当接收到的值达到条形图规范的步长阈值时,将创建一个条形图并将其发送到处理程序。
Parameters:
参数:
instrument (Instrument) – The instrument for the aggregator.
instrument (Instrument) - 聚合器的金融工具。
bar_type (BarType) – The bar type for the aggregator.
bar_type (BarType) - 聚合器的条形图类型。
handler (Callable [ [Bar ] , None ]) – The bar handler for the aggregator.
handler (Callable [[Bar],None]) - 聚合器的条形图处理程序。
Raises: ValueError – If instrument.id != bar_type.instrument_id.
引发:ValueError - 如果 instrument.id != bar_type.instrument_id。
"""
def __init__(self, instrument: Instrument, bar_type: BarType, handler: Callable[[Bar], None]):
...
@property
def bar_type(self) -> BarType:
"""
The aggregators bar type.
聚合器的条形图类型。
Returns:
BarType
"""
...
def get_cumulative_value(self):
"""
Return the current cumulative value of the aggregator.
返回聚合器的当前累积值。
Return type: Decimal
"""
...
def handle_bar(self, bar: Bar) -> void:
"""
Update the aggregator with the given bar.
使用给定的条形图更新聚合器。
Parameters: bar (Bar) – The bar for the update.
参数:bar (Bar) - 用于更新的条形图。
"""
...
def handle_quote_tick(self, tick: QuoteTick) -> void:
"""
Update the aggregator with the given tick.
使用给定的报价更新聚合器。
Parameters: tick (QuoteTick) – The tick for the update.
参数:tick (QuoteTick) - 用于更新的报价。
"""
...
def handle_trade_tick(self, tick: TradeTick) -> void:
"""
Update the aggregator with the given tick.
使用给定的交易更新聚合器。
Parameters: tick (TradeTick) – The tick for the update.
参数:tick (TradeTick) - 用于更新的交易。
"""
...
def set_await_partial(self, value: bool):
"""
"""
...
def set_partial(self, partial_bar: Bar) -> void:
"""
Set the initial values for a partially completed bar.
为部分完成的条形图设置初始值。
This method can only be called once per instance.
此方法每个实例只能调用一次。
Parameters: partial_bar (Bar) – The partial bar with values to set.
参数:partial_bar (Bar) - 要设置值的局部条形图。
"""
...
class VolumeBarAggregator 成交量条形图聚合器
class VolumeBarAggregator(BarAggregator):
"""
Provides a means of building volume bars from ticks.
提供一种从报价构建成交量条形图的方法。
When received volume reaches the step threshold of the bar specification, then a bar is created and sent to the handler.
当接收到的成交量达到条形图规范的步长阈值时,将创建一个条形图并将其发送到处理程序。
Parameters:
参数:
instrument (Instrument) – The instrument for the aggregator.
instrument (Instrument) - 聚合器的金融工具。
bar_type (BarType) – The bar type for the aggregator.
bar_type (BarType) - 聚合器的条形图类型。
handler (Callable [ [Bar ] , None ]) – The bar handler for the aggregator.
handler (Callable [[Bar],None]) - 聚合器的条形图处理程序。
Raises: ValueError – If instrument.id != bar_type.instrument_id.
引发:ValueError - 如果 instrument.id != bar_type.instrument_id。
"""
def __init__(self, instrument: Instrument, bar_type: BarType, handler: Callable[[Bar], None]):
...
@property
def bar_type(self) -> BarType:
"""
The aggregators bar type.
聚合器的条形图类型。
Returns:
BarType
"""
...
def handle_bar(self, bar: Bar) -> void:
"""
Update the aggregator with the given bar.
使用给定的条形图更新聚合器。
Parameters: bar (Bar) – The bar for the update.
参数:bar (Bar) - 用于更新的条形图。
"""
...
def handle_quote_tick(self, tick: QuoteTick) -> void:
"""
Update the aggregator with the given tick.
使用给定的报价更新聚合器。
Parameters: tick (QuoteTick) – The tick for the update.
参数:tick (QuoteTick) - 用于更新的报价。
"""
...
def handle_trade_tick(self, tick: TradeTick) -> void:
"""
Update the aggregator with the given tick.
使用给定的交易更新聚合器。
Parameters: tick (TradeTick) – The tick for the update.
参数:tick (TradeTick) - 用于更新的交易。
"""
...
def set_await_partial(self, value: bool):
"""
"""
...
def set_partial(self, partial_bar: Bar) -> void:
"""
Set the initial values for a partially completed bar.
为部分完成的条形图设置初始值。
This method can only be called once per instance.
此方法每个实例只能调用一次。
Parameters: partial_bar (Bar) – The partial bar with values to set.
参数:partial_bar (Bar) - 要设置值的局部条形图。
"""
...
Client 客户端
class DataClient 数据客户端
class DataClient(Component):
"""
The base class for all data clients.
所有数据客户端的基类。
Parameters:
参数:
client_id (ClientId) – The data client ID.
client_id (ClientId) - 数据客户端 ID。
msgbus (MessageBus) – The message bus for the client.
msgbus (MessageBus) - 客户端的消息总线。
clock (Clock) – The clock for the client.
clock (Clock) - 客户端的时钟。
venue (Venue , optional) – The client venue. If multi-venue then can be None.
venue (Venue,可选) - 客户端场所。如果是多场所,则可以为 None。
config (NautilusConfig , optional) – The configuration for the instance.
config (NautilusConfig,可选) - 实例的配置。
Warning:
This class should not be used directly, but through a concrete subclass.
此类不应直接使用,而应通过具体的子类使用。
"""
def __init__(self, client_id: ClientId, msgbus: MessageBus, cache: Cache, clock: Clock, venue: Venue | None = None, config: NautilusConfig | None = None):
...
@property
def id(self) -> ComponentId:
"""
The components ID.
组件 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
"""
...
@property
def state(self) -> ComponentState:
"""
ComponentState
Return the components current state.
返回组件的当前状态。
Return type: ComponentState
Type: Component.state
"""
...
@property
def trader_id(self):
"""
The trader ID associated with the component.
与组件关联的交易者 ID。
Returns:
TraderId
"""
...
@property
def type(self):
"""
The components type.
组件类型。
Returns:
type
"""
...
@property
def venue(self):
"""
The clients venue ID (if applicable).
客户端的场所 ID(如果适用)。
Returns:
Venue or None
"""
...
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.
警告:
不要覆盖。
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 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.
警告:
不要覆盖。
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.
警告:
不要覆盖。
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.
返回组件类的完全限定名称。
Return type: str
"""
...
def request(self, data_type, correlation_id: UUID4) -> void:
"""
Request data for the given data type.
请求给定数据类型的数据。
Parameters:
参数:
data_type (DataType) – The data type for the subscription.
data_type (DataType) - 订阅的数据类型。
correlation_id (UUID4) – The correlation ID for the response.
correlation_id (UUID4) - 响应的相关 ID。
"""
...
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.
警告:
不要覆盖。
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.
警告:
不要覆盖。
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 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.
警告:
不要覆盖。
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 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.
警告:
不要覆盖。
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) -> void:
"""
Subscribe to data for the given data type.
订阅给定数据类型的数据。
Parameters: data_type (DataType) – The data type for the subscription.
参数:data_type (DataType) - 订阅的数据类型。
"""
...
def subscribed_custom_data(self) -> list:
"""
Return the custom data types subscribed to.
返回订阅的自定义数据类型。
Return type: list[DataType]
"""
...
def unsubscribe(self, data_type) -> void:
"""
Unsubscribe from data for the given data type.
取消订阅给定数据类型的数据。
Parameters: data_type (DataType) – The data type for the subscription.
参数:data_type (DataType) - 订阅的数据类型。
"""
...
class MarketDataClient 市场数据客户端
class MarketDataClient(DataClient):
"""
The base class for all market data clients.
所有市场数据客户端的基类。
Parameters:
参数:
client_id (ClientId) – The data client ID.
client_id (ClientId) - 数据客户端 ID。
msgbus (MessageBus) – The message bus for the client.
msgbus (MessageBus) - 客户端的消息总线。
cache (Cache) – The cache for the client.
cache (Cache) - 客户端的缓存。
clock (Clock) – The clock for the client.
clock (Clock) - 客户端的时钟。
venue (Venue , optional) – The client venue. If multi-venue then can be None.
venue (Venue,可选) - 客户端场所。如果是多场所,则可以为 None。
```python
config (NautilusConfig , optional) – The configuration for the instance.
config (NautilusConfig,可选) - 实例的配置。
Warning:
This class should not be used directly, but through a concrete subclass.
此类不应直接使用,而应通过具体的子类使用。
"""
def __init__(self, client_id: ClientId, msgbus: MessageBus, cache: Cache, clock: Clock, venue: Venue | None = None, config: NautilusConfig | None = None):
...
@property
def id(self) -> ComponentId:
"""
The components ID.
组件 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
"""
...
@property
def state(self) -> ComponentState:
"""
ComponentState
Return the components current state.
返回组件的当前状态。
Return type: ComponentState
Type: Component.state
"""
...
@property
def trader_id(self):
"""
The trader ID associated with the component.
与组件关联的交易者 ID。
Returns:
TraderId
"""
...
@property
def type(self):
"""
The components type.
组件类型。
Returns:
type
"""
...
@property
def venue(self):
"""
The clients venue ID (if applicable).
客户端的场所 ID(如果适用)。
Returns:
Venue or None
"""
...
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.
警告:
不要覆盖。
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 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.
警告:
不要覆盖。
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.
警告:
不要覆盖。
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.
返回组件类的完全限定名称。
Return type: str
"""
...
def request(self, data_type, correlation_id: UUID4) -> void:
"""
Request data for the given data type.
请求给定数据类型的数据。
Parameters:
参数:
data_type (DataType) – The data type for the subscription.
data_type (DataType) - 订阅的数据类型。
correlation_id (UUID4) – The correlation ID for the response.
correlation_id (UUID4) - 响应的相关 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.
bar_type (BarType) - 请求的条形图类型。
limit (int) – The limit for the number of returned bars.
limit (int) - 返回条形图数量的限制。
correlation_id (UUID4) – The correlation ID for the request.
correlation_id (UUID4) - 请求的相关 ID。
start (datetime , optional) – The start datetime (UTC) of request time range (inclusive).
start (datetime,可选) - 请求时间范围的开始日期时间(UTC)(含)。
end (datetime , optional) – The end datetime (UTC) of request time range. The inclusiveness depends on individual data client implementation.
end (datetime,可选) - 请求时间范围的结束日期时间(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.
请求给定金融工具 ID 的金融工具数据。
Parameters:
参数:
instrument_id (InstrumentId) – The instrument ID for the request.
instrument_id (InstrumentId) - 请求的金融工具 ID。
correlation_id (UUID4) – The correlation ID for the request.
correlation_id (UUID4) - 请求的相关 ID。
start (datetime , optional) – The start datetime (UTC) of request time range (inclusive).
start (datetime,可选) - 请求时间范围的开始日期时间(UTC)(含)。
end (datetime , optional) – The end datetime (UTC) of request time range. The inclusiveness depends on individual data client implementation.
end (datetime,可选) - 请求时间范围的结束日期时间(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.
venue (Venue) - 请求的场所。
correlation_id (UUID4) – The correlation ID for the request.
correlation_id (UUID4) - 请求的相关 ID。
start (datetime , optional) – The start datetime (UTC) of request time range (inclusive).
start (datetime,可选) - 请求时间范围的开始日期时间(UTC)(含)。
end (datetime , optional) – The end datetime (UTC) of request time range. The inclusiveness depends on individual data client implementation.
end (datetime,可选) - 请求时间范围的结束日期时间(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 (InstrumentId) - 订单簿快照请求的金融工具 ID。
limit (int) – The limit on the depth of the order book snapshot.
limit (int) - 订单簿快照深度的限制。
correction_id (UUID4) – The correlation ID for the request.
correction_id (UUID4) - 请求的相关 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 (InstrumentId) - 请求的报价金融工具 ID。
limit (int) – The limit for the number of returned ticks.
limit (int) - 返回报价数量的限制。
correlation_id (UUID4) – The correlation ID for the request.
correlation_id (UUID4) - 请求的相关 ID。
start (datetime , optional) – The start datetime (UTC) of request time range (inclusive).
start (datetime,可选) - 请求时间范围的开始日期时间(UTC)(含)。
end (datetime , optional) – The end datetime (UTC) of request time range. The inclusiveness depends on individual data client implementation.
end (datetime,可选) - 请求时间范围的结束日期时间(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 (InstrumentId) - 请求的交易金融工具 ID。
limit (int) – The limit for the number of returned ticks.
limit (int) - 返回交易数量的限制。
correlation_id (UUID4) – The correlation ID for the request.
correlation_id (UUID4) - 请求的相关 ID。
start (datetime , optional) – The start datetime (UTC) of request time range (inclusive).
start (datetime,可选) - 请求时间范围的开始日期时间(UTC)(含)。
end (datetime , optional) – The end datetime (UTC) of request time range. The inclusiveness depends on individual data client implementation.
end (datetime,可选) - 请求时间范围的结束日期时间(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.
警告:
不要覆盖。
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.
警告:
不要覆盖。
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 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.
警告:
不要覆盖。
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 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.
警告:
不要覆盖。
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) -> void:
"""
Subscribe to data for the given data type.
订阅给定数据类型的数据。
Parameters: data_type (DataType) – The data type for the subscription.
参数:data_type (DataType) - 订阅的数据类型。
"""
...
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.
参数:bar_type (BarType) - 要订阅的条形图类型。
"""
...
def subscribe_instrument(self, instrument_id: InstrumentId) -> void:
"""
Subscribe to the Instrument with the given instrument ID.
订阅具有给定金融工具 ID 的金融工具。
"""
...
def subscribe_instrument_close(self, instrument_id: InstrumentId) -> void:
"""
Subscribe to InstrumentClose updates for the given instrument ID.
订阅给定金融工具 ID 的 InstrumentClose 更新。
Parameters: instrument_id (InstrumentId) – The tick instrument to subscribe to.
参数:instrument_id (InstrumentId) - 要订阅的报价金融工具。
"""
...
def subscribe_instrument_status(self, instrument_id: InstrumentId) -> void:
"""
Subscribe to InstrumentStatus data for the given instrument ID.
订阅给定金融工具 ID 的 InstrumentStatus 数据。
Parameters: instrument_id (InstrumentId) – The tick instrument to subscribe to.
参数:instrument_id (InstrumentId) - 要订阅的报价金融工具。
"""
...
def subscribe_instruments(self) -> void:
"""
Subscribe to all Instrument data.
订阅所有金融工具数据。
"""
...
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.
订阅给定金融工具 ID 的 OrderBookDeltas 数据。
Parameters:
参数:
instrument_id (InstrumentId) – The order book instrument to subscribe to.
instrument_id (InstrumentId) - 要订阅的订单簿金融工具。
book_type (BookType {L1_MBP, L2_MBP, L3_MBO}) – The order book type.
book_type (BookType {L1_MBP, L2_MBP, L3_MBO}) - 订单簿类型。
depth (int , optional , default None) – The maximum depth for the subscription.
depth (int,可选,默认 None) - 订阅的最大深度。
kwargs (dict , optional) – The keyword arguments for exchange specific parameters.
kwargs (dict,可选) - 交换特定参数的关键字参数。
"""
...
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.
订阅给定金融工具 ID 的 OrderBook 快照数据。
Parameters:
参数:
instrument_id (InstrumentId) – The order book instrument to subscribe to.
instrument_id (InstrumentId) - 要订阅的订单簿金融工具。
book_type (BookType {L1_MBP, L2_MBP, L3_MBO}) – The order book level.
book_type (BookType {L1_MBP, L2_MBP, L3_MBO}) - 订单簿级别。
depth (int , optional) – The maximum depth for the order book. A depth of 0 is maximum depth.
depth (int,可选) - 订单簿的最大深度。深度为 0 表示最大深度。
kwargs (dict , optional) – The keyword arguments for exchange specific parameters.
kwargs (dict,可选) - 交换特定参数的关键字参数。
"""
...
def subscribe_quote_ticks(self, instrument_id: InstrumentId) -> void:
"""
Subscribe to QuoteTick data for the given instrument ID.
订阅给定金融工具 ID 的报价数据。
Parameters: instrument_id (InstrumentId) – The tick instrument to subscribe to.
参数:instrument_id (InstrumentId) - 要订阅的报价金融工具。
"""
...
def subscribe_trade_ticks(self, instrument_id: InstrumentId) -> void:
"""
Subscribe to TradeTick data for the given instrument ID.
订阅给定金融工具 ID 的交易数据。
Parameters: instrument_id (InstrumentId) – The tick instrument to subscribe to.
参数:instrument_id (InstrumentId) - 要订阅的交易金融工具。
"""
...
def subscribed_bars(self) -> list:
"""
Return the bar types subscribed to.
返回订阅的条形图类型。
Return type: list[BarType]
"""
...
def subscribed_custom_data(self) -> list:
"""
Return the custom data types subscribed to.
返回订阅的自定义数据类型。
Return type: list[DataType]
"""
...
def subscribed_instrument_close(self) -> list:
"""
Return the instrument closes subscribed to.
返回订阅的金融工具收盘价。
Return type: list[InstrumentId]
"""
...
def subscribed_instrument_status(self) -> list:
"""
Return the status update instruments subscribed to.
返回订阅的状态更新金融工具。
Return type: list[InstrumentId]
"""
...
def subscribed_instruments(self) -> list:
"""
Return the instruments subscribed to.
返回订阅的金融工具。
Return type: list[InstrumentId]
"""
...
def subscribed_order_book_deltas(self) -> list:
"""
Return the order book delta instruments subscribed to.
返回订阅的订单簿增量金融工具。
Return type: list[InstrumentId]
"""
...
def subscribed_order_book_snapshots(self) -> list:
"""
Return the order book snapshot instruments subscribed to.
返回订阅的订单簿快照金融工具。
Return type: list[InstrumentId]
"""
...
def subscribed_quote_ticks(self) -> list:
"""
Return the quote tick instruments subscribed to.
返回订阅的报价金融工具。
Return type: list[InstrumentId]
"""
...
def subscribed_trade_ticks(self) -> list:
"""
Return the trade tick instruments subscribed to.
返回订阅的交易金融工具。
Return type: list[InstrumentId]
"""
...
def unsubscribe(self, data_type) -> void:
"""
Unsubscribe from data for the given data type.
取消订阅给定数据类型的数据。
Parameters: data_type (DataType) – The data type for the subscription.
参数:data_type (DataType) - 订阅的数据类型。
"""
...
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.
参数:bar_type (BarType) - 要取消订阅的条形图类型。
"""
...
def unsubscribe_instrument(self, instrument_id: InstrumentId) -> void:
"""
Unsubscribe from Instrument data for the given instrument ID.
取消订阅给定金融工具 ID 的金融工具数据。
Parameters: instrument_id (InstrumentId) – The instrument to unsubscribe from.
参数:instrument_id (InstrumentId) - 要取消订阅的金融工具。
"""
...
def unsubscribe_instrument_close(self, instrument_id: InstrumentId) -> void:
"""
Unsubscribe from InstrumentClose data for the given instrument ID.
取消订阅给定金融工具 ID 的 InstrumentClose 数据。
Parameters: instrument_id (InstrumentId) – The tick instrument to unsubscribe from.
参数:instrument_id (InstrumentId) - 要取消订阅的报价金融工具。
"""
...
def unsubscribe_instrument_status(self, instrument_id: InstrumentId) -> void:
"""
Unsubscribe from InstrumentStatus data for the given instrument ID.
取消订阅给定金融工具 ID 的 InstrumentStatus 数据。
Parameters: instrument_id (InstrumentId) – The instrument status updates to unsubscribe from.
参数:instrument_id (InstrumentId) - 要取消订阅的金融工具状态更新。
"""
...
def unsubscribe_instruments(self) -> void:
"""
Unsubscribe from all Instrument data.
取消订阅所有金融工具数据。
"""
...
def unsubscribe_order_book_deltas(self, instrument_id: InstrumentId) -> void:
"""
Unsubscribe from OrderBookDeltas data for the given instrument ID.
取消订阅给定金融工具 ID 的 OrderBookDeltas 数据。
Parameters: instrument_id (InstrumentId) – The order book instrument to unsubscribe from.
参数:instrument_id (InstrumentId) - 要取消订阅的订单簿金融工具。
"""
...
def unsubscribe_order_book_snapshots(self, instrument_id: InstrumentId) -> void:
"""
Unsubscribe from OrderBook snapshots data for the given instrument ID.
取消订阅给定金融工具 ID 的 OrderBook 快照数据。
Parameters: instrument_id (InstrumentId) – The order book instrument to unsubscribe from.
参数:instrument_id (InstrumentId) - 要取消订阅的订单簿金融工具。
"""
...
def unsubscribe_quote_ticks(self, instrument_id: InstrumentId) -> void:
"""
Unsubscribe from QuoteTick data for the given instrument ID.
取消订阅给定金融工具 ID 的报价数据。
Parameters: instrument_id (InstrumentId) – The tick instrument to unsubscribe from.
参数:instrument_id (InstrumentId) - 要取消订阅的报价金融工具。
"""
...
def unsubscribe_trade_ticks(self, instrument_id: InstrumentId) -> void:
"""
Unsubscribe from TradeTick data for the given instrument ID.
取消订阅给定金融工具 ID 的交易数据。
Parameters: instrument_id (InstrumentId) – The tick instrument to unsubscribe from.
参数:instrument_id (InstrumentId) - 要取消订阅的交易金融工具。
"""
...
Engine 引擎
The DataEngine is the central component of the entire data stack.
DataEngine 是整个数据栈的核心组件。
The data engines primary responsibility is to orchestrate interactions between the DataClient instances, and the rest of the platform. This includes sending requests to, and receiving responses from, data endpoints via its registered data clients.
数据引擎的主要职责是协调 DataClient 实例与平台其余部分之间的交互。这包括通过其注册的数据客户端向数据端点发送请求以及从数据端点接收响应。
The engine employs a simple fan-in fan-out messaging pattern to execute DataCommand type messages, and process DataResponse messages or market data objects.
引擎采用简单的扇入扇出消息传递模式来执行 DataCommand 类型消息,并处理 DataResponse 消息或市场数据对象。
Alternative implementations can be written on top of the generic engine - which just need to override the execute, process, send and receive methods.
可以在通用引擎之上编写替代实现 - 只需要覆盖 execute、process、send 和 receive 方法。
class DataEngine 数据引擎
class DataEngine(Component):
"""
Provides a high-performance data engine for managing many DataClient instances, for the asynchronous ingest of data.
提供一个高性能数据引擎,用于管理许多 DataClient 实例,以异步提取数据。
Parameters:
参数:
msgbus (MessageBus) – The message bus for the engine.
msgbus (MessageBus) - 引擎的消息总线。
cache (Cache) – The cache for the engine.
cache (Cache) - 引擎的缓存。
clock (Clock) – The clock for the engine.
clock (Clock) - 引擎的时钟。
config (DataEngineConfig , optional) – The configuration for the instance.
config (DataEngineConfig,可选) - 实例的配置。
"""
def __init__(self, msgbus: MessageBus, cache: Cache, clock: Clock, config: DataEngineConfig | None = None):
...
@property
def command_count(self):
"""
The total count of data commands received by the engine.
引擎接收到的数据命令总数。
Returns:
int
"""
...
@property
def data_count(self):
"""
The total count of data stream objects received by the engine.
引擎接收到的数据流对象总数。
Returns:
int
"""
...
@property
def debug(self):
"""
If debug mode is active (will provide extra debug logging).
如果调试模式处于活动状态(将提供额外的调试日志)。
Returns:
bool
"""
...
@property
def default_client(self):
"""
ClientId | None
Return the default data client registered with the engine.
返回在引擎中注册的默认数据客户端。
Return type: ClientId or None
Type: DataEngine.default_client
"""
...
@property
def id(self) -> ComponentId:
"""
The components ID.
组件 ID。
Returns:
ComponentId
"""
...
@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
"""
...
@property
def registered_clients(self) -> list[ClientId]:
"""
list[ClientId]
Return the execution clients registered with the engine.
返回在引擎中注册的执行客户端。
Return type: list[ClientId]
Type: DataEngine.registered_clients
"""
...
@property
def request_count(self):
"""
The total count of data requests received by the engine.
引擎接收到的数据请求总数。
Returns:
int
"""
...
@property
def response_count(self):
"""
The total count of data responses received by the engine.
引擎接收到的数据响应总数。
Returns:
int
"""
...
@property
def state(self) -> ComponentState:
"""
ComponentState
Return the components current state.
返回组件的当前状态。
Return type: ComponentState
Type: Component.state
"""
...
@property
def subscribed_bars(self) -> list:
"""
Return the bar types subscribed to.
返回订阅的条形图类型。
Return type: list[BarType]
"""
...
@property
def subscribed_custom_data(self) -> list:
"""
Return the custom data types subscribed to.
返回订阅的自定义数据类型。
Return type: list[DataType]
"""
...
@property
def subscribed_instrument_close(self) -> list:
"""
Return the close price instruments subscribed to.
返回订阅的收盘价金融工具。
Return type: list[InstrumentId]
"""
...
@property
def subscribed_instrument_status(self) -> list:
"""
Return the status update instruments subscribed to.
返回订阅的状态更新金融工具。
Return type: list[InstrumentId]
"""
...
@property
def subscribed_instruments(self) -> list:
"""
Return the instruments subscribed to.
返回订阅的金融工具。
Return type: list[InstrumentId]
"""
...
@property
def subscribed_order_book_deltas(self) -> list:
"""
Return the order book delta instruments subscribed to.
返回订阅的订单簿增量金融工具。
Return type: list[InstrumentId]
"""
...
@property
def subscribed_order_book_snapshots(self) -> list:
"""
Return the order book snapshot instruments subscribed to.
返回订阅的订单簿快照金融工具。
Return type: list[InstrumentId]
"""
...
@property
def subscribed_quote_ticks(self) -> list:
"""
Return the quote tick instruments subscribed to.
返回订阅的报价金融工具。
Return type: list[InstrumentId]
"""
...
@property
def subscribed_synthetic_quotes(self) -> list:
"""
Return the synthetic instrument quote ticks subscribed to.
返回订阅的合成金融工具报价。
Return type: list[InstrumentId]
"""
...
@property
def subscribed_synthetic_trades(self) -> list:
"""
Return the synthetic instrument trade ticks subscribed to.
返回订阅的合成金融工具交易。
Return type: list[InstrumentId]
"""
...
@property
def subscribed_trade_ticks(self) -> list:
"""
Return the trade tick instruments subscribed to.
返回订阅的交易金融工具。
Return type: list[InstrumentId]
"""
...
@property
def trader_id(self):
"""
The trader ID associated with the component.
与组件关联的交易者 ID。
Returns:
TraderId
"""
...
@property
def type(self):
"""
The components type.
组件类型。
Returns:
type
"""
...
def check_connected(self) -> bool:
"""
Check all of the engines clients are connected.
检查引擎的所有客户端是否已连接。
Returns: True if all clients connected, else False.
返回值:如果所有客户端都已连接,则返回 True,否则返回 False。
Return type: bool
"""
...
def check_disconnected(self) -> bool:
"""
Check all of the engines clients are disconnected.
检查引擎的所有客户端是否已断开连接。
Returns: True if all clients disconnected, else False.
返回值:如果所有客户端都已断开连接,则返回 True,否则返回 False。
Return type: bool
"""
...
def connect(self) -> None:
"""
Connect the engine by calling connect on all registered clients.
通过对所有注册的客户端调用 connect 来连接引擎。
"""
...
```python
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.
警告:
不要覆盖。
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 deregister_client(self, client: DataClient) -> void:
"""
Deregister the given data client from the data engine.
从数据引擎中取消注册给定的数据客户端。
Parameters: client (DataClient) – The data client to deregister.
参数:client (DataClient) - 要取消注册的数据客户端。
"""
...
def disconnect(self) -> None:
"""
Disconnect the engine by calling disconnect on all registered clients.
通过对所有注册的客户端调用 disconnect 来断开引擎连接。
"""
...
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.
警告:
不要覆盖。
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 execute(self, command: DataCommand) -> void:
"""
Execute the given data command.
执行给定的数据命令。
Parameters: command (DataCommand) – The command to execute.
参数:command (DataCommand) - 要执行的命令。
"""
...
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.
警告:
不要覆盖。
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.
返回组件类的完全限定名称。
Return type: str
"""
...
def process(self, data: Data) -> void:
"""
Process the given data.
处理给定的数据。
Parameters: data (Data) – The data to process.
参数:data (Data) - 要处理的数据。
"""
...
def register_catalog(self, catalog: ParquetDataCatalog) -> None:
"""
Register the given data catalog with the engine.
将给定的数据目录注册到引擎。
Parameters: catalog (ParquetDataCatalog) – The data catalog to register.
参数:catalog (ParquetDataCatalog) - 要注册的数据目录。
"""
...
def register_client(self, client: DataClient) -> void:
"""
Register the given data client with the data engine.
将给定的数据客户端注册到数据引擎。
Parameters: client (DataClient) – The client to register.
参数:client (DataClient) - 要注册的客户端。
Raises: ValueError – If client is already registered.
引发:ValueError - 如果客户端已注册。
"""
...
def register_default_client(self, client: DataClient) -> void:
"""
Register the given client as the default routing client (when a specific venue routing cannot be found).
将给定的客户端注册为默认路由客户端(当找不到特定的场所路由时)。
Any existing default routing client will be overwritten.
任何现有的默认路由客户端都将被覆盖。
Parameters: client (DataClient) – The client to register.
参数:client (DataClient) - 要注册的客户端。
"""
...
def register_venue_routing(self, client: DataClient, venue: Venue) -> void:
"""
Register the given client to route messages to the given venue.
注册给定的客户端以将消息路由到给定的场所。
Any existing client in the routing map for the given venue will be overwritten.
给定场所的路由映射中任何现有的客户端都将被覆盖。
Parameters:
参数:
venue (Venue) – The venue to route messages to.
venue (Venue) - 要将消息路由到的场所。
client (DataClient) – The client for the venue routing.
client (DataClient) - 用于场所路由的客户端。
"""
...
def request(self, request: DataRequest) -> void:
"""
Handle the given request.
处理给定的请求。
Parameters: request (DataRequest) – The request to handle.
参数:request (DataRequest) - 要处理的请求。
"""
...
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.
警告:
不要覆盖。
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 response(self, response: DataResponse) -> void:
"""
Handle the given response.
处理给定的响应。
Parameters: response (DataResponse) – The response to handle.
参数:response (DataResponse) - 要处理的响应。
"""
...
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.
警告:
不要覆盖。
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 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.
警告:
不要覆盖。
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 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.
警告:
不要覆盖。
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 stop_clients(self) -> void:
"""
Stop the registered clients.
停止注册的客户端。
"""
...
Messages 消息
class DataCommand 数据命令
class DataCommand(Command):
"""
The base class for all data commands.
所有数据命令的基类。
Parameters:
参数:
client_id (ClientId, optional with no default so None must be passed explicitly) – The data client ID for the command.
client_id (ClientId,可选,没有默认值,因此必须显式传递 None) - 命令的数据客户端 ID。
venue (Venue, optional with no default so None must be passed explicitly) – The venue for the command.
venue (Venue,可选,没有默认值,因此必须显式传递 None) - 命令的场所。
data_type (type) – The data type for the command.
data_type (type) - 命令的数据类型。
command_id (UUID4) – The command ID.
command_id (UUID4) - 命令 ID。
ts_init (uint64_t) – UNIX timestamp (nanoseconds) when the object was initialized.
ts_init (uint64_t) - 对象初始化时的 UNIX 时间戳(纳秒)。
Raises: ValueError – If both client_id and venue are both None (not enough routing info).
引发:ValueError - 如果 client_id 和 venue 均为 None(路由信息不足)。
Warning:
This class should not be used directly, but through a concrete subclass.
此类不应直接使用,而应通过具体的子类使用。
"""
def __init__(self, client_id: ClientId | None, venue: Venue | None, data_type, command_id: UUID4, ts_init: int):
...
@property
def client_id(self):
"""
The data client ID for the command.
命令的数据客户端 ID。
Returns:
ClientId or None
"""
...
@property
def data_type(self) -> type:
"""
The command data type.
命令的数据类型。
Returns:
type
"""
...
@property
def id(self) -> UUID4:
"""
The command message ID.
命令消息 ID。
Returns:
UUID4
"""
...
@property
def ts_init(self) -> int:
"""
UNIX timestamp (nanoseconds) when the object was initialized.
对象初始化时的 UNIX 时间戳(纳秒)。
Returns:
uint64_t
"""
...
@property
def venue(self):
"""
The venue for the command.
命令的场所。
Returns:
Venue or None
"""
...
class DataRequest 数据请求
class DataRequest(Request):
"""
Represents a request for data.
表示数据请求。
Parameters:
参数:
client_id (ClientId, optional with no default so None must be passed explicitly) – The data client ID for the request.
client_id (ClientId,可选,没有默认值,因此必须显式传递 None) - 请求的数据客户端 ID。
venue (Venue, optional with no default so None must be passed explicitly) – The venue for the request.
venue (Venue,可选,没有默认值,因此必须显式传递 None) - 请求的场所。
data_type (type) – The data type for the request.
data_type (type) - 请求的数据类型。
callback (Callable [ *[*Any ] , None ]) – The delegate to call with the data.
callback (Callable [*[*Any],None]) - 使用数据调用的委托。
request_id (UUID4) – The request ID.
request_id (UUID4) - 请求 ID。
ts_init (uint64_t) – UNIX timestamp (nanoseconds) when the object was initialized.
ts_init (uint64_t) - 对象初始化时的 UNIX 时间戳(纳秒)。
Raises: ValueError – If both client_id and venue are both None (not enough routing info).
引发:ValueError - 如果 client_id 和 venue 均为 None(路由信息不足)。
"""
def __init__(self, client_id: ClientId | None, venue: Venue | None, data_type, callback: Callable[[Any], None], request_id: UUID4, ts_init: int):
...
@property
def callback(self):
"""
The callback for the response.
响应的回调函数。
Returns:
Callable
"""
...
@property
def client_id(self):
"""
The data client ID for the request.
请求的数据客户端 ID。
Returns:
ClientId or None
"""
...
@property
def data_type(self) -> type:
"""
The request data type.
请求的数据类型。
Returns:
type
"""
...
@property
def id(self) -> UUID4:
"""
The request message ID.
请求消息 ID。
Returns:
UUID4
"""
...
@property
def ts_init(self) -> int:
"""
UNIX timestamp (nanoseconds) when the object was initialized.
对象初始化时的 UNIX 时间戳(纳秒)。
Returns:
uint64_t
"""
...
@property
def venue(self):
"""
The venue for the request.
请求的场所。
Returns:
Venue or None
"""
...
class DataResponse 数据响应
class DataResponse(Response):
"""
Represents a response with data.
表示带有数据的响应。
Parameters:
参数:
client_id (ClientId, optional with no default so None must be passed explicitly) – The data client ID of the response.
client_id (ClientId,可选,没有默认值,因此必须显式传递 None) - 响应的数据客户端 ID。
venue (Venue, optional with no default so None must be passed explicitly) – The venue for the response.
venue (Venue,可选,没有默认值,因此必须显式传递 None) - 响应的场所。
data_type (type) – The data type of the response.
data_type (type) - 响应的数据类型。
data (object) – The data of the response.
data (object) - 响应的数据。
correlation_id (UUID4) – The correlation ID.
correlation_id (UUID4) - 相关 ID。
response_id (UUID4) – The response ID.
response_id (UUID4) - 响应 ID。
ts_init (uint64_t) – UNIX timestamp (nanoseconds) when the object was initialized.
ts_init (uint64_t) - 对象初始化时的 UNIX 时间戳(纳秒)。
Raises: ValueError – If both client_id and venue are both None (not enough routing info).
引发:ValueError - 如果 client_id 和 venue 均为 None(路由信息不足)。
"""
def __init__(self, client_id: ClientId | None, venue: Venue | None, data_type, data, correlation_id: UUID4, response_id: UUID4, ts_init: int):
...
@property
def client_id(self):
"""
The data client ID for the response.
响应的数据客户端 ID。
Returns:
ClientId or None
"""
...
@property
def correlation_id(self) -> UUID4:
"""
The response correlation ID.
响应相关 ID。
Returns:
UUID4
"""
...
@property
def data(self):
"""
The response data.
响应数据。
Returns:
object
"""
...
@property
def data_type(self) -> type:
"""
The response data type.
响应的数据类型。
Returns:
type
"""
...
@property
def id(self) -> UUID4:
"""
The response message ID.
响应消息 ID。
Returns:
UUID4
"""
...
@property
def ts_init(self) -> int:
"""
UNIX timestamp (nanoseconds) when the object was initialized.
对象初始化时的 UNIX 时间戳(纳秒)。
Returns:
uint64_t
"""
...
@property
def venue(self):
"""
The venue for the response.
响应的场所。
Returns:
Venue or None
"""
...
class Subscribe 订阅
class Subscribe(DataCommand):
"""
Represents a command to subscribe to data.
表示订阅数据的命令。
Parameters:
参数:
client_id (ClientId, optional with no default so None must be passed explicitly) – The data client ID for the command.
client_id (ClientId,可选,没有默认值,因此必须显式传递 None) - 命令的数据客户端 ID。
venue (Venue, optional with no default so None must be passed explicitly) – The venue for the command.
venue (Venue,可选,没有默认值,因此必须显式传递 None) - 命令的场所。
data_type (type) – The data type for the subscription.
data_type (type) - 订阅的数据类型。
command_id (UUID4) – The command ID.
command_id (UUID4) - 命令 ID。
ts_init (uint64_t) – UNIX timestamp (nanoseconds) when the object was initialized.
ts_init (uint64_t) - 对象初始化时的 UNIX 时间戳(纳秒)。
Raises: ValueError – If both client_id and venue are both None (not enough routing info).
引发:ValueError - 如果 client_id 和 venue 均为 None(路由信息不足)。
"""
def __init__(self, client_id: ClientId | None, venue: Venue | None, data_type, command_id: UUID4, ts_init: int):
...
@property
def client_id(self):
"""
The data client ID for the command.
命令的数据客户端 ID。
Returns:
ClientId or None
"""
...
@property
def data_type(self) -> type:
"""
The command data type.
命令的数据类型。
Returns:
type
"""
...
@property
def id(self) -> UUID4:
"""
The command message ID.
命令消息 ID。
Returns:
UUID4
"""
...
@property
def ts_init(self) -> int:
"""
UNIX timestamp (nanoseconds) when the object was initialized.
对象初始化时的 UNIX 时间戳(纳秒)。
Returns:
uint64_t
"""
...
@property
def venue(self):
"""
The venue for the command.
命令的场所。
Returns:
Venue or None
"""
...
class Unsubscribe 取消订阅
class Unsubscribe(DataCommand):
"""
Represents a command to unsubscribe from data.
表示取消订阅数据的命令。
Parameters:
参数:
client_id (ClientId, optional with no default so None must be passed explicitly) – The data client ID for the command.
client_id (ClientId,可选,没有默认值,因此必须显式传递 None) - 命令的数据客户端 ID。
venue (Venue, optional with no default so None must be passed explicitly) – The venue for the command.
venue (Venue,可选,没有默认值,因此必须显式传递 None) - 命令的场所。
data_type (type) – The data type to unsubscribe from.
data_type (type) - 要取消订阅的数据类型。
command_id (UUID4) – The command ID.
command_id (UUID4) - 命令 ID。
ts_init (uint64_t) – UNIX timestamp (nanoseconds) when the object was initialized.
ts_init (uint64_t) - 对象初始化时的 UNIX 时间戳(纳秒)。
Raises: ValueError – If both client_id and venue are both None (not enough routing info).
引发:ValueError - 如果 client_id 和 venue 均为 None(路由信息不足)。
"""
def __init__(self, client_id: ClientId | None, venue: Venue | None, data_type, command_id: UUID4, ts_init: int):
...
@property
def client_id(self):
"""
The data client ID for the command.
命令的数据客户端 ID。
Returns:
ClientId or None
"""
...
@property
def data_type(self) -> type:
"""
The command data type.
命令的数据类型。
Returns:
type
"""
...
@property
def id(self) -> UUID4:
"""
The command message ID.
命令消息 ID。
Returns:
UUID4
"""
...
@property
def ts_init(self) -> int:
"""
UNIX timestamp (nanoseconds) when the object was initialized.
对象初始化时的 UNIX 时间戳(纳秒)。
Returns:
uint64_t
"""
...
@property
def venue(self):
"""
The venue for the command.
命令的场所。
Returns:
Venue or None
"""
...