Execution 执行 - Loren1166/NautilusTrader- GitHub Wiki
Execution 执行
The execution subpackage groups components relating to the execution stack for the platform.
执行子包将与平台执行栈相关的组件分组。
The layered architecture of the execution stack somewhat mirrors the data 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.
由于高性能,核心组件在回测和实时实现之间可重用 - 有助于确保交易操作的逻辑一致性。
Components 组件
class ExecAlgorithm 执行算法
Bases: Actor
class ExecAlgorithm(Actor):
"""
The base class for all execution algorithms.
所有执行算法的基类。
This class allows traders to implement their own customized execution algorithms.
此类允许交易者实现他们自己的自定义执行算法。
Parameters:
参数:
config (ExecAlgorithmConfig , optional) – The execution algorithm configuration.
config (ExecAlgorithmConfig,可选) - 执行算法配置。
Raises: TypeError – If config is not of type ExecAlgorithmConfig.
引发:TypeError - 如果 config 的类型不是 ExecAlgorithmConfig。
Warning:
This class should not be used directly, but through a concrete subclass.
此类不应直接使用,而应通过具体的子类使用。
"""
def __init__(self, config: ExecAlgorithmConfig | None = None):
...
Properties 属性
@property
def cache(self):
"""
The read-only cache for the actor.
actor 的只读缓存。
Returns:
CacheFacade
"""
...
@property
def clock(self):
"""
The actors clock.
actor 的时钟。
Returns:
Clock
"""
...
@property
def config(self):
"""
The actors configuration.
actor 的配置。
Returns:
NautilusConfig
"""
...
@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 log(self) :
"""
The actors logger.
actor 的日志记录器。
Returns:
Logger
"""
...
@property
def msgbus(self):
"""
The message bus for the actor (if registered).
actor 的消息总线(如果已注册)。
Returns:
MessageBus or None
"""
...
@property
def portfolio(self):
"""
The read-only portfolio for the actor.
actor 的只读投资组合。
Returns:
PortfolioFacade
"""
...
@property
def registered_indicators(self):
"""
Return the registered indicators for the strategy.
返回策略的已注册指标。
Return type: list[Indicator]
"""
...
@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
"""
...
Methods 方法
def active_task_ids(self) -> list:
"""
Return the active task identifiers.
返回活动的 task 标识符。
Return type: list[TaskId]
"""
...
def add_synthetic(self, synthetic: SyntheticInstrument) -> void:
"""
Add the created synthetic instrument to the cache.
将创建的合成金融工具添加到缓存中。
Parameters: synthetic (SyntheticInstrument) – The synthetic instrument to add to the cache.
参数:synthetic (SyntheticInstrument) - 要添加到缓存中的合成金融工具。
Raises: KeyError – If synthetic is already in the cache.
引发:KeyError - 如果合成金融工具已存在于缓存中。
"""
...
def cancel_all_tasks(self) -> void:
"""
Cancel all queued and active tasks.
取消所有排队和活动的 task。
"""
...
def cancel_order(self, order: Order, client_id: ClientId = None) -> void:
"""
Cancel the given order with optional routing instructions.
取消给定的订单,并附带可选的路由指令。
A CancelOrder command will be created and then sent to either the OrderEmulator or the ExecutionEngine (depending on whether the order is emulated).
将创建一个 CancelOrder 命令,然后将其发送到 OrderEmulator 或 ExecutionEngine(取决于订单是否已模拟)。
Logs an error if no VenueOrderId has been assigned to the order.
如果未向订单分配 VenueOrderId,则记录错误。
Parameters:
参数:
order (Order) – The order to cancel.
order (Order) - 要取消的订单。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
"""
...
def cancel_task(self, task_id: TaskId) -> void:
"""
Cancel the task with the given task_id (if queued or active).
取消具有给定 task_id 的任务(如果已排队或活动)。
If the task is not found then a warning is logged.
如果未找到任务,则会记录警告。
Parameters: task_id (TaskId) – The task identifier.
参数:task_id (TaskId) – 任务标识符。
"""
...
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_warning_event(self, event) -> void:
"""
Deregister the given event type from warning log levels.
从警告日志级别取消注册给定的事件类型。
Parameters: event (type) – The event class to deregister.
参数:event (type) - 要取消注册的事件类。
"""
...
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: TradingCommand) -> void:
"""
Handle the given trading command by processing it with the execution algorithm.
通过使用执行算法处理给定的交易命令来处理它。
Parameters: command (SubmitOrder) – The command to handle.
参数:command (SubmitOrder) - 要处理的命令。
Raises: ValueError – If command.exec_algorithm_id is not equal to self.id.
引发:ValueError - 如果 command.exec_algorithm_id 不等于 self.id。
"""
...
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 handle_bar(self, bar: Bar) -> void:
"""
Handle the given bar data.
处理给定的 bar 数据。
If state is RUNNING then passes to on_bar.
如果状态为 RUNNING,则传递给 on_bar。
Parameters: bar (Bar) – The bar received.
参数:bar (Bar) - 接收到的 bar。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def handle_bars(self, bars: list) -> void:
"""
Handle the given historical bar data by handling each bar individually.
通过单独处理每个 bar 来处理给定的历史 bar 数据。
Parameters: bars (list [Bar ]) – The bars to handle.
参数:bars (list [Bar ]) - 要处理的 bar。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def handle_data(self, data: Data) -> void:
"""
Handle the given data.
处理给定的数据。
If state is RUNNING then passes to on_data.
如果状态为 RUNNING,则传递给 on_data。
Parameters: data (Data) – The data received.
参数:data (Data) - 接收到的数据。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def handle_event(self, event: Event) -> void:
"""
Handle the given event.
处理给定的事件。
If state is RUNNING then passes to on_event.
如果状态为 RUNNING,则传递给 on_event。
Parameters: event (Event) – The event received.
参数:event (Event) - 接收到的事件。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def handle_historical_data(self, data) -> void:
"""
Handle the given historical data.
处理给定的历史数据。
Parameters: data (Data) – The historical data received.
参数:data (Data) - 接收到的历史数据。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def handle_instrument(self, instrument: Instrument) -> void:
"""
Handle the given instrument.
处理给定的金融工具。
Passes to on_instrument if state is RUNNING.
如果状态为 RUNNING,则传递给 on_instrument。
Parameters: instrument (Instrument) – The instrument received.
参数:instrument (Instrument) - 接收到的金融工具。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def handle_instrument_close(self, update: InstrumentClose) -> void:
"""
Handle the given instrument close update.
处理给定的金融工具关闭更新。
If state is RUNNING then passes to on_instrument_close.
如果状态为 RUNNING,则传递给 on_instrument_close。
Parameters: update (InstrumentClose) – The update received.
参数:update (InstrumentClose) - 接收到的更新。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def handle_instrument_status(self, data: InstrumentStatus) -> void:
"""
Handle the given instrument status update.
处理给定的金融工具状态更新。
If state is RUNNING then passes to on_instrument_status.
如果状态为 RUNNING,则传递给 on_instrument_status。
Parameters: data (InstrumentStatus) – The status update received.
参数:data (InstrumentStatus) - 接收到的状态更新。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def handle_instruments(self, instruments: list) -> void:
"""
Handle the given instruments data by handling each instrument individually.
通过单独处理每个金融工具来处理给定的金融工具数据。
Parameters: instruments (list [Instrument ]) – The instruments received.
参数:instruments (list [Instrument ]) - 接收到的金融工具。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def handle_order_book(self, order_book: OrderBook) -> void:
"""
Handle the given order book.
处理给定的订单簿。
Passes to on_order_book if state is RUNNING.
如果状态为 RUNNING,则传递给 on_order_book。
Parameters: order_book (OrderBook) – The order book received.
参数:order_book (OrderBook) - 接收到的订单簿。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def handle_order_book_deltas(self, deltas) -> void:
"""
Handle the given order book deltas.
处理给定的订单簿增量。
Passes to on_order_book_deltas if state is RUNNING. The deltas will be nautilus_pyo3.OrderBookDeltas if the pyo3_conversion flag was set for the subscription.
如果状态为 RUNNING,则传递给 on_order_book_deltas。如果为订阅设置了 pyo3_conversion 标志,则增量将为 nautilus_pyo3.OrderBookDeltas。
Parameters: deltas (OrderBookDeltas or nautilus_pyo3.OrderBookDeltas) – The order book deltas received.
参数:deltas (OrderBookDeltas or nautilus_pyo3.OrderBookDeltas) - 接收到的订单簿增量。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def handle_quote_tick(self, tick: QuoteTick) -> void:
"""
Handle the given quote tick.
处理给定的报价 tick。
If state is RUNNING then passes to on_quote_tick.
如果状态为 RUNNING,则传递给 on_quote_tick。
Parameters: tick (QuoteTick) – The tick received.
参数:tick (QuoteTick) - 接收到的 tick。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def handle_quote_ticks(self, ticks: list) -> void:
"""
Handle the given historical quote tick data by handling each tick individually.
通过单独处理每个 tick 来处理给定的历史报价 tick 数据。
Parameters: ticks (list [QuoteTick ]) – The ticks received.
参数:ticks (list [QuoteTick ]) - 接收到的 tick。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def handle_trade_tick(self, tick: TradeTick) -> void:
"""
Handle the given trade tick.
处理给定的交易 tick。
If state is RUNNING then passes to on_trade_tick.
如果状态为 RUNNING,则传递给 on_trade_tick。
Parameters: tick (TradeTick) – The tick received.
参数:tick (TradeTick) - 接收到的 tick。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def handle_trade_ticks(self, ticks: list) -> void:
"""
Handle the given historical trade tick data by handling each tick individually.
通过单独处理每个 tick 来处理给定的历史交易 tick 数据。
Parameters: ticks (list [TradeTick ]) – The ticks received.
参数:ticks (list [TradeTick ]) - 接收到的 tick。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def has_active_tasks(self) -> bool:
"""
Return a value indicating whether there are any active tasks.
返回值指示是否有任何活动的 task。
Return type: bool
"""
...
def has_any_tasks(self) -> bool:
"""
Return a value indicating whether there are any queued or active tasks.
返回值指示是否有任何排队或活动的 task。
Return type: bool
"""
...
def has_pending_requests(self) -> bool:
"""
Return whether the actor is pending processing for any requests.
返回 actor 是否正在等待处理任何请求。
Returns: True if any requests are pending, else False.
返回值:如果有任何请求正在等待处理,则返回 True,否则返回 False。
Return type: bool
"""
...
def has_queued_tasks(self) -> bool:
"""
Return a value indicating whether there are any queued tasks.
返回值指示是否有任何排队的 task。
Return type: bool
"""
...
def indicators_initialized(self) -> bool:
"""
Return a value indicating whether all indicators are initialized.
返回值指示是否所有指标都已初始化。
Returns: True if all initialized, else False
返回值:如果所有指标都已初始化,则返回 True,否则返回 False。
Return type: bool
"""
...
def is_pending_request(self, request_id: UUID4) -> bool:
"""
Return whether the request for the given identifier is pending processing.
返回给定标识符的请求是否正在等待处理。
Parameters: request_id (UUID4) – The request ID to check.
参数:request_id (UUID4) - 要检查的请求 ID。
Returns: True if request is pending, else False.
返回值:如果请求正在等待处理,则返回 True,否则返回 False。
Return type: bool
"""
...
def load(self, state: dict) -> void:
"""
Load the actor/strategy state from the give state dictionary.
从给定的状态字典加载 actor/strategy 状态。
Calls on_load and passes the state.
调用 on_load 并传递状态。
Parameters: state (dict *[*str , object ]) – The state dictionary.
参数:state (dict *[*str , object ]) - 状态字典。
Raises: RuntimeError – If actor/strategy is not registered with a trader.
引发:RuntimeError - 如果 actor/strategy 未在交易者处注册。
Warning:
Exceptions raised will be caught, logged, and reraised.
引发的异常将被捕获、记录并重新引发。
"""
...
def modify_order(self, order: Order, quantity: Quantity = None, price: Price = None, trigger_price: Price = None, client_id: ClientId = None) -> void:
"""
Modify the given order with optional parameters and routing instructions.
使用可选参数和路由指令修改给定订单。
An ModifyOrder command will be created and then sent to the RiskEngine.
将创建一个 ModifyOrder 命令,然后将其发送到 RiskEngine。
At least one value must differ from the original order for the command to be valid.
至少有一个值必须与原始订单不同,才能使命令有效。
Will use an Order Cancel/Replace Request (a.k.a Order Modification) for FIX protocols, otherwise if order update is not available for the API, then will cancel and replace with a new order using the original ClientOrderId.
对于 FIX 协议,将使用订单取消/替换请求(也称为订单修改),否则,如果 API 不支持订单更新,则将使用原始 ClientOrderId 取消并替换为新订单。
Parameters:
参数:
order (Order) – The order to update.
order (Order) - 要更新的订单。
quantity (Quantity , optional) – The updated quantity for the given order.
quantity (Quantity,可选) - 给定订单的更新数量。
price (Price , optional) – The updated price for the given order (if applicable).
price (Price,可选) - 给定订单的更新价格(如果适用)。
trigger_price (Price , optional) – The updated trigger price for the given order (if applicable).
trigger_price (Price,可选) - 给定订单的更新触发价格(如果适用)。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
Raises:
引发:
ValueError – If price is not None and order does not have a price.
ValueError - 如果 price 不为 None 并且订单没有价格。
ValueError – If trigger is not None and order does not have a trigger_price.
ValueError - 如果 trigger 不为 None 并且订单没有 trigger_price。
Warning:
If the order is already closed or at PENDING_CANCEL status then the command will not be generated, and a warning will be logged.
如果订单已关闭或处于 PENDING_CANCEL 状态,则不会生成命令,并且会记录警告。
"""
...
def modify_order_in_place(self, order: Order, quantity: Quantity = None, price: Price = None, trigger_price: Price = None) -> void:
"""
Modify the given INITIALIZED order in place (immediately) with optional parameters.
使用可选参数就地(立即)修改给定的 INITIALIZED 订单。
At least one value must differ from the original order for the command to be valid.
至少有一个值必须与原始订单不同,才能使命令有效。
Parameters:
参数:
order (Order) – The order to update.
order (Order) - 要更新的订单。
quantity (Quantity , optional) – The updated quantity for the given order.
quantity (Quantity,可选) - 给定订单的更新数量。
price (Price , optional) – The updated price for the given order (if applicable).
price (Price,可选) - 给定订单的更新价格(如果适用)。
trigger_price (Price , optional) – The updated trigger price for the given order (if applicable).
trigger_price (Price,可选) - 给定订单的更新触发价格(如果适用)。
Raises:
引发:
ValueError – If order.status is not INITIALIZED or RELEASED.
ValueError - 如果 order.status 不是 INITIALIZED 或 RELEASED。
ValueError – If price is not None and order does not have a price.
ValueError - 如果 price 不为 None 并且订单没有价格。
ValueError – If trigger is not None and order does not have a trigger_price.
ValueError - 如果 trigger 不为 None 并且订单没有 trigger_price。
Warning:
If the order is already closed or at PENDING_CANCEL status then the command will not be generated, and a warning will be logged.
如果订单已关闭或处于 PENDING_CANCEL 状态,则不会生成命令,并且会记录警告。
"""
...
def on_bar(self, bar: Bar) -> void:
"""
Actions to be performed when running and receives a bar.
运行时执行的操作以及接收到的 bar。
Parameters: bar (Bar) – The bar received.
参数:bar (Bar) - 接收到的 bar。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_data(self, data: Data) -> void:
"""
Actions to be performed when running and receives data.
运行时执行的操作以及接收到的数据。
Parameters: data (Data) – The data received.
参数:data (Data) - 接收到的数据。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_degrade(self) -> void:
"""
Actions to be performed on degrade.
降级时执行的操作。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
Should be overridden in the actor implementation.
应该在 actor 实现中重写。
"""
...
def on_dispose(self) -> void:
"""
Actions to be performed on dispose.
释放时执行的操作。
Cleanup/release any resources used here.
在此处清理/释放使用的任何资源。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_event(self, event: Event) -> void:
"""
Actions to be performed running and receives an event.
运行时执行的操作以及接收到的事件。
Parameters: event (Event) – The event received.
参数:event (Event) - 接收到的事件。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_fault(self) -> void:
"""
Actions to be performed on fault.
出现故障时执行的操作。
Cleanup any resources used by the actor here.
在此处清理 actor 使用的任何资源。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
Should be overridden in the actor implementation.
应该在 actor 实现中重写。
"""
...
def on_historical_data(self, data) -> void:
"""
Actions to be performed when running and receives historical data.
运行时执行的操作以及接收到的历史数据。
Parameters: data (Data) – The historical data received.
参数:data (Data) - 接收到的历史数据。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_instrument(self, instrument: Instrument) -> void:
"""
Actions to be performed when running and receives an instrument.
运行时执行的操作以及接收到的金融工具。
Parameters: instrument (Instrument) – The instrument received.
参数:instrument (Instrument) - 接收到的金融工具。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_instrument_close(self, update: InstrumentClose) -> void:
"""
Actions to be performed when running and receives an instrument close update.
运行时执行的操作以及接收到的金融工具关闭更新。
Parameters: update (InstrumentClose) – The instrument close received.
参数:update (InstrumentClose) - 接收到的金融工具关闭。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_instrument_status(self, data: InstrumentStatus) -> void:
"""
Actions to be performed when running and receives an instrument status update.
运行时执行的操作以及接收到的金融工具状态更新。
Parameters: data (InstrumentStatus) – The instrument status update received.
参数:data (InstrumentStatus) - 接收到的金融工具状态更新。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_load(self, state: dict) -> void:
"""
Actions to be performed when the actor state is loaded.
加载 actor 状态时执行的操作。
Saved state values will be contained in the give state dictionary.
保存的状态值将包含在给定的状态字典中。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_order(self, order: Order) -> void:
"""
Actions to be performed when running and receives an order.
运行时执行的操作以及接收到的订单。
Parameters: order (Order) – The order to be handled.
参数:order (Order) - 要处理的订单。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_order_accepted(self, event: OrderAccepted) -> void:
"""
Actions to be performed when running and receives an order accepted event.
运行时执行的操作以及接收到的订单接受事件。
Parameters: event (OrderAccepted) – The event received.
参数:event (OrderAccepted) - 接收到的事件。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_order_book(self, order_book: OrderBook) -> void:
"""
Actions to be performed when running and receives an order book.
运行时执行的操作以及接收到的订单簿。
Parameters: order_book (OrderBook) – The order book received.
参数:order_book (OrderBook) - 接收到的订单簿。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_order_book_deltas(self, deltas) -> void:
"""
Actions to be performed when running and receives order book deltas.
运行时执行的操作以及接收到的订单簿增量。
Parameters: deltas (OrderBookDeltas or nautilus_pyo3.OrderBookDeltas) – The order book deltas received.
参数:deltas (OrderBookDeltas or nautilus_pyo3.OrderBookDeltas) - 接收到的订单簿增量。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_order_cancel_rejected(self, event: OrderCancelRejected) -> void:
"""
Actions to be performed when running and receives an order cancel rejected event.
运行时执行的操作以及接收到的订单取消拒绝事件。
Parameters: event (OrderCancelRejected) – The event received.
参数:event (OrderCancelRejected) - 接收到的事件。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_order_canceled(self, event: OrderCanceled) -> void:
"""
Actions to be performed when running and receives an order canceled event.
运行时执行的操作以及接收到的订单取消事件。
Parameters: event (OrderCanceled) – The event received.
参数:event (OrderCanceled) - 接收到的事件。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_order_denied(self, event: OrderDenied) -> void:
"""
Actions to be performed when running and receives an order denied event.
运行时执行的操作以及接收到的订单拒绝事件。
Parameters: event (OrderDenied) – The event received.
参数:event (OrderDenied) - 接收到的事件。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
```python
def on_order_emulated(self, event: OrderEmulated) -> void:
"""
Actions to be performed when running and receives an order initialized event.
运行时执行的操作以及接收到的订单初始化事件。
Parameters: event (OrderEmulated) – The event received.
参数:event (OrderEmulated) - 接收到的事件。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_order_event(self, event: OrderEvent) -> void:
"""
Actions to be performed when running and receives an order event.
运行时执行的操作以及接收到的订单事件。
Parameters: event (OrderEvent) – The event received.
参数:event (OrderEvent) - 接收到的事件。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_order_expired(self, event: OrderExpired) -> void:
"""
Actions to be performed when running and receives an order expired event.
运行时执行的操作以及接收到的订单过期事件。
Parameters: event (OrderExpired) – The event received.
参数:event (OrderExpired) - 接收到的事件。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_order_filled(self, event: OrderFilled) -> void:
"""
Actions to be performed when running and receives an order filled event.
运行时执行的操作以及接收到的订单成交事件。
Parameters: event (OrderFilled) – The event received.
参数:event (OrderFilled) - 接收到的事件。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_order_initialized(self, event: OrderInitialized) -> void:
"""
Actions to be performed when running and receives an order initialized event.
运行时执行的操作以及接收到的订单初始化事件。
Parameters: event (OrderInitialized) – The event received.
参数:event (OrderInitialized) - 接收到的事件。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_order_list(self, order_list: OrderList) -> void:
"""
Actions to be performed when running and receives an order list.
运行时执行的操作以及接收到的订单列表。
Parameters: order_list (OrderList) – The order list to be handled.
参数:order_list (OrderList) - 要处理的订单列表。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_order_modify_rejected(self, event: OrderModifyRejected) -> void:
"""
Actions to be performed when running and receives an order modify rejected event.
运行时执行的操作以及接收到的订单修改拒绝事件。
Parameters: event (OrderModifyRejected) – The event received.
参数:event (OrderModifyRejected) - 接收到的事件。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_order_pending_cancel(self, event: OrderPendingCancel) -> void:
"""
Actions to be performed when running and receives an order pending cancel event.
运行时执行的操作以及接收到的订单待取消事件。
Parameters: event (OrderPendingCancel) – The event received.
参数:event (OrderPendingCancel) - 接收到的事件。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_order_pending_update(self, event: OrderPendingUpdate) -> void:
"""
Actions to be performed when running and receives an order pending update event.
运行时执行的操作以及接收到的订单待更新事件。
Parameters: event (OrderPendingUpdate) – The event received.
参数:event (OrderPendingUpdate) - 接收到的事件。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_order_rejected(self, event: OrderRejected) -> void:
"""
Actions to be performed when running and receives an order rejected event.
运行时执行的操作以及接收到的订单拒绝事件。
Parameters: event (OrderRejected) – The event received.
参数:event (OrderRejected) - 接收到的事件。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_order_released(self, event: OrderReleased) -> void:
"""
Actions to be performed when running and receives an order released event.
运行时执行的操作以及接收到的订单释放事件。
Parameters: event (OrderReleased) – The event received.
参数:event (OrderReleased) - 接收到的事件。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_order_submitted(self, event: OrderSubmitted) -> void:
"""
Actions to be performed when running and receives an order submitted event.
运行时执行的操作以及接收到的订单提交事件。
Parameters: event (OrderSubmitted) – The event received.
参数:event (OrderSubmitted) - 接收到的事件。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_order_triggered(self, event: OrderTriggered) -> void:
"""
Actions to be performed when running and receives an order triggered event.
运行时执行的操作以及接收到的订单触发事件。
Parameters: event (OrderTriggered) – The event received.
参数:event (OrderTriggered) - 接收到的事件。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_order_updated(self, event: OrderUpdated) -> void:
"""
Actions to be performed when running and receives an order updated event.
运行时执行的操作以及接收到的订单更新事件。
Parameters: event (OrderUpdated) – The event received.
参数:event (OrderUpdated) - 接收到的事件。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_position_changed(self, event: PositionChanged) -> void:
"""
Actions to be performed when running and receives a position changed event.
运行时执行的操作以及接收到的持仓更改事件。
Parameters: event (PositionChanged) – The event received.
参数:event (PositionChanged) - 接收到的事件。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_position_closed(self, event: PositionClosed) -> void:
"""
Actions to be performed when running and receives a position closed event.
运行时执行的操作以及接收到的持仓关闭事件。
Parameters: event (PositionClosed) – The event received.
参数:event (PositionClosed) - 接收到的事件。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_position_event(self, event: PositionEvent) -> void:
"""
Actions to be performed when running and receives a position event.
运行时执行的操作以及接收到的持仓事件。
Parameters: event (PositionEvent) – The event received.
参数:event (PositionEvent) - 接收到的事件。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_position_opened(self, event: PositionOpened) -> void:
"""
Actions to be performed when running and receives a position opened event.
运行时执行的操作以及接收到的持仓打开事件。
Parameters: event (PositionOpened) – The event received.
参数:event (PositionOpened) - 接收到的事件。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_quote_tick(self, tick: QuoteTick) -> void:
"""
Actions to be performed when running and receives a quote tick.
运行时执行的操作以及接收到的报价 tick。
Parameters: tick (QuoteTick) – The tick received.
参数:tick (QuoteTick) - 接收到的 tick。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_reset(self) -> void:
"""
Actions to be performed on reset.
重置时执行的操作。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
Should be overridden in a user implementation.
应该在用户实现中重写。
"""
...
def on_resume(self) -> void:
"""
Actions to be performed on resume.
恢复时执行的操作。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_save(self) -> dict:
"""
Actions to be performed when the actor state is saved.
保存 actor 状态时执行的操作。
Create and return a state dictionary of values to be saved.
创建并返回要保存的值的状态字典。
Returns: The strategy state dictionary.
返回值:策略状态字典。
Return type: dict[str, bytes]
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_start(self) -> void:
"""
Actions to be performed on start.
启动时执行的操作。
The intent is that this method is called once per trading ‘run’, when initially starting.
其目的是在每次交易“运行”开始时调用此方法一次。
It is recommended to subscribe/request for data here.
建议在此处订阅/请求数据。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
Should be overridden in a user implementation.
应该在用户实现中重写。
"""
...
def on_stop(self) -> void:
"""
Actions to be performed on stop.
停止时执行的操作。
The intent is that this method is called to pause, or when done for day.
其目的是在暂停时或当天完成后调用此方法。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
Should be overridden in a user implementation.
应该在用户实现中重写。
"""
...
def on_trade_tick(self, tick: TradeTick) -> void:
"""
Actions to be performed when running and receives a trade tick.
运行时执行的操作以及接收到的交易 tick。
Parameters: tick (TradeTick) – The tick received.
参数:tick (TradeTick) - 接收到的 tick。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def pending_requests(self) -> set:
"""
Return the request IDs which are currently pending processing.
返回当前正在等待处理的请求 ID。
Return type: set[UUID4]
"""
...
def publish_data(self, data_type: DataType, data: Data) -> void:
"""
Publish the given data to the message bus.
将给定的数据发布到消息总线。
Parameters:
参数:
data_type (DataType) – The data type being published.
data_type (DataType) - 正在发布的数据类型。
data (Data) – The data to publish.
data (Data) - 要发布的数据。
"""
...
def publish_signal(self, name: str, value, ts_event: int=0) -> void:
"""
Publish the given value as a signal to the message bus.
将给定的值作为信号发布到消息总线。
Parameters:
参数:
name (str) – The name of the signal being published. The signal name is case-insensitive and will be capitalized (e.g., ‘example’ becomes ‘SignalExample’).
name (str) - 正在发布的信号的名称。信号名称不区分大小写,并且将大写(例如,“example”变为“SignalExample”)。
value (object) – The signal data to publish.
value (object) - 要发布的信号数据。
ts_event (uint64_t , optional) – UNIX timestamp (nanoseconds) when the signal event occurred. If None then will timestamp current time.
ts_event (uint64_t,可选) - 信号事件发生时的 UNIX 时间戳(纳秒)。如果为 None,则将使用当前时间作为时间戳。
"""
...
def queue_for_executor(self, func: Callable, args: tuple=None, kwargs: dict=None):
"""
Queues the callable func to be executed as fn(*args, **kwargs) sequentially.
将可调用函数 func 排队,以便按顺序执行为 fn(*args, **kwargs)。
Parameters:
参数:
func (Callable) – The function to be executed.
func (Callable) - 要执行的函数。
args (positional arguments) – The positional arguments for the call to func.
args(位置参数) - 对 func 的调用的位置参数。
kwargs (arbitrary keyword arguments) – The keyword arguments for the call to func.
kwargs(任意关键字参数) - 对 func 的调用的关键字参数。
Raises: TypeError – If func is not of type Callable.
引发:TypeError - 如果 func 的类型不是 Callable。
"""
...
def queued_task_ids(self) -> list:
"""
Return the queued task identifiers.
返回排队的 task 标识符。
Return type: list[TaskId]
"""
...
def register(self, trader_id: TraderId, portfolio: PortfolioFacade, msgbus: MessageBus, cache: CacheFacade, clock: Clock) -> void:
"""
Register the execution algorithm with a trader.
向交易者注册执行算法。
Parameters:
参数:
trader_id (TraderId) – The trader ID for the execution algorithm.
trader_id (TraderId) - 执行算法的交易者 ID。
portfolio (PortfolioFacade) – The read-only portfolio for the execution algorithm.
portfolio (PortfolioFacade) - 执行算法的只读投资组合。
msgbus (MessageBus) – The message bus for the execution algorithm.
msgbus (MessageBus) - 执行算法的消息总线。
cache (CacheFacade) – The read-only cache for the execution algorithm.
cache (CacheFacade) - 执行算法的只读缓存。
clock (Clock) – The clock for the execution algorithm.
clock (Clock) - 执行算法的时钟。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def register_base(self, portfolio: PortfolioFacade, msgbus: MessageBus, cache: CacheFacade, clock: Clock) -> void:
"""
Register with a trader.
向交易者注册。
Parameters:
参数:
portfolio (PortfolioFacade) – The read-only portfolio for the actor.
portfolio (PortfolioFacade) - actor 的只读投资组合。
msgbus (MessageBus) – The message bus for the actor.
msgbus (MessageBus) - actor 的消息总线。
cache (CacheFacade) – The read-only cache for the actor.
cache (CacheFacade) - actor 的只读缓存。
clock (Clock) – The clock for the actor.
clock (Clock) - actor 的时钟。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def register_executor(self, loop, executor: Executor) -> void:
"""
Register the given Executor for the actor.
为 actor 注册给定的 Executor。
Parameters:
参数:
loop (asyncio.AsbtractEventLoop) – The event loop of the application.
loop (asyncio.AsbtractEventLoop) - 应用程序的事件循环。
executor (concurrent.futures.Executor) – The executor to register.
executor (concurrent.futures.Executor) - 要注册的执行器。
Raises: TypeError – If executor is not of type concurrent.futures.Executor
引发:TypeError - 如果 executor 的类型不是 concurrent.futures.Executor。
"""
...
def register_indicator_for_bars(self, bar_type: BarType, indicator: Indicator) -> void:
"""
Register the given indicator with the actor/strategy to receive bar data for the given bar type.
向 actor/strategy 注册给定的指标,以便接收给定 bar 类型的 bar 数据。
Parameters:
参数:
bar_type (BarType) – The bar type for bar updates.
bar_type (BarType) - bar 更新的 bar 类型。
indicator (Indicator) – The indicator to register.
indicator (Indicator) - 要注册的指标。
"""
...
def register_indicator_for_quote_ticks(self, instrument_id: InstrumentId, indicator: Indicator) -> void:
"""
Register the given indicator with the actor/strategy to receive quote tick data for the given instrument ID.
向 actor/strategy 注册给定的指标,以便接收给定金融工具 ID 的报价 tick 数据。
Parameters:
参数:
instrument_id (InstrumentId) – The instrument ID for tick updates.
instrument_id (InstrumentId) - tick 更新的金融工具 ID。
indicator (Indicator) – The indicator to register.
indicator (Indicator) - 要注册的指标。
"""
...
def register_indicator_for_trade_ticks(self, instrument_id: InstrumentId, indicator) -> void:
"""
Register the given indicator with the actor/strategy to receive trade tick data for the given instrument ID.
向 actor/strategy 注册给定的指标,以便接收给定金融工具 ID 的交易 tick 数据。
Parameters:
参数:
instrument_id (InstrumentId) – The instrument ID for tick updates.
instrument_id (InstrumentId) - tick 更新的金融工具 ID。
indicator (indicator) – The indicator to register.
indicator (indicator) - 要注册的指标。
"""
...
def register_warning_event(self, event) -> void:
"""
Register the given event type for warning log levels.
为警告日志级别注册给定的事件类型。
Parameters: event (type) – The event class to register.
参数:event (type) - 要注册的事件类。
"""
...
def request_bars(self, bar_type: BarType, start: datetime=None, end: datetime=None, client_id: ClientId=None, callback=None) -> UUID4:
"""
Request historical Bar data.
请求历史 Bar 数据。
If end is None then will request up to the most recent data.
如果 end 为 None,则将请求最多到最新数据。
Parameters:
参数:
bar_type (BarType) – The bar type for the request.
bar_type (BarType) - 请求的 bar 类型。
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)。包含性取决于各个数据客户端的实现。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
callback (Callable [ [UUID4 ] , None ] , optional) – The registered callback, to be called with the request ID when the response has completed processing.
callback (Callable [ [UUID4 ] , None ],可选) - 注册的回调函数,当响应完成处理时,将使用请求 ID 调用该回调函数。
Returns: The request_id for the request.
返回值:请求的 request_id。
Return type: UUID4
Raises:
引发:
ValueError – If start and end are not None and start is >= end.
ValueError - 如果 start 和 end 不为 None 并且 start >= end。
TypeError – If callback is not None and not of type Callable.
TypeError - 如果 callback 不为 None 并且类型不是 Callable。
"""
...
def request_data(self, data_type: DataType, client_id: ClientId, callback=None) -> UUID4:
"""
Request custom data for the given data type from the given data client.
从给定的数据客户端请求给定数据类型的自定义数据。
Parameters:
参数:
data_type (DataType) – The data type for the request.
data_type (DataType) - 请求的数据类型。
client_id (ClientId) – The data client ID.
client_id (ClientId) - 数据客户端 ID。
callback (Callable [ [UUID4 ] , None ] , optional) – The registered callback, to be called with the request ID when the response has completed processing.
callback (Callable [ [UUID4 ] , None ],可选) - 注册的回调函数,当响应完成处理时,将使用请求 ID 调用该回调函数。
Returns: The request_id for the request.
返回值:请求的 request_id。
Return type: UUID4
Raises: TypeError – If callback is not None and not of type Callable.
引发:TypeError - 如果 callback 不为 None 并且类型不是 Callable。
"""
...
def request_instrument(self, instrument_id: InstrumentId, start: datetime=None, end: datetime=None, client_id: ClientId=None, callback=None) -> UUID4:
"""
Request Instrument data for the given instrument ID.
请求给定金融工具 ID 的金融工具数据。
If end is None then will request up to the most recent data.
如果 end 为 None,则将请求最多到最新数据。
Parameters:
参数:
instrument_id (InstrumentId) – The instrument ID for the request.
instrument_id (InstrumentId) - 请求的金融工具 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)。包含性取决于各个数据客户端的实现。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
callback (Callable [ [UUID4 ] , None ] , optional) – The registered callback, to be called with the request ID when the response has completed processing.
callback (Callable [ [UUID4 ] , None ],可选) - 注册的回调函数,当响应完成处理时,将使用请求 ID 调用该回调函数。
Returns: The request_id for the request.
返回值:请求的 request_id。
Return type: UUID4
Raises:
引发:
ValueError – If start and end are not None and start is >= end.
ValueError - 如果 start 和 end 不为 None 并且 start >= end。
TypeError – If callback is not None and not of type Callable.
TypeError - 如果 callback 不为 None 并且类型不是 Callable。
"""
...
def request_instruments(self, venue: Venue, start: datetime=None, end: datetime=None, client_id: ClientId=None, callback=None) -> UUID4:
"""
Request all Instrument data for the given venue.
请求给定场所的所有金融工具数据。
If end is None then will request up to the most recent data.
如果 end 为 None,则将请求最多到最新数据。
Parameters:
参数:
venue (Venue) – The venue for the request.
venue (Venue) - 请求的场所。
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)。包含性取决于各个数据客户端的实现。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
callback (Callable [ [UUID4 ] , None ] , optional) – The registered callback, to be called with the request ID when the response has completed processing.
callback (Callable [ [UUID4 ] , None ],可选) - 注册的回调函数,当响应完成处理时,将使用请求 ID 调用该回调函数。
Returns: The request_id for the request.
返回值:请求的 request_id。
Return type: UUID4
Raises:
引发:
ValueError – If start and end are not None and start is >= end.
ValueError - 如果 start 和 end 不为 None 并且 start >= end。
TypeError – If callback is not None and not of type Callable.
TypeError - 如果 callback 不为 None 并且类型不是 Callable。
"""
...
def request_order_book_snapshot(self, instrument_id: InstrumentId, limit: int, client_id: ClientId=None, callback=None) -> UUID4:
"""
Request an order book snapshot.
请求订单簿快照。
Parameters:
参数:
instrument_id (InstrumentId) – The instrument ID for the order book snapshot request.
instrument_id (InstrumentId) - 订单簿快照请求的金融工具 ID。
limit (int , optional) – The limit on the depth of the order book snapshot (default is None).
limit (int,可选) - 订单簿快照深度的限制(默认为 None)。
client_id (ClientId , optional) – The specific client ID for the command. If None, it will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
callback (Callable [ [UUID4 ] , None ] , optional) – The registered callback, to be called with the request ID when the response has completed processing.
callback (Callable [ [UUID4 ] , None ],可选) - 注册的回调函数,当响应完成处理时,将使用请求 ID 调用该回调函数。
Returns: The request_id for the request.
返回值:请求的 request_id。
Return type: UUID4
Raises:
引发:
ValueError – If the instrument_id is None.
ValueError - 如果 instrument_id 为 None。
TypeError – If callback is not None and not of type Callable.
TypeError - 如果 callback 不为 None 并且类型不是 Callable。
"""
...
def request_quote_ticks(self, instrument_id: InstrumentId, start: datetime=None, end: datetime=None, client_id: ClientId=None, callback=None) -> UUID4:
"""
Request historical QuoteTick data.
请求历史报价 Tick 数据。
If end is None then will request up to the most recent data.
如果 end 为 None,则将请求最多到最新数据。
Parameters:
参数:
instrument_id (InstrumentId) – The tick instrument ID for the request.
instrument_id (InstrumentId) - 请求的 tick 金融工具 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)。包含性取决于各个数据客户端的实现。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
callback (Callable [ [UUID4 ] , None ] , optional) – The registered callback, to be called with the request ID when the response has completed processing.
callback (Callable [ [UUID4 ] , None ],可选) - 注册的回调函数,当响应完成处理时,将使用请求 ID 调用该回调函数。
Returns: The request_id for the request.
返回值:请求的 request_id。
Return type: UUID4
Raises:
引发:
ValueError – If start and end are not None and start is >= end.
ValueError - 如果 start 和 end 不为 None 并且 start >= end。
TypeError – If callback is not None and not of type Callable.
TypeError - 如果 callback 不为 None 并且类型不是 Callable。
"""
...
def request_trade_ticks(self, instrument_id: InstrumentId, start: datetime=None, end: datetime=None, client_id: ClientId=None, callback=None) -> UUID4:
"""
Request historical TradeTick data.
请求历史交易 Tick 数据。
If end is None then will request up to the most recent data.
如果 end 为 None,则将请求最多到最新数据。
Parameters:
参数:
instrument_id (InstrumentId) – The tick instrument ID for the request.
instrument_id (InstrumentId) - 请求的 tick 金融工具 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)。包含性取决于各个数据客户端的实现。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
callback (Callable [ [UUID4 ] , None ] , optional) – The registered callback, to be called with the request ID when the response has completed processing.
callback (Callable [ [UUID4 ] , None ],可选) - 注册的回调函数,当响应完成处理时,将使用请求 ID 调用该回调函数。
Returns: The request_id for the request.
返回值:请求的 request_id。
Return type: UUID4
Raises:
引发:
ValueError – If start and end are not None and start is >= end.
ValueError - 如果 start 和 end 不为 None 并且 start >= end。
TypeError – If callback is not None and not of type Callable.
TypeError - 如果 callback 不为 None 并且类型不是 Callable。
"""
...
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 run_in_executor(self, func: Callable, args: tuple=None, kwargs: dict=None):
"""
Schedules the callable func to be executed as fn(*args, **kwargs).
计划可调用函数 func 以 fn(*args, **kwargs) 的形式执行。
Parameters:
参数:
func (Callable) – The function to be executed.
func (Callable) - 要执行的函数。
args (positional arguments) – The positional arguments for the call to func.
args(位置参数) - 对 func 的调用的位置参数。
kwargs (arbitrary keyword arguments) – The keyword arguments for the call to func.
```python
kwargs(任意关键字参数) - 对 func 的调用的关键字参数。
Returns: The unique task identifier for the execution. This also corresponds to any future objects memory address.
返回值:执行的唯一 task 标识符。这也对应于任何 future 对象的内存地址。
Return type: TaskId
Raises: TypeError – If func is not of type Callable.
引发:TypeError - 如果 func 的类型不是 Callable。
"""
...
def save(self) -> dict:
"""
Return the actor/strategy state dictionary to be saved.
返回要保存的 actor/strategy 状态字典。
Calls on_save.
调用 on_save。
Raises: RuntimeError – If actor/strategy is not registered with a trader.
引发:RuntimeError - 如果 actor/strategy 未在交易者处注册。
Warning:
Exceptions raised will be caught, logged, and reraised.
引发的异常将被捕获、记录并重新引发。
"""
...
def spawn_limit(self, primary: Order, quantity: Quantity, price: Price, time_in_force=TimeInForce.GTC, expire_time: datetime = None, post_only: bool = False, reduce_only: bool = False, display_qty: Quantity = None, emulation_trigger=TriggerType.NO_TRIGGER, tags: list = None, reduce_primary: bool = True):
"""
Spawn a new LIMIT order from the given primary order.
从给定的主订单生成一个新的限价订单。
Parameters:
参数:
primary (Order) – The primary order from which this order will spawn.
primary (Order) - 将从中生成此订单的主订单。
quantity (Quantity) – The spawned orders quantity (> 0). Must be less than primary.quantity.
quantity (Quantity) - 生成的订单数量 (> 0)。必须小于 primary.quantity。
price (Price) – The spawned orders price.
price (Price) - 生成的订单价格。
time_in_force (TimeInForce {GTC, IOC, FOK, GTD, DAY, AT_THE_OPEN, AT_THE_CLOSE}, default GTC) – The spawned orders time in force.
time_in_force (TimeInForce {GTC、IOC、FOK、GTD、DAY、AT_THE_OPEN、AT_THE_CLOSE},默认 GTC) - 生成的订单的有效时间。
expire_time (datetime , optional) – The spawned order expiration (for GTD orders).
expire_time (datetime,可选) - 生成的订单的到期时间(对于 GTD 订单)。
post_only (bool , default False) – If the spawned order will only provide liquidity (make a market).
post_only (bool,默认 False) - 生成的订单是否只提供流动性(做市)。
reduce_only (bool , default False) – If the spawned order carries the ‘reduce-only’ execution instruction.
reduce_only (bool,默认 False) - 生成的订单是否带有“仅减仓”执行指令。
display_qty (Quantity , optional) – The quantity of the spawned order to display on the public book (iceberg).
display_qty (Quantity,可选) - 要在公共订单簿上显示的生成的订单数量(冰山订单)。
emulation_trigger (TriggerType, default NO_TRIGGER) – The spawned orders emulation trigger.
emulation_trigger (TriggerType,默认 NO_TRIGGER) - 生成的订单的模拟触发器。
tags (list *[*str ] , optional) – The custom user tags for the order.
tags (list *[*str],可选) - 订单的自定义用户标签。
reduce_primary (bool , default True) – If the primary order quantity should be reduced by the given quantity.
reduce_primary (bool,默认 True) - 主订单数量是否应减少给定的数量。
Return type: LimitOrder
Raises:
引发:
ValueError – If primary.exec_algorithm_id is not equal to self.id.
ValueError - 如果 primary.exec_algorithm_id 不等于 self.id。
ValueError – If quantity is not positive (> 0).
ValueError - 如果数量不是正数 (> 0)。
ValueError – If time_in_force is GTD and expire_time <= UNIX epoch.
ValueError - 如果 time_in_force 为 GTD 且 expire_time <= UNIX epoch。
ValueError – If display_qty is negative (< 0) or greater than quantity.
ValueError - 如果 display_qty 为负数 (< 0) 或大于数量。
"""
...
def spawn_market(self, primary: Order, quantity: Quantity, time_in_force=TimeInForce.GTC, reduce_only: bool = False, tags: list = None, reduce_primary: bool = True):
"""
Spawn a new MARKET order from the given primary order.
从给定的主订单生成一个新的市价订单。
Parameters:
参数:
primary (Order) – The primary order from which this order will spawn.
primary (Order) - 将从中生成此订单的主订单。
quantity (Quantity) – The spawned orders quantity (> 0).
quantity (Quantity) - 生成的订单数量 (> 0)。
time_in_force (TimeInForce {GTC, IOC, FOK, DAY, AT_THE_OPEN, AT_THE_CLOSE}, default GTC) – The spawned orders time in force. Often not applicable for market orders.
time_in_force (TimeInForce {GTC、IOC、FOK、DAY、AT_THE_OPEN、AT_THE_CLOSE},默认 GTC) - 生成的订单的有效时间。通常不适用于市价订单。
reduce_only (bool , default False) – If the spawned order carries the ‘reduce-only’ execution instruction.
reduce_only (bool,默认 False) - 生成的订单是否带有“仅减仓”执行指令。
tags (list *[*str ] , optional) – The custom user tags for the order.
tags (list *[*str],可选) - 订单的自定义用户标签。
reduce_primary (bool , default True) – If the primary order quantity should be reduced by the given quantity.
reduce_primary (bool,默认 True) - 主订单数量是否应减少给定的数量。
Return type: MarketOrder
Raises:
引发:
ValueError – If primary.exec_algorithm_id is not equal to self.id.
ValueError - 如果 primary.exec_algorithm_id 不等于 self.id。
ValueError – If quantity is not positive (> 0).
ValueError - 如果数量不是正数 (> 0)。
ValueError – If time_in_force is GTD.
ValueError - 如果 time_in_force 为 GTD。
"""
...
def spawn_market_to_limit(self, primary: Order, quantity: Quantity, time_in_force=TimeInForce.GTC, expire_time: datetime = None, reduce_only: bool = False, display_qty: Quantity = None, emulation_trigger=TriggerType.NO_TRIGGER, tags: list = None, reduce_primary: bool = True):
"""
Spawn a new MARKET_TO_LIMIT order from the given primary order.
从给定的主订单生成一个新的市价转限价订单。
Parameters:
参数:
primary (Order) – The primary order from which this order will spawn.
primary (Order) - 将从中生成此订单的主订单。
quantity (Quantity) – The spawned orders quantity (> 0). Must be less than primary.quantity.
quantity (Quantity) - 生成的订单数量 (> 0)。必须小于 primary.quantity。
time_in_force (TimeInForce {GTC, IOC, FOK, GTD, DAY, AT_THE_OPEN, AT_THE_CLOSE}, default GTC) – The spawned orders time in force.
time_in_force (TimeInForce {GTC、IOC、FOK、GTD、DAY、AT_THE_OPEN、AT_THE_CLOSE},默认 GTC) - 生成的订单的有效时间。
expire_time (datetime , optional) – The spawned order expiration (for GTD orders).
expire_time (datetime,可选) - 生成的订单的到期时间(对于 GTD 订单)。
reduce_only (bool , default False) – If the spawned order carries the ‘reduce-only’ execution instruction.
reduce_only (bool,默认 False) - 生成的订单是否带有“仅减仓”执行指令。
display_qty (Quantity , optional) – The quantity of the spawned order to display on the public book (iceberg).
display_qty (Quantity,可选) - 要在公共订单簿上显示的生成的订单数量(冰山订单)。
emulation_trigger (TriggerType, default NO_TRIGGER) – The spawned orders emulation trigger.
emulation_trigger (TriggerType,默认 NO_TRIGGER) - 生成的订单的模拟触发器。
tags (list *[*str ] , optional) – The custom user tags for the order.
tags (list *[*str],可选) - 订单的自定义用户标签。
reduce_primary (bool , default True) – If the primary order quantity should be reduced by the given quantity.
reduce_primary (bool,默认 True) - 主订单数量是否应减少给定的数量。
Return type: MarketToLimitOrder
Raises:
引发:
ValueError – If primary.exec_algorithm_id is not equal to self.id.
ValueError - 如果 primary.exec_algorithm_id 不等于 self.id。
ValueError – If quantity is not positive (> 0).
ValueError - 如果数量不是正数 (> 0)。
ValueError – If time_in_force is GTD and expire_time <= UNIX epoch.
ValueError - 如果 time_in_force 为 GTD 且 expire_time <= UNIX epoch。
ValueError – If display_qty is negative (< 0) or greater than quantity.
ValueError - 如果 display_qty 为负数 (< 0) 或大于数量。
"""
...
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 submit_order(self, order: Order) -> void:
"""
Submit the given order (may be the primary or spawned order).
提交给定的订单(可以是主订单或生成的订单)。
A SubmitOrder command will be created and sent to the RiskEngine.
将创建一个 SubmitOrder 命令并将其发送到 RiskEngine。
If the client order ID is duplicate, then the order will be denied.
如果客户端订单 ID 重复,则订单将被拒绝。
Parameters:
参数:
order (Order) – The order to submit.
order (Order) - 要提交的订单。
parent_order_id (ClientOrderId , optional) – The parent client order identifier. If provided then will be considered a child order of the parent.
parent_order_id (ClientOrderId,可选) - 父客户端订单标识符。如果提供,则将被视为父订单的子订单。
Raises:
引发:
ValueError – If order.status is not INITIALIZED or RELEASED.
ValueError - 如果 order.status 不是 INITIALIZED 或 RELEASED。
ValueError – If order.emulation_trigger is not NO_TRIGGER.
ValueError - 如果 order.emulation_trigger 不是 NO_TRIGGER。
Warning:
If a position_id is passed and a position does not yet exist, then any position opened by the order will have this position ID assigned. This may not be what you intended.
如果传递了 position_id 并且持仓尚不存在,则由订单打开的任何持仓都将分配此持仓 ID。这可能不是您想要的。
Emulated orders cannot be sent from execution algorithms (intentionally constraining complexity).
模拟订单不能从执行算法发送(故意限制复杂性)。
"""
...
def subscribe_bars(self, bar_type: BarType, client_id: ClientId=None, await_partial: bool=False) -> void:
"""
Subscribe to streaming Bar data for the given bar type.
订阅给定 bar 类型的流式 Bar 数据。
Parameters:
参数:
bar_type (BarType) – The bar type to subscribe to.
bar_type (BarType) - 要订阅的 bar 类型。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
await_partial (bool , default False) – If the bar aggregator should await the arrival of a historical partial bar prior to actively aggregating new bars.
await_partial (bool,默认 False) - bar 聚合器是否应在主动聚合新 bar 之前等待历史部分 bar 的到来。
"""
...
def subscribe_data(self, data_type: DataType, client_id: ClientId=None) -> void:
"""
Subscribe to data of the given data type.
订阅给定数据类型的数据。
Parameters:
参数:
data_type (DataType) – The data type to subscribe to.
data_type (DataType) - 要订阅的数据类型。
client_id (ClientId , optional) – The data client ID. If supplied then a Subscribe command will be sent to the corresponding data client.
client_id (ClientId,可选) - 数据客户端 ID。如果提供,则将向相应的数据客户端发送 Subscribe 命令。
"""
...
def subscribe_instrument(self, instrument_id: InstrumentId, client_id: ClientId=None) -> void:
"""
Subscribe to update Instrument data for the given instrument ID.
订阅给定金融工具 ID 的更新金融工具数据。
Parameters:
参数:
instrument_id (InstrumentId) – The instrument ID for the subscription.
instrument_id (InstrumentId) - 订阅的金融工具 ID。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
"""
...
def subscribe_instrument_close(self, instrument_id: InstrumentId, client_id: ClientId=None) -> void:
"""
Subscribe to close updates for the given instrument ID.
订阅给定金融工具 ID 的收盘价更新。
Parameters:
参数:
instrument_id (InstrumentId) – The instrument to subscribe to status updates for.
instrument_id (InstrumentId) - 要订阅状态更新的金融工具。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
"""
...
def subscribe_instrument_status(self, instrument_id: InstrumentId, client_id: ClientId=None) -> void:
"""
Subscribe to status updates for the given instrument ID.
订阅给定金融工具 ID 的状态更新。
Parameters:
参数:
instrument_id (InstrumentId) – The instrument to subscribe to status updates for.
instrument_id (InstrumentId) - 要订阅状态更新的金融工具。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
"""
...
def subscribe_instruments(self, venue: Venue, client_id: ClientId=None) -> void:
"""
Subscribe to update Instrument data for the given venue.
订阅给定场所的更新金融工具数据。
Parameters:
参数:
venue (Venue) – The venue for the subscription.
venue (Venue) - 订阅的场所。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从场所推断出来。
"""
...
def subscribe_order_book_at_interval(self, instrument_id: InstrumentId, book_type=BookType.L2_MBP, depth: int=0, interval_ms: int=1000, kwargs: dict=None, client_id: ClientId=None, managed: bool=True) -> void:
"""
Subscribe to an OrderBook at a specified interval for the given instrument ID.
以指定的间隔订阅给定金融工具 ID 的订单簿。
The DataEngine will only maintain one order book for each instrument. Because of this - the level, depth and kwargs for the stream will be set as per the last subscription request (this will also affect all subscribers).
数据引擎将只为每个金融工具维护一个订单簿。因此,流的级别、深度和 kwargs 将根据最后一个订阅请求进行设置(这也会影响所有订阅者)。
Parameters:
参数:
instrument_id (InstrumentId) – The order book instrument ID to subscribe to.
instrument_id (InstrumentId) - 要订阅的订单簿金融工具 ID。
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) – The maximum depth for the order book. A depth of 0 is maximum depth.
depth (int,可选) - 订单簿的最大深度。深度为 0 表示最大深度。
interval_ms (int) – The order book snapshot interval in milliseconds (must be positive).
interval_ms (int) - 订单簿快照间隔(以毫秒为单位)(必须为正数)。
kwargs (dict , optional) – The keyword arguments for exchange specific parameters.
kwargs (dict,可选) - 交换特定参数的关键字参数。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
managed (bool , default True) – If an order book should be managed by the data engine based on the subscribed feed.
managed (bool,默认 True) - 是否应根据订阅的源由数据引擎管理订单簿。
Raises:
引发:
ValueError – If depth is negative (< 0).
ValueError - 如果 depth 为负数(< 0)。
ValueError – If interval_ms is not positive (> 0).
ValueError - 如果 interval_ms 不是正数(> 0)。
Warning:
Consider subscribing to order book deltas if you need intervals less than 100 milliseconds.
如果需要小于 100 毫秒的间隔,请考虑订阅订单簿增量。
"""
...
def subscribe_order_book_deltas(self, instrument_id: InstrumentId, book_type=BookType.L2_MBP, depth: int=0, kwargs: dict=None, client_id: ClientId=None, managed: bool=True, pyo3_conversion: bool=False) -> void:
"""
Subscribe to the order book data stream, being a snapshot then deltas for the given instrument ID.
订阅订单簿数据流,即给定金融工具 ID 的快照,然后是增量。
Parameters:
参数:
instrument_id (InstrumentId) – The order book instrument ID to subscribe to.
instrument_id (InstrumentId) - 要订阅的订单簿金融工具 ID。
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) – 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,可选) - 交换特定参数的关键字参数。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
managed (bool , default True) – If an order book should be managed by the data engine based on the subscribed feed.
managed (bool,默认 True) - 是否应根据订阅的源由数据引擎管理订单簿。
pyo3_conversion (bool , default False) – If received deltas should be converted to nautilus_pyo3.OrderBookDeltas prior to being passed to the on_order_book_deltas handler.
pyo3_conversion (bool,默认 False) - 在传递给 on_order_book_deltas 处理程序之前,是否应将接收到的增量转换为 nautilus_pyo3.OrderBookDeltas。
"""
...
def subscribe_quote_ticks(self, instrument_id: InstrumentId, client_id: ClientId=None) -> void:
"""
Subscribe to streaming QuoteTick data for the given instrument ID.
订阅给定金融工具 ID 的流式报价 Tick 数据。
Parameters:
参数:
instrument_id (InstrumentId) – The tick instrument to subscribe to.
instrument_id (InstrumentId) - 要订阅的 tick 金融工具。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
"""
...
def subscribe_signal(self, name: str='') -> void:
"""
Subscribe to a specific signal by name, or to all signals if no name is provided.
按名称订阅特定信号,或者如果没有提供名称,则订阅所有信号。
Parameters: name (str , optional) – The name of the signal to subscribe to. If not provided or an empty string is passed, the subscription will include all signals. The signal name is case-insensitive and will be capitalized (e.g., ‘example’ becomes ‘SignalExample*’).
参数:name (str,可选) - 要订阅的信号的名称。如果没有提供或传递空字符串,则订阅将包含所有信号。信号名称不区分大小写,并且将大写(例如,“example”变为“SignalExample*”)。
"""
...
def subscribe_trade_ticks(self, instrument_id: InstrumentId, client_id: ClientId=None) -> void:
"""
Subscribe to streaming TradeTick data for the given instrument ID.
订阅给定金融工具 ID 的流式交易 Tick 数据。
Parameters:
参数:
instrument_id (InstrumentId) – The tick instrument to subscribe to.
instrument_id (InstrumentId) - 要订阅的 tick 金融工具。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
"""
...
def to_importable_config(self) -> ImportableExecAlgorithmConfig:
"""
Returns an importable configuration for this execution algorithm.
返回此执行算法的可导入配置。
Return type: ImportableExecAlgorithmConfig
"""
...
def unsubscribe_bars(self, bar_type: BarType, client_id: ClientId=None) -> void:
"""
Unsubscribe from streaming Bar data for the given bar type.
取消订阅给定 bar 类型的流式 Bar 数据。
Parameters:
参数:
bar_type (BarType) – The bar type to unsubscribe from.
bar_type (BarType) - 要取消订阅的 bar 类型。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
"""
...
def unsubscribe_data(self, data_type: DataType, client_id: ClientId=None) -> void:
"""
Unsubscribe from data of the given data type.
取消订阅给定数据类型的数据。
Parameters:
参数:
data_type (DataType) – The data type to unsubscribe from.
data_type (DataType) - 要取消订阅的数据类型。
client_id (ClientId , optional) – The data client ID. If supplied then an Unsubscribe command will be sent to the data client.
client_id (ClientId,可选) - 数据客户端 ID。如果提供,则将向数据客户端发送 Unsubscribe 命令。
"""
...
def unsubscribe_instrument(self, instrument_id: InstrumentId, client_id: ClientId=None) -> void:
"""
Unsubscribe from update Instrument data for the given instrument ID.
取消订阅给定金融工具 ID 的更新金融工具数据。
Parameters:
参数:
instrument_id (InstrumentId) – The instrument to unsubscribe from.
instrument_id (InstrumentId) - 要取消订阅的金融工具。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
"""
...
def unsubscribe_instrument_status(self, instrument_id: InstrumentId, client_id: ClientId=None) -> void:
"""
Unsubscribe to status updates of the given venue.
取消订阅给定场所的状态更新。
Parameters:
参数:
instrument_id (InstrumentId) – The instrument to unsubscribe to status updates for.
instrument_id (InstrumentId) - 要取消订阅状态更新的金融工具。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从场所推断出来。
"""
...
def unsubscribe_instruments(self, venue: Venue, client_id: ClientId=None) -> void:
"""
Unsubscribe from update Instrument data for the given venue.
取消订阅给定场所的更新金融工具数据。
Parameters:
参数:
venue (Venue) – The venue for the subscription.
venue (Venue) - 订阅的场所。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从场所推断出来。
"""
...
def unsubscribe_order_book_at_interval(self, instrument_id: InstrumentId, interval_ms: int=1000, client_id: ClientId=None) -> void:
"""
Unsubscribe from an OrderBook at a specified interval for the given instrument ID.
以指定的间隔取消订阅给定金融工具 ID 的订单簿。
The interval must match the previously subscribed interval.
间隔必须与之前订阅的间隔匹配。
Parameters:
参数:
instrument_id (InstrumentId) – The order book instrument to subscribe to.
instrument_id (InstrumentId) - 要订阅的订单簿金融工具。
interval_ms (int) – The order book snapshot interval in milliseconds.
interval_ms (int) - 订单簿快照间隔(以毫秒为单位)。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
"""
...
def unsubscribe_order_book_deltas(self, instrument_id: InstrumentId, client_id: ClientId=None) -> void:
"""
Unsubscribe the order book deltas stream for the given instrument ID.
取消订阅给定金融工具 ID 的订单簿增量流。
Parameters:
参数:
instrument_id (InstrumentId) – The order book instrument to subscribe to.
instrument_id (InstrumentId) - 要订阅的订单簿金融工具。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
"""
...
def unsubscribe_quote_ticks(self, instrument_id: InstrumentId, client_id: ClientId=None) -> void:
"""
Unsubscribe from streaming QuoteTick data for the given instrument ID.
取消订阅给定金融工具 ID 的流式报价 Tick 数据。
Parameters:
参数:
instrument_id (InstrumentId) – The tick instrument to unsubscribe from.
instrument_id (InstrumentId) - 要取消订阅的 tick 金融工具。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
"""
...
def unsubscribe_trade_ticks(self, instrument_id: InstrumentId, client_id: ClientId=None) -> void:
"""
Unsubscribe from streaming TradeTick data for the given instrument ID.
取消订阅给定金融工具 ID 的流式交易 Tick 数据。
Parameters:
参数:
instrument_id (InstrumentId) – The tick instrument ID to unsubscribe from.
instrument_id (InstrumentId) - 要取消订阅的 tick 金融工具 ID。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
"""
...
def update_synthetic(self, synthetic: SyntheticInstrument) -> void:
"""
Update the synthetic instrument in the cache.
更新缓存中的合成金融工具。
Parameters: synthetic (SyntheticInstrument) – The synthetic instrument to update in the cache.
参数:synthetic (SyntheticInstrument) - 要在缓存中更新的合成金融工具。
Raises: KeyError – If synthetic does not already exist in the cache.
引发:KeyError - 如果合成金融工具在缓存中不存在。
"""
...
class ExecutionClient 执行客户端
Bases: Component
class ExecutionClient(Component):
"""
The base class for all execution clients.
所有执行客户端的基类。
Parameters:
参数:
client_id (ClientId) – The client ID.
client_id (ClientId) - 客户端 ID。
venue (Venue, optional with no default so None must be passed explicitly) – The client venue. If multi-venue then can be None.
venue (Venue,可选,没有默认值,因此必须显式传递 None) - 客户端场所。如果是多场所,则可以为 None。
oms_type (OmsType) – The venues order management system type.
oms_type (OmsType) - 场所的订单管理系统类型。
account_type (AccountType) – The account type for the client.
account_type (AccountType) - 客户端的账户类型。
base_currency (Currency, optional with no default so None must be passed explicitly) – The account base currency. Use None for multi-currency accounts.
base_currency (Currency,可选,没有默认值,因此必须显式传递 None) - 账户基础货币。对于多币种账户,请使用 None。
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) - 客户端的时钟。
config (NautilusConfig , optional) – The configuration for the instance.
config (NautilusConfig,可选) - 实例的配置。
Raises:
引发:
ValueError – If client_id is not equal to account_id.get_issuer().
ValueError - 如果 client_id 不等于 account_id.get_issuer()。
ValueError – If oms_type is UNSPECIFIED (must be specified).
ValueError - 如果 oms_type 为 UNSPECIFIED(必须指定)。
Warning:
This class should not be used directly, but through a concrete subclass.
此类不应直接使用,而应通过具体的子类使用。
"""
def __init__(self, client_id: ClientId, venue: Venue | None, oms_type: OmsType, account_type: AccountType, base_currency: Currency | None, msgbus: MessageBus, cache: Cache, clock: Clock, config: NautilusConfig | None = None):
...
Properties 属性
@property
def account_id(self):
"""
The clients account ID.
客户端的账户 ID。
```python
Returns:
AccountId or None
"""
...
@property
def account_type(self) -> AccountType:
"""
The clients account type.
客户端的账户类型。
Returns:
AccountType
"""
...
@property
def base_currency(self):
"""
The clients account base currency (None for multi-currency accounts).
客户端的账户基础货币(对于多币种账户,为 None)。
Returns:
Currency or 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 oms_type(self) -> OmsType:
"""
The venues order management system type.
场所的订单管理系统类型。
Returns:
OmsType
"""
...
@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 not a routing client).
客户端的场所 ID(如果不是路由客户端)。
Returns:
Venue or None
"""
...
Methods 方法
def batch_cancel_orders(self, command: BatchCancelOrders) -> void:
"""
Batch cancel orders for the instrument ID contained in the given command.
批量取消给定命令中包含的金融工具 ID 的订单。
Parameters: command (BatchCancelOrders) – The command to execute.
参数:command (BatchCancelOrders) - 要执行的命令。
"""
...
def cancel_all_orders(self, command: CancelAllOrders) -> void:
"""
Cancel all orders for the instrument ID contained in the given command.
取消给定命令中包含的金融工具 ID 的所有订单。
Parameters: command (CancelAllOrders) – The command to execute.
参数:command (CancelAllOrders) - 要执行的命令。
"""
...
def cancel_order(self, command: CancelOrder) -> void:
"""
Cancel the order with the client order ID contained in the given command.
取消给定命令中包含的客户端订单 ID 的订单。
Parameters: command (CancelOrder) – The command to execute.
参数:command (CancelOrder) - 要执行的命令。
"""
...
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 generate_account_state(self, balances: list, margins: list, reported: bool, ts_event: int, info: dict = None) -> void:
"""
Generate an AccountState event and publish on the message bus.
生成 AccountState 事件并在消息总线上发布。
Parameters:
参数:
balances (list [AccountBalance ]) – The account balances.
balances (list [AccountBalance ]) - 账户余额。
margins (list [MarginBalance ]) – The margin balances.
margins (list [MarginBalance ]) - 保证金余额。
reported (bool) – If the balances are reported directly from the exchange.
reported (bool) - 余额是否直接从交易所报告。
ts_event (uint64_t) – UNIX timestamp (nanoseconds) when the account state event occurred.
ts_event (uint64_t) - 账户状态事件发生的 UNIX 时间戳(纳秒)。
info (dict *[*str , object ]) – The additional implementation specific account information.
info (dict *[*str,object]) - 其他特定于实现的账户信息。
"""
...
def generate_order_accepted(self, strategy_id: StrategyId, instrument_id: InstrumentId, client_order_id: ClientOrderId, venue_order_id: VenueOrderId, ts_event: int) -> void:
"""
Generate an OrderAccepted event and send it to the ExecutionEngine.
生成 OrderAccepted 事件并将其发送到 ExecutionEngine。
Parameters:
参数:
strategy_id (StrategyId) – The strategy ID associated with the event.
strategy_id (StrategyId) - 与事件关联的策略 ID。
instrument_id (InstrumentId) – The instrument ID.
instrument_id (InstrumentId) - 金融工具 ID。
client_order_id (ClientOrderId) – The client order ID.
client_order_id (ClientOrderId) - 客户端订单 ID。
venue_order_id (VenueOrderId) – The venue order ID (assigned by the venue).
venue_order_id (VenueOrderId) - 场所订单 ID(由场所分配)。
ts_event (uint64_t) – UNIX timestamp (nanoseconds) when the order accepted event occurred.
ts_event (uint64_t) - 订单接受事件发生的 UNIX 时间戳(纳秒)。
"""
...
def generate_order_cancel_rejected(self, strategy_id: StrategyId, instrument_id: InstrumentId, client_order_id: ClientOrderId, venue_order_id: VenueOrderId, reason: str, ts_event: int) -> void:
"""
Generate an OrderCancelRejected event and send it to the ExecutionEngine.
生成 OrderCancelRejected 事件并将其发送到 ExecutionEngine。
Parameters:
参数:
strategy_id (StrategyId) – The strategy ID associated with the event.
strategy_id (StrategyId) - 与事件关联的策略 ID。
instrument_id (InstrumentId) – The instrument ID.
instrument_id (InstrumentId) - 金融工具 ID。
client_order_id (ClientOrderId) – The client order ID.
client_order_id (ClientOrderId) - 客户端订单 ID。
venue_order_id (VenueOrderId) – The venue order ID (assigned by the venue).
venue_order_id (VenueOrderId) - 场所订单 ID(由场所分配)。
reason (str) – The order cancel rejected reason.
reason (str) - 订单取消拒绝的原因。
ts_event (uint64_t) – UNIX timestamp (nanoseconds) when the order cancel rejected event occurred.
ts_event (uint64_t) - 订单取消拒绝事件发生的 UNIX 时间戳(纳秒)。
"""
...
def generate_order_canceled(self, strategy_id: StrategyId, instrument_id: InstrumentId, client_order_id: ClientOrderId, venue_order_id: VenueOrderId, ts_event: int) -> void:
"""
Generate an OrderCanceled event and send it to the ExecutionEngine.
生成 OrderCanceled 事件并将其发送到 ExecutionEngine。
Parameters:
参数:
strategy_id (StrategyId) – The strategy ID associated with the event.
strategy_id (StrategyId) - 与事件关联的策略 ID。
instrument_id (InstrumentId) – The instrument ID.
instrument_id (InstrumentId) - 金融工具 ID。
client_order_id (ClientOrderId) – The client order ID.
client_order_id (ClientOrderId) - 客户端订单 ID。
venue_order_id (VenueOrderId) – The venue order ID (assigned by the venue).
venue_order_id (VenueOrderId) - 场所订单 ID(由场所分配)。
ts_event (uint64_t) – UNIX timestamp (nanoseconds) when order canceled event occurred.
ts_event (uint64_t) - 订单取消事件发生的 UNIX 时间戳(纳秒)。
"""
...
def generate_order_expired(self, strategy_id: StrategyId, instrument_id: InstrumentId, client_order_id: ClientOrderId, venue_order_id: VenueOrderId, ts_event: int) -> void:
"""
Generate an OrderExpired event and send it to the ExecutionEngine.
生成 OrderExpired 事件并将其发送到 ExecutionEngine。
Parameters:
参数:
strategy_id (StrategyId) – The strategy ID associated with the event.
strategy_id (StrategyId) - 与事件关联的策略 ID。
instrument_id (InstrumentId) – The instrument ID.
instrument_id (InstrumentId) - 金融工具 ID。
client_order_id (ClientOrderId) – The client order ID.
client_order_id (ClientOrderId) - 客户端订单 ID。
venue_order_id (VenueOrderId) – The venue order ID (assigned by the venue).
venue_order_id (VenueOrderId) - 场所订单 ID(由场所分配)。
ts_event (uint64_t) – UNIX timestamp (nanoseconds) when the order expired event occurred.
ts_event (uint64_t) - 订单过期事件发生的 UNIX 时间戳(纳秒)。
"""
...
def generate_order_filled(self, strategy_id: StrategyId, instrument_id: InstrumentId, client_order_id: ClientOrderId, venue_order_id: VenueOrderId, venue_position_id: PositionId | None, trade_id: TradeId, order_side: OrderSide, order_type: OrderType, last_qty: Quantity, last_px: Price, quote_currency: Currency, commission: Money, liquidity_side: LiquiditySide, ts_event: int) -> void:
"""
Generate an OrderFilled event and send it to the ExecutionEngine.
生成 OrderFilled 事件并将其发送到 ExecutionEngine。
Parameters:
参数:
strategy_id (StrategyId) – The strategy ID associated with the event.
strategy_id (StrategyId) - 与事件关联的策略 ID。
instrument_id (InstrumentId) – The instrument ID.
instrument_id (InstrumentId) - 金融工具 ID。
client_order_id (ClientOrderId) – The client order ID.
client_order_id (ClientOrderId) - 客户端订单 ID。
venue_order_id (VenueOrderId) – The venue order ID (assigned by the venue).
venue_order_id (VenueOrderId) - 场所订单 ID(由场所分配)。
trade_id (TradeId) – The trade ID.
trade_id (TradeId) - 交易 ID。
venue_position_id (PositionId, optional with no default so None must be passed explicitly) – The venue position ID associated with the order. If the trading venue has assigned a position ID / ticket then pass that here, otherwise pass None and the execution engine OMS will handle position ID resolution.
venue_position_id (PositionId,可选,没有默认值,因此必须显式传递 None) - 与订单关联的场所持仓 ID。如果交易场所已为交易分配了持仓 ID/票据,则在此处传递该 ID,否则传递 None,执行引擎 OMS 将处理持仓 ID 解析。
order_side (OrderSide {BUY, SELL}) – The execution order side.
order_side (OrderSide {BUY、SELL}) - 执行订单方向。
order_type (OrderType) – The execution order type.
order_type (OrderType) - 执行订单类型。
last_qty (Quantity) – The fill quantity for this execution.
last_qty (Quantity) - 此执行的成交数量。
last_px (Price) – The fill price for this execution (not average price).
last_px (Price) - 此执行的成交价格(不是平均价格)。
quote_currency (Currency) – The currency of the price.
quote_currency (Currency) - 价格的货币。
commission (Money) – The fill commission.
commission (Money) - 成交佣金。
liquidity_side (LiquiditySide {NO_LIQUIDITY_SIDE, MAKER, TAKER}) – The execution liquidity side.
liquidity_side (LiquiditySide {NO_LIQUIDITY_SIDE、MAKER、TAKER}) - 执行流动性方向。
ts_event (uint64_t) – UNIX timestamp (nanoseconds) when the order filled event occurred.
ts_event (uint64_t) - 订单成交事件发生的 UNIX 时间戳(纳秒)。
"""
...
def generate_order_modify_rejected(self, strategy_id: StrategyId, instrument_id: InstrumentId, client_order_id: ClientOrderId, venue_order_id: VenueOrderId, reason: str, ts_event: int) -> void:
"""
Generate an OrderModifyRejected event and send it to the ExecutionEngine.
生成 OrderModifyRejected 事件并将其发送到 ExecutionEngine。
Parameters:
参数:
strategy_id (StrategyId) – The strategy ID associated with the event.
strategy_id (StrategyId) - 与事件关联的策略 ID。
instrument_id (InstrumentId) – The instrument ID.
instrument_id (InstrumentId) - 金融工具 ID。
client_order_id (ClientOrderId) – The client order ID.
client_order_id (ClientOrderId) - 客户端订单 ID。
venue_order_id (VenueOrderId) – The venue order ID (assigned by the venue).
venue_order_id (VenueOrderId) - 场所订单 ID(由场所分配)。
reason (str) – The order update rejected reason.
reason (str) - 订单更新拒绝的原因。
ts_event (uint64_t) – UNIX timestamp (nanoseconds) when the order update rejection event occurred.
ts_event (uint64_t) - 订单更新拒绝事件发生的 UNIX 时间戳(纳秒)。
"""
...
def generate_order_rejected(self, strategy_id: StrategyId, instrument_id: InstrumentId, client_order_id: ClientOrderId, reason: datetime, ts_event: int) -> void:
"""
Generate an OrderRejected event and send it to the ExecutionEngine.
生成 OrderRejected 事件并将其发送到 ExecutionEngine。
Parameters:
参数:
strategy_id (StrategyId) – The strategy ID associated with the event.
strategy_id (StrategyId) - 与事件关联的策略 ID。
instrument_id (InstrumentId) – The instrument ID.
instrument_id (InstrumentId) - 金融工具 ID。
client_order_id (ClientOrderId) – The client order ID.
client_order_id (ClientOrderId) - 客户端订单 ID。
reason (datetime) – The order rejected reason.
reason (datetime) - 订单拒绝的原因。
ts_event (uint64_t) – UNIX timestamp (nanoseconds) when the order rejected event occurred.
ts_event (uint64_t) - 订单拒绝事件发生的 UNIX 时间戳(纳秒)。
"""
...
def generate_order_submitted(self, strategy_id: StrategyId, instrument_id: InstrumentId, client_order_id: ClientOrderId, ts_event: int) -> void:
"""
Generate an OrderSubmitted event and send it to the ExecutionEngine.
生成 OrderSubmitted 事件并将其发送到 ExecutionEngine。
Parameters:
参数:
strategy_id (StrategyId) – The strategy ID associated with the event.
strategy_id (StrategyId) - 与事件关联的策略 ID。
instrument_id (InstrumentId) – The instrument ID.
instrument_id (InstrumentId) - 金融工具 ID。
client_order_id (ClientOrderId) – The client order ID.
client_order_id (ClientOrderId) - 客户端订单 ID。
ts_event (uint64_t) – UNIX timestamp (nanoseconds) when the order submitted event occurred.
ts_event (uint64_t) - 订单提交事件发生的 UNIX 时间戳(纳秒)。
"""
...
def generate_order_triggered(self, strategy_id: StrategyId, instrument_id: InstrumentId, client_order_id: ClientOrderId, venue_order_id: VenueOrderId, ts_event: int) -> void:
"""
Generate an OrderTriggered event and send it to the ExecutionEngine.
生成 OrderTriggered 事件并将其发送到 ExecutionEngine。
Parameters:
参数:
strategy_id (StrategyId) – The strategy ID associated with the event.
strategy_id (StrategyId) - 与事件关联的策略 ID。
instrument_id (InstrumentId) – The instrument ID.
instrument_id (InstrumentId) - 金融工具 ID。
client_order_id (ClientOrderId) – The client order ID.
client_order_id (ClientOrderId) - 客户端订单 ID。
venue_order_id (VenueOrderId) – The venue order ID (assigned by the venue).
venue_order_id (VenueOrderId) - 场所订单 ID(由场所分配)。
ts_event (uint64_t) – UNIX timestamp (nanoseconds) when the order triggered event occurred.
ts_event (uint64_t) - 订单触发事件发生的 UNIX 时间戳(纳秒)。
"""
...
def generate_order_updated(self, strategy_id: StrategyId, instrument_id: InstrumentId, client_order_id: ClientOrderId, venue_order_id: VenueOrderId, quantity: Quantity, price: Price, trigger_price: Price, ts_event: int, venue_order_id_modified: bool = False) -> void:
"""
Generate an OrderUpdated event and send it to the ExecutionEngine.
生成 OrderUpdated 事件并将其发送到 ExecutionEngine。
Parameters:
参数:
strategy_id (StrategyId) – The strategy ID associated with the event.
strategy_id (StrategyId) - 与事件关联的策略 ID。
instrument_id (InstrumentId) – The instrument ID.
instrument_id (InstrumentId) - 金融工具 ID。
client_order_id (ClientOrderId) – The client order ID.
client_order_id (ClientOrderId) - 客户端订单 ID。
venue_order_id (VenueOrderId) – The venue order ID (assigned by the venue).
venue_order_id (VenueOrderId) - 场所订单 ID(由场所分配)。
quantity (Quantity) – The orders current quantity.
quantity (Quantity) - 订单的当前数量。
price (Price) – The orders current price.
price (Price) - 订单的当前价格。
trigger_price (Price, optional with no default so None must be passed explicitly) – The orders current trigger price.
trigger_price (Price,可选,没有默认值,因此必须显式传递 None) - 订单的当前触发价格。
ts_event (uint64_t) – UNIX timestamp (nanoseconds) when the order update event occurred.
ts_event (uint64_t) - 订单更新事件发生的 UNIX 时间戳(纳秒)。
venue_order_id_modified (bool) – If the ID was modified for this event.
venue_order_id_modified (bool) - 此事件的 ID 是否已修改。
"""
...
def get_account(self) -> Account:
"""
Return the account for the client (if registered).
返回客户端的账户(如果已注册)。
Return type: Account or None
"""
...
def modify_order(self, command: ModifyOrder) -> void:
"""
Modify the order with parameters contained in the command.
使用命令中包含的参数修改订单。
Parameters: command (ModifyOrder) – The command to execute.
参数:command (ModifyOrder) - 要执行的命令。
"""
...
def query_order(self, command: QueryOrder) -> void:
"""
Initiate a reconciliation for the queried order which will generate an OrderStatusReport.
启动对查询订单的对账,这将生成 OrderStatusReport。
Parameters: command (QueryOrder) – The command to execute.
参数:command (QueryOrder) - 要执行的命令。
"""
...
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 submit_order(self, command: SubmitOrder) -> void:
"""
Submit the order contained in the given command for execution.
提交给定命令中包含的订单以执行。
Parameters: command (SubmitOrder) – The command to execute.
参数:command (SubmitOrder) - 要执行的命令。
"""
...
def submit_order_list(self, command: SubmitOrderList) -> void:
"""
Submit the order list contained in the given command for execution.
提交给定命令中包含的订单列表以执行。
Parameters: command (SubmitOrderList) – The command to execute.
参数:command (SubmitOrderList) - 要执行的命令。
"""
...
class OrderEmulator 订单模拟器
Bases: Actor
class OrderEmulator(Actor):
"""
Provides order emulation for specified trigger types.
为指定的触发器类型提供订单模拟。
Parameters:
参数:
portfolio (PortfolioFacade) – The read-only portfolio for the order emulator.
portfolio (PortfolioFacade) - 订单模拟器的只读投资组合。
msgbus (MessageBus) – The message bus for the order emulator.
msgbus (MessageBus) - 订单模拟器的消息总线。
cache (Cache) – The cache for the order emulator.
cache (Cache) - 订单模拟器的缓存。
clock (Clock) – The clock for the order emulator.
clock (Clock) - 订单模拟器的时钟。
config (OrderEmulatorConfig , optional) – The configuration for the order emulator.
config (OrderEmulatorConfig,可选) - 订单模拟器的配置。
"""
def __init__(self, portfolio: PortfolioFacade, msgbus: MessageBus, cache: Cache, clock: Clock, config: OrderEmulatorConfig | None = None):
...
Properties 属性
@property
def cache(self):
"""
The read-only cache for the actor.
actor 的只读缓存。
Returns:
CacheFacade
"""
...
@property
def clock(self):
"""
The actors clock.
actor 的时钟。
Returns:
Clock
"""
...
@property
def command_count(self):
"""
The total count of commands received by the emulator.
模拟器接收到的命令总数。
Returns:
int
"""
...
@property
def config(self):
"""
The actors configuration.
actor 的配置。
Returns:
NautilusConfig
"""
...
@property
def debug(self):
"""
If debug mode is active (will provide extra debug logging).
如果调试模式处于活动状态(将提供额外的调试日志)。
Returns:
bool
"""
...
@property
def event_count(self):
"""
The total count of events received by the emulator.
模拟器接收到的事件总数。
Returns:
int
"""
...
@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 log(self) :
"""
The actors logger.
actor 的日志记录器。
Returns:
Logger
"""
...
@property
def msgbus(self):
"""
The message bus for the actor (if registered).
actor 的消息总线(如果已注册)。
Returns:
MessageBus or None
"""
...
@property
def portfolio(self):
"""
The read-only portfolio for the actor.
actor 的只读投资组合。
Returns:
PortfolioFacade
"""
...
@property
def registered_indicators(self):
"""
Return the registered indicators for the strategy.
返回策略的已注册指标。
Return type: list[Indicator]
"""
...
@property
def state(self) -> ComponentState:
"""
ComponentState
Return the components current state.
返回组件的当前状态。
Return type: ComponentState
Type: Component.state
"""
...
@property
def subscribed_quotes(self) -> list[InstrumentId]:
"""
list[InstrumentId]
Return the subscribed quote feeds for the emulator.
返回模拟器订阅的报价源。
Return type: list[InstrumentId]
Type: OrderEmulator.subscribed_quotes
"""
...
@property
def subscribed_trades(self) -> list[InstrumentId]:
"""
list[InstrumentId]
Return the subscribed trade feeds for the emulator.
返回模拟器订阅的交易源。
Return type: list[InstrumentId]
Type: OrderEmulator.subscribed_trades
"""
...
@property
def trader_id(self):
"""
The trader ID associated with the component.
与组件关联的交易者 ID。
Returns:
TraderId
"""
...
@property
def type(self):
"""
The components type.
组件类型。
Returns:
type
"""
...
Methods 方法
def active_task_ids(self) -> list:
"""
Return the active task identifiers.
返回活动的 task 标识符。
Return type: list[TaskId]
"""
...
def add_synthetic(self, synthetic: SyntheticInstrument) -> void:
"""
Add the created synthetic instrument to the cache.
将创建的合成金融工具添加到缓存中。
Parameters: synthetic (SyntheticInstrument) – The synthetic instrument to add to the cache.
参数:synthetic (SyntheticInstrument) - 要添加到缓存中的合成金融工具。
Raises: KeyError – If synthetic is already in the cache.
引发:KeyError - 如果合成金融工具已存在于缓存中。
"""
...
def cancel_all_tasks(self) -> void:
"""
Cancel all queued and active tasks.
取消所有排队和活动的 task。
"""
...
def cancel_task(self, task_id: TaskId) -> void:
"""
Cancel the task with the given task_id (if queued or active).
取消具有给定 task_id 的任务(如果已排队或活动)。
If the task is not found then a warning is logged.
如果未找到任务,则会记录警告。
Parameters: task_id (TaskId) – The task identifier.
参数:task_id (TaskId) – 任务标识符。
"""
...
def create_matching_core(self, instrument_id: InstrumentId, price_increment: Price):
"""
Create an internal matching core for the given instrument.
为给定的金融工具创建一个内部匹配核心。
Parameters:
参数:
instrument_id (InstrumentId) – The instrument ID for the matching core.
instrument_id (InstrumentId) - 匹配核心的金融工具 ID。
price_increment (Price) – The minimum price increment (tick size) for the matching core.
price_increment (Price) - 匹配核心的最小价格增量(刻度大小)。
```python
Return type: MatchingCore
Raises: KeyError – If a matching core for the given instrument_id already exists.
引发:KeyError - 如果给定 instrument_id 的匹配核心已存在。
"""
...
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_warning_event(self, event) -> void:
"""
Deregister the given event type from warning log levels.
从警告日志级别取消注册给定的事件类型。
Parameters: event (type) – The event class to deregister.
参数:event (type) - 要取消注册的事件类。
"""
...
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: TradingCommand) -> void:
"""
Execute the given command.
执行给定的命令。
Parameters: command (TradingCommand) – The command to execute.
参数:command (TradingCommand) - 要执行的命令。
"""
...
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 get_matching_core(self, instrument_id: InstrumentId):
"""
Return the emulators matching core for the given instrument ID.
返回给定金融工具 ID 的模拟器的匹配核心。
Return type: MatchingCore or None
"""
...
def get_submit_order_commands(self) -> dict[ClientOrderId, SubmitOrder]:
"""
Return the emulators cached submit order commands.
返回模拟器缓存的提交订单命令。
Return type: dict[ClientOrderId, SubmitOrder]
"""
...
def handle_bar(self, bar: Bar) -> void:
"""
Handle the given bar data.
处理给定的 bar 数据。
If state is RUNNING then passes to on_bar.
如果状态为 RUNNING,则传递给 on_bar。
Parameters: bar (Bar) – The bar received.
参数:bar (Bar) - 接收到的 bar。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def handle_bars(self, bars: list) -> void:
"""
Handle the given historical bar data by handling each bar individually.
通过单独处理每个 bar 来处理给定的历史 bar 数据。
Parameters: bars (list [Bar ]) – The bars to handle.
参数:bars (list [Bar ]) - 要处理的 bar。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def handle_data(self, data: Data) -> void:
"""
Handle the given data.
处理给定的数据。
If state is RUNNING then passes to on_data.
如果状态为 RUNNING,则传递给 on_data。
Parameters: data (Data) – The data received.
参数:data (Data) - 接收到的数据。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def handle_event(self, event: Event) -> void:
"""
Handle the given event.
处理给定的事件。
If state is RUNNING then passes to on_event.
如果状态为 RUNNING,则传递给 on_event。
Parameters: event (Event) – The event received.
参数:event (Event) - 接收到的事件。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def handle_historical_data(self, data) -> void:
"""
Handle the given historical data.
处理给定的历史数据。
Parameters: data (Data) – The historical data received.
参数:data (Data) - 接收到的历史数据。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def handle_instrument(self, instrument: Instrument) -> void:
"""
Handle the given instrument.
处理给定的金融工具。
Passes to on_instrument if state is RUNNING.
如果状态为 RUNNING,则传递给 on_instrument。
Parameters: instrument (Instrument) – The instrument received.
参数:instrument (Instrument) - 接收到的金融工具。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def handle_instrument_close(self, update: InstrumentClose) -> void:
"""
Handle the given instrument close update.
处理给定的金融工具关闭更新。
If state is RUNNING then passes to on_instrument_close.
如果状态为 RUNNING,则传递给 on_instrument_close。
Parameters: update (InstrumentClose) – The update received.
参数:update (InstrumentClose) - 接收到的更新。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def handle_instrument_status(self, data: InstrumentStatus) -> void:
"""
Handle the given instrument status update.
处理给定的金融工具状态更新。
If state is RUNNING then passes to on_instrument_status.
如果状态为 RUNNING,则传递给 on_instrument_status。
Parameters: data (InstrumentStatus) – The status update received.
参数:data (InstrumentStatus) - 接收到的状态更新。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def handle_instruments(self, instruments: list) -> void:
"""
Handle the given instruments data by handling each instrument individually.
通过单独处理每个金融工具来处理给定的金融工具数据。
Parameters: instruments (list [Instrument ]) – The instruments received.
参数:instruments (list [Instrument ]) - 接收到的金融工具。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def handle_order_book(self, order_book: OrderBook) -> void:
"""
Handle the given order book.
处理给定的订单簿。
Passes to on_order_book if state is RUNNING.
如果状态为 RUNNING,则传递给 on_order_book。
Parameters: order_book (OrderBook) – The order book received.
参数:order_book (OrderBook) - 接收到的订单簿。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def handle_order_book_deltas(self, deltas) -> void:
"""
Handle the given order book deltas.
处理给定的订单簿增量。
Passes to on_order_book_deltas if state is RUNNING. The deltas will be nautilus_pyo3.OrderBookDeltas if the pyo3_conversion flag was set for the subscription.
如果状态为 RUNNING,则传递给 on_order_book_deltas。如果为订阅设置了 pyo3_conversion 标志,则增量将为 nautilus_pyo3.OrderBookDeltas。
Parameters: deltas (OrderBookDeltas or nautilus_pyo3.OrderBookDeltas) – The order book deltas received.
参数:deltas (OrderBookDeltas or nautilus_pyo3.OrderBookDeltas) - 接收到的订单簿增量。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def handle_quote_tick(self, tick: QuoteTick) -> void:
"""
Handle the given quote tick.
处理给定的报价 tick。
If state is RUNNING then passes to on_quote_tick.
如果状态为 RUNNING,则传递给 on_quote_tick。
Parameters: tick (QuoteTick) – The tick received.
参数:tick (QuoteTick) - 接收到的 tick。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def handle_quote_ticks(self, ticks: list) -> void:
"""
Handle the given historical quote tick data by handling each tick individually.
通过单独处理每个 tick 来处理给定的历史报价 tick 数据。
Parameters: ticks (list [QuoteTick ]) – The ticks received.
参数:ticks (list [QuoteTick ]) - 接收到的 tick。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def handle_trade_tick(self, tick: TradeTick) -> void:
"""
Handle the given trade tick.
处理给定的交易 tick。
If state is RUNNING then passes to on_trade_tick.
如果状态为 RUNNING,则传递给 on_trade_tick。
Parameters: tick (TradeTick) – The tick received.
参数:tick (TradeTick) - 接收到的 tick。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def handle_trade_ticks(self, ticks: list) -> void:
"""
Handle the given historical trade tick data by handling each tick individually.
通过单独处理每个 tick 来处理给定的历史交易 tick 数据。
Parameters: ticks (list [TradeTick ]) – The ticks received.
参数:ticks (list [TradeTick ]) - 接收到的 tick。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def has_active_tasks(self) -> bool:
"""
Return a value indicating whether there are any active tasks.
返回值指示是否有任何活动的 task。
Return type: bool
"""
...
def has_any_tasks(self) -> bool:
"""
Return a value indicating whether there are any queued or active tasks.
返回值指示是否有任何排队或活动的 task。
Return type: bool
"""
...
def has_pending_requests(self) -> bool:
"""
Return whether the actor is pending processing for any requests.
返回 actor 是否正在等待处理任何请求。
Returns: True if any requests are pending, else False.
返回值:如果有任何请求正在等待处理,则返回 True,否则返回 False。
Return type: bool
"""
...
def has_queued_tasks(self) -> bool:
"""
Return a value indicating whether there are any queued tasks.
返回值指示是否有任何排队的 task。
Return type: bool
"""
...
def indicators_initialized(self) -> bool:
"""
Return a value indicating whether all indicators are initialized.
返回值指示是否所有指标都已初始化。
Returns: True if all initialized, else False
返回值:如果所有指标都已初始化,则返回 True,否则返回 False。
Return type: bool
"""
...
def is_pending_request(self, request_id: UUID4) -> bool:
"""
Return whether the request for the given identifier is pending processing.
返回给定标识符的请求是否正在等待处理。
Parameters: request_id (UUID4) – The request ID to check.
参数:request_id (UUID4) - 要检查的请求 ID。
Returns: True if request is pending, else False.
返回值:如果请求正在等待处理,则返回 True,否则返回 False。
Return type: bool
"""
...
def load(self, state: dict) -> void:
"""
Load the actor/strategy state from the give state dictionary.
从给定的状态字典加载 actor/strategy 状态。
Calls on_load and passes the state.
调用 on_load 并传递状态。
Parameters: state (dict *[*str , object ]) – The state dictionary.
参数:state (dict *[*str , object ]) - 状态字典。
Raises: RuntimeError – If actor/strategy is not registered with a trader.
引发:RuntimeError - 如果 actor/strategy 未在交易者处注册。
Warning:
Exceptions raised will be caught, logged, and reraised.
引发的异常将被捕获、记录并重新引发。
"""
...
def on_bar(self, bar: Bar) -> void:
"""
Actions to be performed when running and receives a bar.
运行时执行的操作以及接收到的 bar。
Parameters: bar (Bar) – The bar received.
参数:bar (Bar) - 接收到的 bar。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_data(self, data: Data) -> void:
"""
Actions to be performed when running and receives data.
运行时执行的操作以及接收到的数据。
Parameters: data (Data) – The data received.
参数:data (Data) - 接收到的数据。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_degrade(self) -> void:
"""
Actions to be performed on degrade.
降级时执行的操作。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
Should be overridden in the actor implementation.
应该在 actor 实现中重写。
"""
...
def on_dispose(self) -> void:
"""
Actions to be performed on dispose.
释放时执行的操作。
Cleanup/release any resources used here.
在此处清理/释放使用的任何资源。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_event(self, event: Event) -> void:
"""
Handle the given event.
处理给定的事件。
Parameters: event (Event) – The received event to handle.
参数:event (Event) - 要处理的接收到的事件。
"""
...
def on_fault(self) -> void:
"""
Actions to be performed on fault.
出现故障时执行的操作。
Cleanup any resources used by the actor here.
在此处清理 actor 使用的任何资源。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
Should be overridden in the actor implementation.
应该在 actor 实现中重写。
"""
...
def on_historical_data(self, data) -> void:
"""
Actions to be performed when running and receives historical data.
运行时执行的操作以及接收到的历史数据。
Parameters: data (Data) – The historical data received.
参数:data (Data) - 接收到的历史数据。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_instrument(self, instrument: Instrument) -> void:
"""
Actions to be performed when running and receives an instrument.
运行时执行的操作以及接收到的金融工具。
Parameters: instrument (Instrument) – The instrument received.
参数:instrument (Instrument) - 接收到的金融工具。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_instrument_close(self, update: InstrumentClose) -> void:
"""
Actions to be performed when running and receives an instrument close update.
运行时执行的操作以及接收到的金融工具关闭更新。
Parameters: update (InstrumentClose) – The instrument close received.
参数:update (InstrumentClose) - 接收到的金融工具关闭。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_instrument_status(self, data: InstrumentStatus) -> void:
"""
Actions to be performed when running and receives an instrument status update.
运行时执行的操作以及接收到的金融工具状态更新。
Parameters: data (InstrumentStatus) – The instrument status update received.
参数:data (InstrumentStatus) - 接收到的金融工具状态更新。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_load(self, state: dict) -> void:
"""
Actions to be performed when the actor state is loaded.
加载 actor 状态时执行的操作。
Saved state values will be contained in the give state dictionary.
保存的状态值将包含在给定的状态字典中。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_order_book(self, order_book: OrderBook) -> void:
"""
Actions to be performed when running and receives an order book.
运行时执行的操作以及接收到的订单簿。
Parameters: order_book (OrderBook) – The order book received.
参数:order_book (OrderBook) - 接收到的订单簿。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_order_book_deltas(self, deltas) -> void:
"""
"""
...
def on_quote_tick(self, tick: QuoteTick) -> void:
"""
"""
...
def on_reset(self) -> void:
"""
"""
...
def on_resume(self) -> void:
"""
Actions to be performed on resume.
恢复时执行的操作。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_save(self) -> dict:
"""
Actions to be performed when the actor state is saved.
保存 actor 状态时执行的操作。
Create and return a state dictionary of values to be saved.
创建并返回要保存的值的状态字典。
Returns: The strategy state dictionary.
返回值:策略状态字典。
Return type: dict[str, bytes]
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_start(self) -> void:
"""
"""
...
def on_stop(self) -> void:
"""
"""
...
def on_trade_tick(self, tick: TradeTick) -> void:
"""
"""
...
def pending_requests(self) -> set:
"""
Return the request IDs which are currently pending processing.
返回当前正在等待处理的请求 ID。
Return type: set[UUID4]
"""
...
def publish_data(self, data_type: DataType, data: Data) -> void:
"""
Publish the given data to the message bus.
将给定的数据发布到消息总线。
Parameters:
参数:
data_type (DataType) – The data type being published.
data_type (DataType) - 正在发布的数据类型。
data (Data) – The data to publish.
data (Data) - 要发布的数据。
"""
...
def publish_signal(self, name: str, value, ts_event: int=0) -> void:
"""
Publish the given value as a signal to the message bus.
将给定的值作为信号发布到消息总线。
Parameters:
参数:
name (str) – The name of the signal being published. The signal name is case-insensitive and will be capitalized (e.g., ‘example’ becomes ‘SignalExample’).
name (str) - 正在发布的信号的名称。信号名称不区分大小写,并且将大写(例如,“example”变为“SignalExample”)。
value (object) – The signal data to publish.
value (object) - 要发布的信号数据。
ts_event (uint64_t , optional) – UNIX timestamp (nanoseconds) when the signal event occurred. If None then will timestamp current time.
ts_event (uint64_t,可选) - 信号事件发生时的 UNIX 时间戳(纳秒)。如果为 None,则将使用当前时间作为时间戳。
"""
...
def queue_for_executor(self, func: Callable, args: tuple=None, kwargs: dict=None):
"""
Queues the callable func to be executed as fn(*args, **kwargs) sequentially.
将可调用函数 func 排队,以便按顺序执行为 fn(*args, **kwargs)。
Parameters:
参数:
func (Callable) – The function to be executed.
func (Callable) - 要执行的函数。
args (positional arguments) – The positional arguments for the call to func.
args(位置参数) - 对 func 的调用的位置参数。
kwargs (arbitrary keyword arguments) – The keyword arguments for the call to func.
kwargs(任意关键字参数) - 对 func 的调用的关键字参数。
Raises: TypeError – If func is not of type Callable.
引发:TypeError - 如果 func 的类型不是 Callable。
"""
...
def queued_task_ids(self) -> list:
"""
Return the queued task identifiers.
返回排队的 task 标识符。
Return type: list[TaskId]
"""
...
def register_base(self, portfolio: PortfolioFacade, msgbus: MessageBus, cache: CacheFacade, clock: Clock) -> void:
"""
Register with a trader.
向交易者注册。
Parameters:
参数:
portfolio (PortfolioFacade) – The read-only portfolio for the actor.
portfolio (PortfolioFacade) - actor 的只读投资组合。
msgbus (MessageBus) – The message bus for the actor.
msgbus (MessageBus) - actor 的消息总线。
cache (CacheFacade) – The read-only cache for the actor.
cache (CacheFacade) - actor 的只读缓存。
clock (Clock) – The clock for the actor.
clock (Clock) - actor 的时钟。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def register_executor(self, loop, executor: Executor) -> void:
"""
Register the given Executor for the actor.
为 actor 注册给定的 Executor。
Parameters:
参数:
loop (asyncio.AsbtractEventLoop) – The event loop of the application.
loop (asyncio.AsbtractEventLoop) - 应用程序的事件循环。
executor (concurrent.futures.Executor) – The executor to register.
executor (concurrent.futures.Executor) - 要注册的执行器。
Raises: TypeError – If executor is not of type concurrent.futures.Executor
引发:TypeError - 如果 executor 的类型不是 concurrent.futures.Executor。
"""
...
def register_indicator_for_bars(self, bar_type: BarType, indicator: Indicator) -> void:
"""
Register the given indicator with the actor/strategy to receive bar data for the given bar type.
向 actor/strategy 注册给定的指标,以便接收给定 bar 类型的 bar 数据。
Parameters:
参数:
bar_type (BarType) – The bar type for bar updates.
bar_type (BarType) - bar 更新的 bar 类型。
indicator (Indicator) – The indicator to register.
indicator (Indicator) - 要注册的指标。
"""
...
def register_indicator_for_quote_ticks(self, instrument_id: InstrumentId, indicator: Indicator) -> void:
"""
Register the given indicator with the actor/strategy to receive quote tick data for the given instrument ID.
向 actor/strategy 注册给定的指标,以便接收给定金融工具 ID 的报价 tick 数据。
Parameters:
参数:
instrument_id (InstrumentId) – The instrument ID for tick updates.
instrument_id (InstrumentId) - tick 更新的金融工具 ID。
indicator (Indicator) – The indicator to register.
indicator (Indicator) - 要注册的指标。
"""
...
def register_indicator_for_trade_ticks(self, instrument_id: InstrumentId, indicator) -> void:
"""
Register the given indicator with the actor/strategy to receive trade tick data for the given instrument ID.
向 actor/strategy 注册给定的指标,以便接收给定金融工具 ID 的交易 tick 数据。
Parameters:
参数:
instrument_id (InstrumentId) – The instrument ID for tick updates.
instrument_id (InstrumentId) - tick 更新的金融工具 ID。
indicator (indicator) – The indicator to register.
indicator (indicator) - 要注册的指标。
"""
...
def register_warning_event(self, event) -> void:
"""
Register the given event type for warning log levels.
为警告日志级别注册给定的事件类型。
Parameters: event (type) – The event class to register.
参数:event (type) - 要注册的事件类。
"""
...
def request_bars(self, bar_type: BarType, start: datetime=None, end: datetime=None, client_id: ClientId=None, callback=None) -> UUID4:
"""
Request historical Bar data.
请求历史 Bar 数据。
If end is None then will request up to the most recent data.
如果 end 为 None,则将请求最多到最新数据。
Parameters:
参数:
bar_type (BarType) – The bar type for the request.
bar_type (BarType) - 请求的 bar 类型。
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)。包含性取决于各个数据客户端的实现。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
callback (Callable [ [UUID4 ] , None ] , optional) – The registered callback, to be called with the request ID when the response has completed processing.
callback (Callable [ [UUID4 ] , None ],可选) - 注册的回调函数,当响应完成处理时,将使用请求 ID 调用该回调函数。
Returns: The request_id for the request.
返回值:请求的 request_id。
Return type: UUID4
Raises:
引发:
ValueError – If start and end are not None and start is >= end.
ValueError - 如果 start 和 end 不为 None 并且 start >= end。
TypeError – If callback is not None and not of type Callable.
TypeError - 如果 callback 不为 None 并且类型不是 Callable。
"""
...
def request_data(self, data_type: DataType, client_id: ClientId, callback=None) -> UUID4:
"""
Request custom data for the given data type from the given data client.
从给定的数据客户端请求给定数据类型的自定义数据。
Parameters:
参数:
data_type (DataType) – The data type for the request.
data_type (DataType) - 请求的数据类型。
client_id (ClientId) – The data client ID.
client_id (ClientId) - 数据客户端 ID。
callback (Callable [ [UUID4 ] , None ] , optional) – The registered callback, to be called with the request ID when the response has completed processing.
callback (Callable [ [UUID4 ] , None ],可选) - 注册的回调函数,当响应完成处理时,将使用请求 ID 调用该回调函数。
Returns: The request_id for the request.
返回值:请求的 request_id。
Return type: UUID4
Raises: TypeError – If callback is not None and not of type Callable.
引发:TypeError - 如果 callback 不为 None 并且类型不是 Callable。
"""
...
def request_instrument(self, instrument_id: InstrumentId, start: datetime=None, end: datetime=None, client_id: ClientId=None, callback=None) -> UUID4:
"""
Request Instrument data for the given instrument ID.
请求给定金融工具 ID 的金融工具数据。
If end is None then will request up to the most recent data.
如果 end 为 None,则将请求最多到最新数据。
Parameters:
参数:
instrument_id (InstrumentId) – The instrument ID for the request.
instrument_id (InstrumentId) - 请求的金融工具 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)。包含性取决于各个数据客户端的实现。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
callback (Callable [ [UUID4 ] , None ] , optional) – The registered callback, to be called with the request ID when the response has completed processing.
callback (Callable [ [UUID4 ] , None ],可选) - 注册的回调函数,当响应完成处理时,将使用请求 ID 调用该回调函数。
Returns: The request_id for the request.
返回值:请求的 request_id。
Return type: UUID4
Raises:
引发:
ValueError – If start and end are not None and start is >= end.
ValueError - 如果 start 和 end 不为 None 并且 start >= end。
TypeError – If callback is not None and not of type Callable.
TypeError - 如果 callback 不为 None 并且类型不是 Callable。
"""
...
def request_instruments(self, venue: Venue, start: datetime=None, end: datetime=None, client_id: ClientId=None, callback=None) -> UUID4:
"""
Request all Instrument data for the given venue.
请求给定场所的所有金融工具数据。
If end is None then will request up to the most recent data.
如果 end 为 None,则将请求最多到最新数据。
Parameters:
参数:
venue (Venue) – The venue for the request.
venue (Venue) - 请求的场所。
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)。包含性取决于各个数据客户端的实现。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
callback (Callable [ [UUID4 ] , None ] , optional) – The registered callback, to be called with the request ID when the response has completed processing.
```python
callback (Callable [ [UUID4 ] , None ],可选) - 注册的回调函数,当响应完成处理时,将使用请求 ID 调用该回调函数。
Returns: The request_id for the request.
返回值:请求的 request_id。
Return type: UUID4
Raises:
引发:
ValueError – If start and end are not None and start is >= end.
ValueError - 如果 start 和 end 不为 None 并且 start >= end。
TypeError – If callback is not None and not of type Callable.
TypeError - 如果 callback 不为 None 并且类型不是 Callable。
"""
...
def request_order_book_snapshot(self, instrument_id: InstrumentId, limit: int, client_id: ClientId=None, callback=None) -> UUID4:
"""
Request an order book snapshot.
请求订单簿快照。
Parameters:
参数:
instrument_id (InstrumentId) – The instrument ID for the order book snapshot request.
instrument_id (InstrumentId) - 订单簿快照请求的金融工具 ID。
limit (int , optional) – The limit on the depth of the order book snapshot (default is None).
limit (int,可选) - 订单簿快照深度的限制(默认为 None)。
client_id (ClientId , optional) – The specific client ID for the command. If None, it will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
callback (Callable [ [UUID4 ] , None ] , optional) – The registered callback, to be called with the request ID when the response has completed processing.
callback (Callable [ [UUID4 ] , None ],可选) - 注册的回调函数,当响应完成处理时,将使用请求 ID 调用该回调函数。
Returns: The request_id for the request.
返回值:请求的 request_id。
Return type: UUID4
Raises:
引发:
ValueError – If the instrument_id is None.
ValueError - 如果 instrument_id 为 None。
TypeError – If callback is not None and not of type Callable.
TypeError - 如果 callback 不为 None 并且类型不是 Callable。
"""
...
def request_quote_ticks(self, instrument_id: InstrumentId, start: datetime=None, end: datetime=None, client_id: ClientId=None, callback=None) -> UUID4:
"""
Request historical QuoteTick data.
请求历史报价 Tick 数据。
If end is None then will request up to the most recent data.
如果 end 为 None,则将请求最多到最新数据。
Parameters:
参数:
instrument_id (InstrumentId) – The tick instrument ID for the request.
instrument_id (InstrumentId) - 请求的 tick 金融工具 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)。包含性取决于各个数据客户端的实现。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
callback (Callable [ [UUID4 ] , None ] , optional) – The registered callback, to be called with the request ID when the response has completed processing.
callback (Callable [ [UUID4 ] , None ],可选) - 注册的回调函数,当响应完成处理时,将使用请求 ID 调用该回调函数。
Returns: The request_id for the request.
返回值:请求的 request_id。
Return type: UUID4
Raises:
引发:
ValueError – If start and end are not None and start is >= end.
ValueError - 如果 start 和 end 不为 None 并且 start >= end。
TypeError – If callback is not None and not of type Callable.
TypeError - 如果 callback 不为 None 并且类型不是 Callable。
"""
...
def request_trade_ticks(self, instrument_id: InstrumentId, start: datetime=None, end: datetime=None, client_id: ClientId=None, callback=None) -> UUID4:
"""
Request historical TradeTick data.
请求历史交易 Tick 数据。
If end is None then will request up to the most recent data.
如果 end 为 None,则将请求最多到最新数据。
Parameters:
参数:
instrument_id (InstrumentId) – The tick instrument ID for the request.
instrument_id (InstrumentId) - 请求的 tick 金融工具 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)。包含性取决于各个数据客户端的实现。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
callback (Callable [ [UUID4 ] , None ] , optional) – The registered callback, to be called with the request ID when the response has completed processing.
callback (Callable [ [UUID4 ] , None ],可选) - 注册的回调函数,当响应完成处理时,将使用请求 ID 调用该回调函数。
Returns: The request_id for the request.
返回值:请求的 request_id。
Return type: UUID4
Raises:
引发:
ValueError – If start and end are not None and start is >= end.
ValueError - 如果 start 和 end 不为 None 并且 start >= end。
TypeError – If callback is not None and not of type Callable.
TypeError - 如果 callback 不为 None 并且类型不是 Callable。
"""
...
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 run_in_executor(self, func: Callable, args: tuple=None, kwargs: dict=None):
"""
Schedules the callable func to be executed as fn(*args, **kwargs).
计划可调用函数 func 以 fn(*args, **kwargs) 的形式执行。
Parameters:
参数:
func (Callable) – The function to be executed.
func (Callable) - 要执行的函数。
args (positional arguments) – The positional arguments for the call to func.
args(位置参数) - 对 func 的调用的位置参数。
kwargs (arbitrary keyword arguments) – The keyword arguments for the call to func.
kwargs(任意关键字参数) - 对 func 的调用的关键字参数。
Returns: The unique task identifier for the execution. This also corresponds to any future objects memory address.
返回值:执行的唯一 task 标识符。这也对应于任何 future 对象的内存地址。
Return type: TaskId
Raises: TypeError – If func is not of type Callable.
引发:TypeError - 如果 func 的类型不是 Callable。
"""
...
def save(self) -> dict:
"""
Return the actor/strategy state dictionary to be saved.
返回要保存的 actor/strategy 状态字典。
Calls on_save.
调用 on_save。
Raises: RuntimeError – If actor/strategy is not registered with a trader.
引发:RuntimeError - 如果 actor/strategy 未在交易者处注册。
Warning:
Exceptions raised will be caught, logged, and reraised.
引发的异常将被捕获、记录并重新引发。
"""
...
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_bars(self, bar_type: BarType, client_id: ClientId=None, await_partial: bool=False) -> void:
"""
Subscribe to streaming Bar data for the given bar type.
订阅给定 bar 类型的流式 Bar 数据。
Parameters:
参数:
bar_type (BarType) – The bar type to subscribe to.
bar_type (BarType) - 要订阅的 bar 类型。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
await_partial (bool , default False) – If the bar aggregator should await the arrival of a historical partial bar prior to actively aggregating new bars.
await_partial (bool,默认 False) - bar 聚合器是否应在主动聚合新 bar 之前等待历史部分 bar 的到来。
"""
...
def subscribe_data(self, data_type: DataType, client_id: ClientId=None) -> void:
"""
Subscribe to data of the given data type.
订阅给定数据类型的数据。
Parameters:
参数:
data_type (DataType) – The data type to subscribe to.
data_type (DataType) - 要订阅的数据类型。
client_id (ClientId , optional) – The data client ID. If supplied then a Subscribe command will be sent to the corresponding data client.
client_id (ClientId,可选) - 数据客户端 ID。如果提供,则将向相应的数据客户端发送 Subscribe 命令。
"""
...
def subscribe_instrument(self, instrument_id: InstrumentId, client_id: ClientId=None) -> void:
"""
Subscribe to update Instrument data for the given instrument ID.
订阅给定金融工具 ID 的更新金融工具数据。
Parameters:
参数:
instrument_id (InstrumentId) – The instrument ID for the subscription.
instrument_id (InstrumentId) - 订阅的金融工具 ID。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
"""
...
def subscribe_instrument_close(self, instrument_id: InstrumentId, client_id: ClientId=None) -> void:
"""
Subscribe to close updates for the given instrument ID.
订阅给定金融工具 ID 的收盘价更新。
Parameters:
参数:
instrument_id (InstrumentId) – The instrument to subscribe to status updates for.
instrument_id (InstrumentId) - 要订阅状态更新的金融工具。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
"""
...
def subscribe_instrument_status(self, instrument_id: InstrumentId, client_id: ClientId=None) -> void:
"""
Subscribe to status updates for the given instrument ID.
订阅给定金融工具 ID 的状态更新。
Parameters:
参数:
instrument_id (InstrumentId) – The instrument to subscribe to status updates for.
instrument_id (InstrumentId) - 要订阅状态更新的金融工具。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
"""
...
def subscribe_instruments(self, venue: Venue, client_id: ClientId=None) -> void:
"""
Subscribe to update Instrument data for the given venue.
订阅给定场所的更新金融工具数据。
Parameters:
参数:
venue (Venue) – The venue for the subscription.
venue (Venue) - 订阅的场所。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从场所推断出来。
"""
...
def subscribe_order_book_at_interval(self, instrument_id: InstrumentId, book_type=BookType.L2_MBP, depth: int=0, interval_ms: int=1000, kwargs: dict=None, client_id: ClientId=None, managed: bool=True) -> void:
"""
Subscribe to an OrderBook at a specified interval for the given instrument ID.
以指定的间隔订阅给定金融工具 ID 的订单簿。
The DataEngine will only maintain one order book for each instrument. Because of this - the level, depth and kwargs for the stream will be set as per the last subscription request (this will also affect all subscribers).
数据引擎将只为每个金融工具维护一个订单簿。因此,流的级别、深度和 kwargs 将根据最后一个订阅请求进行设置(这也会影响所有订阅者)。
Parameters:
参数:
instrument_id (InstrumentId) – The order book instrument ID to subscribe to.
instrument_id (InstrumentId) - 要订阅的订单簿金融工具 ID。
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) – The maximum depth for the order book. A depth of 0 is maximum depth.
depth (int,可选) - 订单簿的最大深度。深度为 0 表示最大深度。
interval_ms (int) – The order book snapshot interval in milliseconds (must be positive).
interval_ms (int) - 订单簿快照间隔(以毫秒为单位)(必须为正数)。
kwargs (dict , optional) – The keyword arguments for exchange specific parameters.
kwargs (dict,可选) - 交换特定参数的关键字参数。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
managed (bool , default True) – If an order book should be managed by the data engine based on the subscribed feed.
managed (bool,默认 True) - 是否应根据订阅的源由数据引擎管理订单簿。
Raises:
引发:
ValueError – If depth is negative (< 0).
ValueError - 如果 depth 为负数(< 0)。
ValueError – If interval_ms is not positive (> 0).
ValueError - 如果 interval_ms 不是正数(> 0)。
Warning:
Consider subscribing to order book deltas if you need intervals less than 100 milliseconds.
如果需要小于 100 毫秒的间隔,请考虑订阅订单簿增量。
"""
...
def subscribe_order_book_deltas(self, instrument_id: InstrumentId, book_type=BookType.L2_MBP, depth: int=0, kwargs: dict=None, client_id: ClientId=None, managed: bool=True, pyo3_conversion: bool=False) -> void:
"""
Subscribe to the order book data stream, being a snapshot then deltas for the given instrument ID.
订阅订单簿数据流,即给定金融工具 ID 的快照,然后是增量。
Parameters:
参数:
instrument_id (InstrumentId) – The order book instrument ID to subscribe to.
instrument_id (InstrumentId) - 要订阅的订单簿金融工具 ID。
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) – 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,可选) - 交换特定参数的关键字参数。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
managed (bool , default True) – If an order book should be managed by the data engine based on the subscribed feed.
managed (bool,默认 True) - 是否应根据订阅的源由数据引擎管理订单簿。
pyo3_conversion (bool , default False) – If received deltas should be converted to nautilus_pyo3.OrderBookDeltas prior to being passed to the on_order_book_deltas handler.
pyo3_conversion (bool,默认 False) - 在传递给 on_order_book_deltas 处理程序之前,是否应将接收到的增量转换为 nautilus_pyo3.OrderBookDeltas。
"""
...
def subscribe_quote_ticks(self, instrument_id: InstrumentId, client_id: ClientId=None) -> void:
"""
Subscribe to streaming QuoteTick data for the given instrument ID.
订阅给定金融工具 ID 的流式报价 Tick 数据。
Parameters:
参数:
instrument_id (InstrumentId) – The tick instrument to subscribe to.
instrument_id (InstrumentId) - 要订阅的 tick 金融工具。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
"""
...
def subscribe_signal(self, name: str='') -> void:
"""
Subscribe to a specific signal by name, or to all signals if no name is provided.
按名称订阅特定信号,或者如果没有提供名称,则订阅所有信号。
Parameters: name (str , optional) – The name of the signal to subscribe to. If not provided or an empty string is passed, the subscription will include all signals. The signal name is case-insensitive and will be capitalized (e.g., ‘example’ becomes ‘SignalExample*’).
参数:name (str,可选) - 要订阅的信号的名称。如果没有提供或传递空字符串,则订阅将包含所有信号。信号名称不区分大小写,并且将大写(例如,“example”变为“SignalExample*”)。
"""
...
def subscribe_trade_ticks(self, instrument_id: InstrumentId, client_id: ClientId=None) -> void:
"""
Subscribe to streaming TradeTick data for the given instrument ID.
订阅给定金融工具 ID 的流式交易 Tick 数据。
Parameters:
参数:
instrument_id (InstrumentId) – The tick instrument to subscribe to.
instrument_id (InstrumentId) - 要订阅的 tick 金融工具。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
"""
...
def to_importable_config(self) -> ImportableActorConfig:
"""
Returns an importable configuration for this actor.
返回此 actor 的可导入配置。
Return type: ImportableActorConfig
"""
...
def unsubscribe_bars(self, bar_type: BarType, client_id: ClientId=None) -> void:
"""
Unsubscribe from streaming Bar data for the given bar type.
取消订阅给定 bar 类型的流式 Bar 数据。
Parameters:
参数:
bar_type (BarType) – The bar type to unsubscribe from.
bar_type (BarType) - 要取消订阅的 bar 类型。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
"""
...
def unsubscribe_data(self, data_type: DataType, client_id: ClientId=None) -> void:
"""
Unsubscribe from data of the given data type.
取消订阅给定数据类型的数据。
Parameters:
参数:
data_type (DataType) – The data type to unsubscribe from.
data_type (DataType) - 要取消订阅的数据类型。
client_id (ClientId , optional) – The data client ID. If supplied then an Unsubscribe command will be sent to the data client.
client_id (ClientId,可选) - 数据客户端 ID。如果提供,则将向数据客户端发送 Unsubscribe 命令。
"""
...
def unsubscribe_instrument(self, instrument_id: InstrumentId, client_id: ClientId=None) -> void:
"""
Unsubscribe from update Instrument data for the given instrument ID.
取消订阅给定金融工具 ID 的更新金融工具数据。
Parameters:
参数:
instrument_id (InstrumentId) – The instrument to unsubscribe from.
instrument_id (InstrumentId) - 要取消订阅的金融工具。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
"""
...
def unsubscribe_instrument_status(self, instrument_id: InstrumentId, client_id: ClientId=None) -> void:
"""
Unsubscribe to status updates of the given venue.
取消订阅给定场所的状态更新。
Parameters:
参数:
instrument_id (InstrumentId) – The instrument to unsubscribe to status updates for.
instrument_id (InstrumentId) - 要取消订阅状态更新的金融工具。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从场所推断出来。
"""
...
def unsubscribe_instruments(self, venue: Venue, client_id: ClientId=None) -> void:
"""
Unsubscribe from update Instrument data for the given venue.
取消订阅给定场所的更新金融工具数据。
Parameters:
参数:
venue (Venue) – The venue for the subscription.
venue (Venue) - 订阅的场所。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从场所推断出来。
"""
...
def unsubscribe_order_book_at_interval(self, instrument_id: InstrumentId, interval_ms: int=1000, client_id: ClientId=None) -> void:
"""
Unsubscribe from an OrderBook at a specified interval for the given instrument ID.
以指定的间隔取消订阅给定金融工具 ID 的订单簿。
The interval must match the previously subscribed interval.
间隔必须与之前订阅的间隔匹配。
Parameters:
参数:
instrument_id (InstrumentId) – The order book instrument to subscribe to.
instrument_id (InstrumentId) - 要订阅的订单簿金融工具。
interval_ms (int) – The order book snapshot interval in milliseconds.
interval_ms (int) - 订单簿快照间隔(以毫秒为单位)。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
"""
...
def unsubscribe_order_book_deltas(self, instrument_id: InstrumentId, client_id: ClientId=None) -> void:
"""
Unsubscribe the order book deltas stream for the given instrument ID.
取消订阅给定金融工具 ID 的订单簿增量流。
Parameters:
参数:
instrument_id (InstrumentId) – The order book instrument to subscribe to.
instrument_id (InstrumentId) - 要订阅的订单簿金融工具。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
"""
...
def unsubscribe_quote_ticks(self, instrument_id: InstrumentId, client_id: ClientId=None) -> void:
"""
Unsubscribe from streaming QuoteTick data for the given instrument ID.
取消订阅给定金融工具 ID 的流式报价 Tick 数据。
Parameters:
参数:
instrument_id (InstrumentId) – The tick instrument to unsubscribe from.
instrument_id (InstrumentId) - 要取消订阅的 tick 金融工具。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
"""
...
def unsubscribe_trade_ticks(self, instrument_id: InstrumentId, client_id: ClientId=None) -> void:
"""
Unsubscribe from streaming TradeTick data for the given instrument ID.
取消订阅给定金融工具 ID 的流式交易 Tick 数据。
Parameters:
参数:
instrument_id (InstrumentId) – The tick instrument ID to unsubscribe from.
instrument_id (InstrumentId) - 要取消订阅的 tick 金融工具 ID。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
"""
...
def update_synthetic(self, synthetic: SyntheticInstrument) -> void:
"""
Update the synthetic instrument in the cache.
更新缓存中的合成金融工具。
Parameters: synthetic (SyntheticInstrument) – The synthetic instrument to update in the cache.
参数:synthetic (SyntheticInstrument) - 要在缓存中更新的合成金融工具。
Raises: KeyError – If synthetic does not already exist in the cache.
引发:KeyError - 如果合成金融工具在缓存中不存在。
"""
...
class OrderManager 订单管理器
Bases: object
class OrderManager(object):
"""
Provides a generic order execution manager.
提供通用的订单执行管理器。
Parameters:
参数:
clock (Clock) – The clock for the order manager.
clock (Clock) - 订单管理器的时钟。
msgbus (MessageBus) – The message bus for the order manager.
msgbus (MessageBus) - 订单管理器的消息总线。
cache (Cache) – The cache for the order manager.
cache (Cache) - 订单管理器的缓存。
component_name (str) – The component name for the order manager.
component_name (str) - 订单管理器的组件名称。
active_local (str) – If the manager is for active local orders.
active_local (str) - 管理器是否用于活动本地订单。
submit_order_handler (Callable [ [SubmitOrder ] , None ] , optional) – The handler to call when submitting orders.
submit_order_handler (Callable [[SubmitOrder],None],可选) - 提交订单时要调用的处理程序。
cancel_order_handler (Callable [ [Order ] , None ] , optional) – The handler to call when canceling orders.
cancel_order_handler (Callable [[Order],None],可选) - 取消订单时要调用的处理程序。
modify_order_handler (Callable [ [Order , Quantity ] , None ] , optional) – The handler to call when modifying orders (limited to modifying quantity).
modify_order_handler (Callable [[Order,Quantity],None],可选) - 修改订单时要调用的处理程序(仅限于修改数量)。
debug (bool , default False) – If debug mode is active (will provide extra debug logging).
debug (bool,默认 False) - 是否激活调试模式(将提供额外的调试日志)。
Raises:
引发:
TypeError – If submit_order_handler is not None and not of type Callable.
TypeError - 如果 submit_order_handler 不为 None 并且类型不是 Callable。
TypeError – If cancel_order_handler is not None and not of type Callable.
TypeError - 如果 cancel_order_handler 不为 None 并且类型不是 Callable。
TypeError – If modify_order_handler is not None and not of type Callable.
TypeError - 如果 modify_order_handler 不为 None 并且类型不是 Callable。
"""
def __init__(self, clock: Clock, msgbus: MessageBus, cache: Cache, component_name: str, active_local: str, submit_order_handler: Callable[[SubmitOrder], None] = None, cancel_order_handler: Callable[[Order], None] = None, modify_order_handler: Callable[[Order, Quantity], None] = None, debug: bool = False):
...
Properties 属性
@property
def active_local(self):
"""
"""
...
@property
def debug(self):
"""
"""
...
Methods 方法
def cache_submit_order_command(self, command: SubmitOrder) -> void:
"""
Cache the given submit order command with the manager.
使用管理器缓存给定的提交订单命令。
Parameters: command (SubmitOrder) – The submit order command to cache.
参数:command (SubmitOrder) - 要缓存的提交订单命令。
"""
...
def cancel_order(self, order: Order) -> void:
"""
Cancel the given order with the manager.
使用管理器取消给定的订单。
Parameters: order (Order) – The order to cancel.
参数:order (Order) - 要取消的订单。
"""
...
def create_new_submit_order(self, order: Order, position_id: PositionId = None, client_id: ClientId = None) -> void:
"""
Create a new submit order command for the given order.
为给定的订单创建一个新的提交订单命令。
Parameters:
参数:
order (Order) – The order for the command.
order (Order) - 命令的订单。
position_id (PositionId , optional) – The position ID for the command.
position_id (PositionId,可选) - 命令的持仓 ID。
client_id (ClientId , optional) – The client ID for the command.
client_id (ClientId,可选) - 命令的客户端 ID。
"""
...
def get_submit_order_commands(self) -> dict:
"""
Return the managers cached submit order commands.
返回管理器缓存的提交订单命令。
Return type: dict[ClientOrderId, SubmitOrder]
"""
...
def handle_contingencies(self, order: Order) -> void:
"""
"""
...
def handle_contingencies_update(self, order: Order) -> void:
"""
"""
...
def handle_event(self, event: Event) -> void:
"""
```python
Handle the given event.
处理给定的事件。
If a handler for the given event is not implemented then this will simply be a no-op.
如果没有为给定事件实现处理程序,则这将只是一个空操作。
Parameters: event (Event) – The event to handle
参数:event (Event) - 要处理的事件。
"""
...
def handle_order_canceled(self, canceled: OrderCanceled) -> void:
"""
"""
...
def handle_order_expired(self, expired: OrderExpired) -> void:
"""
"""
...
def handle_order_filled(self, filled: OrderFilled) -> void:
"""
"""
...
def handle_order_rejected(self, rejected: OrderRejected) -> void:
"""
"""
...
def handle_order_updated(self, updated: OrderUpdated) -> void:
"""
"""
...
def handle_position_event(self, event: PositionEvent) -> void:
"""
"""
...
def modify_order_quantity(self, order: Order, new_quantity: Quantity) -> void:
"""
Modify the given order with the manager.
使用管理器修改给定的订单。
Parameters:
参数:
order (Order) – The order to modify.
order (Order) - 要修改的订单。
"""
...
def pop_submit_order_command(self, client_order_id: ClientOrderId):
"""
Pop the submit order command for the given client_order_id out of the managers cache (if found).
从管理器的缓存中弹出给定 client_order_id 的提交订单命令(如果找到)。
Parameters: client_order_id (ClientOrderId) – The client order ID for the command to pop.
参数:client_order_id (ClientOrderId) - 要弹出的命令的客户端订单 ID。
Return type: SubmitOrder or None
"""
...
def reset(self) -> void:
"""
Reset the manager, clearing all stateful values.
重置管理器,清除所有有状态值。
"""
...
def send_algo_command(self, command: TradingCommand, exec_algorithm_id: ExecAlgorithmId) -> void:
"""
"""
...
def send_emulator_command(self, command: TradingCommand) -> void:
"""
"""
...
def send_exec_command(self, command: TradingCommand) -> void:
"""
"""
...
def send_exec_event(self, event: OrderEvent) -> void:
"""
"""
...
def send_risk_command(self, command: TradingCommand) -> void:
"""
"""
...
def send_risk_event(self, event: OrderEvent) -> void:
"""
"""
...
def should_manage_order(self, order: Order) -> bool:
"""
Check if the given order should be managed.
检查是否应管理给定的订单。
Parameters: order (Order) – The order to check.
参数:order (Order) - 要检查的订单。
Returns: True if the order should be managed, else False.
返回值:如果应管理订单,则返回 True,否则返回 False。
Return type: bool
"""
...
class MatchingCore 匹配核心
Bases: object
class MatchingCore(object):
"""
Provides a generic order matching core.
提供通用的订单匹配核心。
Parameters:
参数:
instrument_id (InstrumentId) – The instrument ID for the matching core.
instrument_id (InstrumentId) - 匹配核心的金融工具 ID。
price_increment (Price) – The minimum price increment (tick size) for the matching core.
price_increment (Price) - 匹配核心的最小价格增量(刻度大小)。
trigger_stop_order (Callable [ [Order ] , None ]) – The callable when a stop order is triggered.
trigger_stop_order (Callable [[Order],None]) - 触发止损单时可调用的函数。
fill_market_order (Callable [ [Order ] , None ]) – The callable when a market order is filled.
fill_market_order (Callable [[Order],None]) - 成交市价单时可调用的函数。
fill_limit_order (Callable [ [Order ] , None ]) – The callable when a limit order is filled.
fill_limit_order (Callable [[Order],None]) - 成交限价单时可调用的函数。
"""
def __init__(self, instrument_id: InstrumentId, price_increment: Price, trigger_stop_order: Callable, fill_market_order: Callable, fill_limit_order: Callable):
...
Properties 属性
@property
def ask(self):
"""
Price | None
Return the current ask price for the matching core.
返回匹配核心的当前卖价。
Return type: Price or None
Type: MatchingCore.ask
"""
...
@property
def ask_raw(self):
"""
"""
...
@property
def bid(self):
"""
Price | None
Return the current bid price for the matching core.
返回匹配核心的当前买价。
Return type: Price or None
Type: MatchingCore.bid
"""
...
@property
def bid_raw(self):
"""
"""
...
@property
def instrument_id(self) -> InstrumentId:
"""
InstrumentId
Return the instrument ID for the matching core.
返回匹配核心的金融工具 ID。
Return type: InstrumentId
Type: MatchingCore.instrument_id
"""
...
@property
def is_ask_initialized(self):
"""
"""
...
@property
def is_bid_initialized(self):
"""
"""
...
@property
def is_last_initialized(self):
"""
"""
...
@property
def last(self):
"""
Price | None
Return the current last price for the matching core.
返回匹配核心的当前最新价。
Return type: Price or None
Type: MatchingCore.last
"""
...
@property
def last_raw(self):
"""
"""
...
@property
def price_increment(self) -> Price:
"""
Price
Return the instruments minimum price increment (tick size) for the matching core.
返回匹配核心的金融工具的最小价格增量(刻度大小)。
Return type: Price
Type: MatchingCore.price_increment
"""
...
@property
def price_precision(self) -> int:
"""
int
Return the instruments price precision for the matching core.
返回匹配核心的金融工具的价格精度。
Return type: int
Type: MatchingCore.price_precision
"""
...
Methods 方法
def add_order(self, order: Order) -> void:
"""
"""
...
def delete_order(self, order: Order) -> void:
"""
"""
...
def get_order(self, client_order_id: ClientOrderId):
"""
"""
...
def get_orders(self) -> list:
"""
"""
...
def get_orders_ask(self) -> list:
"""
"""
...
def get_orders_bid(self) -> list:
"""
"""
...
def is_limit_matched(self, side: OrderSide, price: Price) -> bool:
"""
"""
...
def is_stop_triggered(self, side: OrderSide, trigger_price: Price) -> bool:
"""
"""
...
def is_touch_triggered(self, side: OrderSide, trigger_price: Price) -> bool:
"""
"""
...
def iterate(self, timestamp_ns: int) -> void:
"""
"""
...
def match_limit_if_touched_order(self, order: Order, initial: bool) -> void:
"""
"""
...
def match_limit_order(self, order: Order) -> void:
"""
"""
...
def match_market_if_touched_order(self, order: Order) -> void:
"""
"""
...
def match_order(self, order: Order, initial: bool = False) -> void:
"""
Match the given order.
匹配给定的订单。
Parameters:
参数:
order (Order) – The order to match.
order (Order) - 要匹配的订单。
initial (bool , default False) – If this is an initial match.
initial (bool,默认 False) - 这是否是初始匹配。
Raises: TypeError – If the order.order_type is an invalid type for the core (e.g. MARKET).
引发:TypeError - 如果 order.order_type 对于核心来说是无效类型(例如 MARKET)。
"""
...
def match_stop_limit_order(self, order: Order, initial: bool) -> void:
"""
"""
...
def match_stop_market_order(self, order: Order) -> void:
"""
"""
...
def order_exists(self, client_order_id: ClientOrderId) -> bool:
"""
"""
...
def reset(self) -> void:
"""
"""
...
Messages 消息
class BatchCancelOrders 批量取消订单
Bases: TradingCommand
class BatchCancelOrders(TradingCommand):
"""
Represents a command to batch cancel orders working on a venue for an instrument.
表示批量取消对金融工具在场所工作的订单的命令。
Parameters:
参数:
trader_id (TraderId) – The trader ID for the command.
trader_id (TraderId) - 命令的交易者 ID。
strategy_id (StrategyId) – The strategy ID for the command.
strategy_id (StrategyId) - 命令的策略 ID。
instrument_id (InstrumentId) – The instrument ID for the command.
instrument_id (InstrumentId) - 命令的金融工具 ID。
cancels (list [CancelOrder ]) – The inner list of cancel order commands.
cancels (list [CancelOrder ]) - 取消订单命令的内部列表。
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 时间戳(纳秒)。
client_id (ClientId , optional) – The execution client ID for the command.
client_id (ClientId,可选) - 命令的执行客户端 ID。
Raises:
引发:
ValueError – If cancels is empty.
ValueError - 如果 cancels 为空。
ValueError – If cancels contains a type other than CancelOrder.
ValueError - 如果 cancels 包含 CancelOrder 以外的类型。
"""
def __init__(self, trader_id: TraderId, strategy_id: StrategyId, instrument_id: InstrumentId, cancels: list, command_id: UUID4, ts_init: int, client_id: ClientId = None):
...
Properties 属性
@property
def cancels(self):
"""
"""
...
@property
def client_id(self):
"""
The execution client ID for the command.
命令的执行客户端 ID。
Returns:
ClientId or None
"""
...
@property
def id(self) -> UUID4:
"""
The command message ID.
命令消息 ID。
Returns:
UUID4
"""
...
@property
def instrument_id(self) -> InstrumentId:
"""
The instrument ID associated with the command.
与命令关联的金融工具 ID。
Returns:
InstrumentId
"""
...
@property
def strategy_id(self) -> StrategyId:
"""
The strategy ID associated with the command.
与命令关联的策略 ID。
Returns:
StrategyId
"""
...
@property
def trader_id(self) -> TraderId:
"""
The trader ID associated with the command.
与命令关联的交易者 ID。
Returns:
TraderId
"""
...
@property
def ts_init(self) -> int:
"""
UNIX timestamp (nanoseconds) when the object was initialized.
对象初始化时的 UNIX 时间戳(纳秒)。
Returns:
uint64_t
"""
...
Methods 方法
@staticmethod
def from_dict(values: dict):
"""
Return a batch cancel order command from the given dict values.
从给定的 dict 值返回批量取消订单命令。
Parameters: values (dict *[*str , object ]) – The values for initialization.
参数:values (dict *[*str,object]) - 初始化的值。
Return type: BatchCancelOrders
"""
...
@staticmethod
def to_dict(obj: 'BatchCancelOrders'):
"""
Return a dictionary representation of this object.
返回此对象的字典表示形式。
Return type: dict[str, object]
"""
...
class CancelAllOrders 取消所有订单
Bases: TradingCommand
class CancelAllOrders(TradingCommand):
"""
Represents a command to cancel all orders for an instrument.
表示取消金融工具的所有订单的命令。
Parameters:
参数:
trader_id (TraderId) – The trader ID for the command.
trader_id (TraderId) - 命令的交易者 ID。
strategy_id (StrategyId) – The strategy ID for the command.
strategy_id (StrategyId) - 命令的策略 ID。
instrument_id (InstrumentId) – The instrument ID for the command.
instrument_id (InstrumentId) - 命令的金融工具 ID。
order_side (OrderSide) – The order side for the command.
order_side (OrderSide) - 命令的订单方向。
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 时间戳(纳秒)。
client_id (ClientId , optional) – The execution client ID for the command.
client_id (ClientId,可选) - 命令的执行客户端 ID。
"""
def __init__(self, trader_id: TraderId, strategy_id: StrategyId, instrument_id: InstrumentId, order_side: OrderSide, command_id: UUID4, ts_init: int, client_id: ClientId = None):
...
Properties 属性
@property
def client_id(self):
"""
The execution client ID for the command.
命令的执行客户端 ID。
Returns:
ClientId or None
"""
...
@property
def id(self) -> UUID4:
"""
The command message ID.
命令消息 ID。
Returns:
UUID4
"""
...
@property
def instrument_id(self) -> InstrumentId:
"""
The instrument ID associated with the command.
与命令关联的金融工具 ID。
Returns:
InstrumentId
"""
...
@property
def order_side(self) -> OrderSide:
"""
The order side for the command.
命令的订单方向。
Returns:
OrderSide
"""
...
@property
def strategy_id(self) -> StrategyId:
"""
The strategy ID associated with the command.
与命令关联的策略 ID。
Returns:
StrategyId
"""
...
@property
def trader_id(self) -> TraderId:
"""
The trader ID associated with the command.
与命令关联的交易者 ID。
Returns:
TraderId
"""
...
@property
def ts_init(self) -> int:
"""
UNIX timestamp (nanoseconds) when the object was initialized.
对象初始化时的 UNIX 时间戳(纳秒)。
Returns:
uint64_t
"""
...
Methods 方法
@staticmethod
def from_dict(values: dict):
"""
Return a cancel order command from the given dict values.
从给定的 dict 值返回取消订单命令。
Parameters: values (dict *[*str , object ]) – The values for initialization.
参数:values (dict *[*str,object]) - 初始化的值。
Return type: CancelAllOrders
"""
...
@staticmethod
def to_dict(obj: 'CancelAllOrders'):
"""
Return a dictionary representation of this object.
返回此对象的字典表示形式。
Return type: dict[str, object]
"""
...
class CancelOrder 取消订单
Bases: TradingCommand
class CancelOrder(TradingCommand):
"""
Represents a command to cancel an order.
表示取消订单的命令。
Parameters:
参数:
trader_id (TraderId) – The trader ID for the command.
trader_id (TraderId) - 命令的交易者 ID。
strategy_id (StrategyId) – The strategy ID for the command.
strategy_id (StrategyId) - 命令的策略 ID。
instrument_id (InstrumentId) – The instrument ID for the command.
instrument_id (InstrumentId) - 命令的金融工具 ID。
client_order_id (ClientOrderId) – The client order ID to cancel.
client_order_id (ClientOrderId) - 要取消的客户端订单 ID。
venue_order_id (VenueOrderId, optional with no default so None must be passed explicitly) – The venue order ID (assigned by the venue) to cancel.
venue_order_id (VenueOrderId,可选,没有默认值,因此必须显式传递 None) - 要取消的场所订单 ID(由场所分配)。
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 时间戳(纳秒)。
client_id (ClientId , optional) – The execution client ID for the command.
client_id (ClientId,可选) - 命令的执行客户端 ID。
"""
def __init__(self, trader_id: TraderId, strategy_id: StrategyId, instrument_id: InstrumentId, client_order_id: ClientOrderId, venue_order_id: VenueOrderId | None, command_id: UUID4, ts_init: int, client_id: ClientId = None):
...
Properties 属性
@property
def client_id(self):
"""
The execution client ID for the command.
命令的执行客户端 ID。
Returns:
ClientId or None
"""
...
@property
def client_order_id(self) -> ClientOrderId:
"""
The client order ID associated with the command.
与命令关联的客户端订单 ID。
Returns:
ClientOrderId
"""
...
@property
def id(self) -> UUID4:
"""
The command message ID.
命令消息 ID。
Returns:
UUID4
"""
...
@property
def instrument_id(self) -> InstrumentId:
"""
The instrument ID associated with the command.
与命令关联的金融工具 ID。
Returns:
InstrumentId
"""
...
@property
def strategy_id(self) -> StrategyId:
"""
The strategy ID associated with the command.
与命令关联的策略 ID。
Returns:
StrategyId
"""
...
@property
def trader_id(self) -> TraderId:
"""
The trader ID associated with the command.
与命令关联的交易者 ID。
Returns:
TraderId
"""
...
@property
def ts_init(self) -> int:
"""
UNIX timestamp (nanoseconds) when the object was initialized.
对象初始化时的 UNIX 时间戳(纳秒)。
Returns:
uint64_t
"""
...
@property
def venue_order_id(self):
"""
The venue order ID associated with the command.
与命令关联的场所订单 ID。
Returns:
VenueOrderId or None
"""
...
Methods 方法
@staticmethod
def from_dict(values: dict):
"""
Return a cancel order command from the given dict values.
从给定的 dict 值返回取消订单命令。
Parameters: values (dict *[*str , object ]) – The values for initialization.
参数:values (dict *[*str,object]) - 初始化的值。
Return type: CancelOrder
"""
...
@staticmethod
def to_dict(obj: 'CancelOrder'):
"""
Return a dictionary representation of this object.
返回此对象的字典表示形式。
Return type: dict[str, object]
"""
...
class ModifyOrder 修改订单
Bases: TradingCommand
class ModifyOrder(TradingCommand):
"""
Represents a command to modify the properties of an existing order.
表示修改现有订单的属性的命令。
Parameters:
参数:
trader_id (TraderId) – The trader ID for the command.
trader_id (TraderId) - 命令的交易者 ID。
strategy_id (StrategyId) – The strategy ID for the command.
strategy_id (StrategyId) - 命令的策略 ID。
instrument_id (InstrumentId) – The instrument ID for the command.
instrument_id (InstrumentId) - 命令的金融工具 ID。
client_order_id (ClientOrderId) – The client order ID to update.
client_order_id (ClientOrderId) - 要更新的客户端订单 ID。
venue_order_id (VenueOrderId, optional with no default so None must be passed explicitly) – The venue order ID (assigned by the venue) to update.
venue_order_id (VenueOrderId,可选,没有默认值,因此必须显式传递 None) - 要更新的场所订单 ID(由场所分配)。
quantity (Quantity, optional with no default so None must be passed explicitly) – The quantity for the order update.
quantity (Quantity,可选,没有默认值,因此必须显式传递 None) - 订单更新的数量。
price (Price, optional with no default so None must be passed explicitly) – The price for the order update.
price (Price,可选,没有默认值,因此必须显式传递 None) - 订单更新的价格。
trigger_price (Price, optional with no default so None must be passed explicitly) – The trigger price for the order update.
trigger_price (Price,可选,没有默认值,因此必须显式传递 None) - 订单更新的触发价格。
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 时间戳(纳秒)。
client_id (ClientId , optional) – The execution client ID for the command.
client_id (ClientId,可选) - 命令的执行客户端 ID。
"""
def __init__(self, trader_id: TraderId, strategy_id: StrategyId, instrument_id: InstrumentId, client_order_id: ClientOrderId, venue_order_id: VenueOrderId | None, quantity: Quantity | None, price: Price | None, trigger_price: Price | None, command_id: UUID4, ts_init: int, client_id: ClientId = None):
...
Properties 属性
@property
def client_id(self):
"""
The execution client ID for the command.
命令的执行客户端 ID。
Returns:
ClientId or None
"""
...
@property
def client_order_id(self) -> ClientOrderId:
"""
The client order ID associated with the command.
与命令关联的客户端订单 ID。
Returns:
ClientOrderId
"""
...
@property
def id(self) -> UUID4:
"""
The command message ID.
命令消息 ID。
Returns:
UUID4
"""
...
@property
def instrument_id(self) -> InstrumentId:
"""
The instrument ID associated with the command.
与命令关联的金融工具 ID。
Returns:
InstrumentId
"""
...
@property
def price(self):
"""
The updated price for the command.
命令的更新价格。
Returns:
Price or None
"""
...
@property
def quantity(self):
"""
The updated quantity for the command.
命令的更新数量。
Returns:
Quantity or None
"""
...
@property
def strategy_id(self) -> StrategyId:
"""
The strategy ID associated with the command.
与命令关联的策略 ID。
Returns:
StrategyId
"""
...
@property
def trader_id(self) -> TraderId:
"""
The trader ID associated with the command.
与命令关联的交易者 ID。
Returns:
TraderId
"""
...
@property
def trigger_price(self):
"""
The updated trigger price for the command.
命令的更新触发价格。
Returns:
Price or None
"""
...
@property
def ts_init(self) -> int:
"""
UNIX timestamp (nanoseconds) when the object was initialized.
对象初始化时的 UNIX 时间戳(纳秒)。
Returns:
uint64_t
"""
...
@property
def venue_order_id(self):
"""
The venue order ID associated with the command.
与命令关联的场所订单 ID。
Returns:
VenueOrderId or None
"""
...
Methods 方法
@staticmethod
def from_dict(values: dict):
"""
Return a modify order command from the given dict values.
从给定的 dict 值返回修改订单命令。
Parameters: values (dict *[*str , object ]) – The values for initialization.
参数:values (dict *[*str,object]) - 初始化的值。
Return type: ModifyOrder
"""
...
@staticmethod
def to_dict(obj: 'ModifyOrder'):
"""
Return a dictionary representation of this object.
返回此对象的字典表示形式。
Return type: dict[str, object]
"""
...
class QueryOrder 查询订单
Bases: TradingCommand
class QueryOrder(TradingCommand):
"""
Represents a command to query an order.
表示查询订单的命令。
Parameters:
参数:
trader_id (TraderId) – The trader ID for the command.
trader_id (TraderId) - 命令的交易者 ID。
strategy_id (StrategyId) – The strategy ID for the command.
strategy_id (StrategyId) - 命令的策略 ID。
instrument_id (InstrumentId) – The instrument ID for the command.
instrument_id (InstrumentId) - 命令的金融工具 ID。
client_order_id (ClientOrderId) – The client order ID for the order to query.
client_order_id (ClientOrderId) - 要查询的订单的客户端订单 ID。
venue_order_id (VenueOrderId, optional with no default so None must be passed explicitly) – The venue order ID (assigned by the venue) to query.
venue_order_id (VenueOrderId,可选,没有默认值,因此必须显式传递 None) - 要查询的场所订单 ID(由场所分配)。
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 时间戳(纳秒)。
client_id (ClientId , optional) – The execution client ID for the command.
client_id (ClientId,可选) - 命令的执行客户端 ID。
"""
def __init__(self, trader_id: TraderId, strategy_id: StrategyId, instrument_id: InstrumentId, client_order_id: ClientOrderId, venue_order_id: VenueOrderId | None, command_id: UUID4, ts_init: int, client_id: ClientId = None):
...
Properties 属性
@property
def client_id(self):
"""
The execution client ID for the command.
命令的执行客户端 ID。
Returns:
ClientId or None
"""
...
@property
def client_order_id(self) -> ClientOrderId:
"""
The client order ID for the order to query.
要查询的订单的客户端订单 ID。
Returns:
ClientOrderId
"""
...
@property
def id(self) -> UUID4:
"""
The command message ID.
命令消息 ID。
Returns:
UUID4
"""
...
@property
def instrument_id(self) -> InstrumentId:
"""
The instrument ID associated with the command.
与命令关联的金融工具 ID。
Returns:
InstrumentId
"""
...
@property
def strategy_id(self) -> StrategyId:
"""
The strategy ID associated with the command.
与命令关联的策略 ID。
Returns:
StrategyId
"""
...
@property
def trader_id(self) -> TraderId:
"""
The trader ID associated with the command.
与命令关联的交易者 ID。
Returns:
TraderId
"""
...
@property
def ts_init(self) -> int:
"""
UNIX timestamp (nanoseconds) when the object was initialized.
对象初始化时的 UNIX 时间戳(纳秒)。
Returns:
uint64_t
"""
...
@property
def venue_order_id(self):
"""
The venue order ID for the order to query.
要查询的订单的场所订单 ID。
Returns:
VenueOrderId or None
"""
...
Methods 方法
@staticmethod
def from_dict(values: dict):
"""
Return a query order command from the given dict values.
从给定的 dict 值返回查询订单命令。
Parameters: values (dict *[*str , object ]) – The values for initialization.
参数:values (dict *[*str,object]) - 初始化的值。
Return type: QueryOrder
"""
...
@staticmethod
def to_dict(obj: 'QueryOrder'):
"""
Return a dictionary representation of this object.
返回此对象的字典表示形式。
Return type: dict[str, object]
"""
...
class SubmitOrder 提交订单
Bases: TradingCommand
class SubmitOrder(TradingCommand):
"""
Represents a command to submit the given order.
表示提交给定订单的命令。
Parameters:
参数:
trader_id (TraderId) – The trader ID for the command.
trader_id (TraderId) - 命令的交易者 ID。
strategy_id (StrategyId) – The strategy ID for the command.
strategy_id (StrategyId) - 命令的策略 ID。
order (Order) – The order to submit.
order (Order) - 要提交的订单。
command_id (UUID4) – The commands ID.
command_id (UUID4) - 命令的 ID。
ts_init (uint64_t) – UNIX timestamp (nanoseconds) when the object was initialized.
ts_init (uint64_t) - 对象初始化时的 UNIX 时间戳(纳秒)。
position_id (PositionId , optional) – The position ID for the command.
position_id (PositionId,可选) - 命令的持仓 ID。
client_id (ClientId , optional) – The execution client ID for the command.
client_id (ClientId,可选) - 命令的执行客户端 ID。
"""
def __init__(self, trader_id: TraderId, strategy_id: StrategyId, order: Order, command_id: UUID4, ts_init: int, position_id: PositionId | None = None, client_id=None):
...
Properties 属性
@property
def client_id(self):
"""
The execution client ID for the command.
命令的执行客户端 ID。
Returns:
ClientId or None
"""
...
@property
def exec_algorithm_id(self):
"""
The execution algorithm ID for the order.
订单的执行算法 ID。
Returns:
ExecAlgorithmId or None
"""
...
@property
def id(self) -> UUID4:
"""
The command message ID.
命令消息 ID。
Returns:
UUID4
"""
...
```python
@property
def instrument_id(self) -> InstrumentId:
"""
The instrument ID associated with the command.
与命令关联的金融工具 ID。
Returns:
InstrumentId
"""
...
@property
def order(self) -> Order:
"""
The order to submit.
要提交的订单。
Returns:
Order
"""
...
@property
def position_id(self):
"""
The position ID to associate with the order.
要与订单关联的持仓 ID。
Returns:
PositionId or None
"""
...
@property
def strategy_id(self) -> StrategyId:
"""
The strategy ID associated with the command.
与命令关联的策略 ID。
Returns:
StrategyId
"""
...
@property
def trader_id(self) -> TraderId:
"""
The trader ID associated with the command.
与命令关联的交易者 ID。
Returns:
TraderId
"""
...
@property
def ts_init(self) -> int:
"""
UNIX timestamp (nanoseconds) when the object was initialized.
对象初始化时的 UNIX 时间戳(纳秒)。
Returns:
uint64_t
"""
...
Methods 方法
@staticmethod
def from_dict(values: dict):
"""
Return a submit order command from the given dict values.
从给定的 dict 值返回提交订单命令。
Parameters: values (dict *[*str , object ]) – The values for initialization.
参数:values (dict *[*str,object]) - 初始化的值。
Return type: SubmitOrder
"""
...
@staticmethod
def to_dict(obj: 'SubmitOrder'):
"""
Return a dictionary representation of this object.
返回此对象的字典表示形式。
Return type: dict[str, object]
"""
...
class SubmitOrderList 提交订单列表
Bases: TradingCommand
class SubmitOrderList(TradingCommand):
"""
Represents a command to submit an order list consisting of an order batch/bulk of related parent-child contingent orders.
表示提交订单列表的命令,该列表由一批相关的父子意外事件订单组成。
This command can correspond to a NewOrderList message for the FIX protocol.
此命令可以对应于 FIX 协议的 NewOrderList 消息。
Parameters:
参数:
trader_id (TraderId) – The trader ID for the command.
trader_id (TraderId) - 命令的交易者 ID。
strategy_id (StrategyId) – The strategy ID for the command.
strategy_id (StrategyId) - 命令的策略 ID。
order_list (OrderList) – The order list to submit.
order_list (OrderList) - 要提交的订单列表。
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 时间戳(纳秒)。
position_id (PositionId , optional) – The position ID for the command.
position_id (PositionId,可选) - 命令的持仓 ID。
client_id (ClientId , optional) – The execution client ID for the command.
client_id (ClientId,可选) - 命令的执行客户端 ID。
"""
def __init__(self, trader_id: TraderId, strategy_id: StrategyId, order_list: OrderList, command_id: UUID4, ts_init: int, position_id: PositionId | None = None, client_id=None):
...
Properties 属性
@property
def client_id(self):
"""
The execution client ID for the command.
命令的执行客户端 ID。
Returns:
ClientId or None
"""
...
@property
def exec_algorithm_id(self):
"""
The execution algorithm ID for the order list.
订单列表的执行算法 ID。
Returns:
ExecAlgorithmId or None
"""
...
@property
def has_emulated_order(self):
"""
If the contained order_list holds at least one emulated order.
如果包含的 order_list 至少包含一个模拟订单。
Returns:
bool
"""
...
@property
def id(self) -> UUID4:
"""
The command message ID.
命令消息 ID。
Returns:
UUID4
"""
...
@property
def instrument_id(self) -> InstrumentId:
"""
The instrument ID associated with the command.
与命令关联的金融工具 ID。
Returns:
InstrumentId
"""
...
@property
def order_list(self) -> OrderList:
"""
The order list to submit.
要提交的订单列表。
Returns:
OrderList
"""
...
@property
def position_id(self):
"""
The position ID to associate with the orders.
要与订单关联的持仓 ID。
Returns:
PositionId or None
"""
...
@property
def strategy_id(self) -> StrategyId:
"""
The strategy ID associated with the command.
与命令关联的策略 ID。
Returns:
StrategyId
"""
...
@property
def trader_id(self) -> TraderId:
"""
The trader ID associated with the command.
与命令关联的交易者 ID。
Returns:
TraderId
"""
...
@property
def ts_init(self) -> int:
"""
UNIX timestamp (nanoseconds) when the object was initialized.
对象初始化时的 UNIX 时间戳(纳秒)。
Returns:
uint64_t
"""
...
Methods 方法
@staticmethod
def from_dict(values: dict):
"""
Return a submit order list command from the given dict values.
从给定的 dict 值返回提交订单列表命令。
Parameters: values (dict *[*str , object ]) – The values for initialization.
参数:values (dict *[*str,object]) - 初始化的值。
Return type: SubmitOrderList
"""
...
@staticmethod
def to_dict(obj: 'SubmitOrderList'):
"""
Return a dictionary representation of this object.
返回此对象的字典表示形式。
Return type: dict[str, object]
"""
...
class TradingCommand 交易命令
Bases: Command
class TradingCommand(Command):
"""
The base class for all trading related commands.
所有与交易相关的命令的基类。
Parameters:
参数:
client_id (ClientId, optional with no default so None must be passed explicitly) – The execution client ID for the command.
client_id (ClientId,可选,没有默认值,因此必须显式传递 None) - 命令的执行客户端 ID。
trader_id (TraderId) – The trader ID for the command.
trader_id (TraderId) - 命令的交易者 ID。
strategy_id (StrategyId) – The strategy ID for the command.
strategy_id (StrategyId) - 命令的策略 ID。
instrument_id (InstrumentId) – The instrument ID for the command.
instrument_id (InstrumentId) - 命令的金融工具 ID。
command_id (UUID4) – The commands ID.
command_id (UUID4) - 命令的 ID。
ts_init (uint64_t) – UNIX timestamp (nanoseconds) when the object was initialized.
ts_init (uint64_t) - 对象初始化时的 UNIX 时间戳(纳秒)。
Warning:
This class should not be used directly, but through a concrete subclass.
此类不应直接使用,而应通过具体的子类使用。
"""
def __init__(self, client_id: ClientId | None, trader_id: TraderId, strategy_id: StrategyId, instrument_id: InstrumentId, command_id: UUID4, ts_init: int):
...
Properties 属性
@property
def client_id(self):
"""
The execution client ID for the command.
命令的执行客户端 ID。
Returns:
ClientId or None
"""
...
@property
def id(self) -> UUID4:
"""
The command message ID.
命令消息 ID。
Returns:
UUID4
"""
...
@property
def instrument_id(self) -> InstrumentId:
"""
The instrument ID associated with the command.
与命令关联的金融工具 ID。
Returns:
InstrumentId
"""
...
@property
def strategy_id(self) -> StrategyId:
"""
The strategy ID associated with the command.
与命令关联的策略 ID。
Returns:
StrategyId
"""
...
@property
def trader_id(self) -> TraderId:
"""
The trader ID associated with the command.
与命令关联的交易者 ID。
Returns:
TraderId
"""
...
@property
def ts_init(self) -> int:
"""
UNIX timestamp (nanoseconds) when the object was initialized.
对象初始化时的 UNIX 时间戳(纳秒)。
Returns:
uint64_t
"""
...
Reports 报告
class ExecutionReport 执行报告
Bases: Document
class ExecutionReport(Document):
"""
The base class for all execution reports.
所有执行报告的基类。
"""
def __init__(self):
...
Properties 属性
@property
def id(self) -> UUID4:
"""
The document message ID.
文档消息 ID。
Returns:
UUID4
"""
...
@property
def ts_init(self) -> int:
"""
UNIX timestamp (nanoseconds) when the object was initialized.
对象初始化时的 UNIX 时间戳(纳秒)。
Returns:
uint64_t
"""
...
class OrderStatusReport 订单状态报告
Bases: ExecutionReport
class OrderStatusReport(ExecutionReport):
"""
Represents an order status at a point in time.
表示某个时间点的订单状态。
Parameters:
参数:
account_id (AccountId) – The account ID for the report.
account_id (AccountId) - 报告的账户 ID。
instrument_id (InstrumentId) – The instrument ID for the report.
instrument_id (InstrumentId) - 报告的金融工具 ID。
venue_order_id (VenueOrderId) – The reported order ID (assigned by the venue).
venue_order_id (VenueOrderId) - 报告的订单 ID(由场所分配)。
order_side (OrderSide {BUY, SELL}) – The reported order side.
order_side (OrderSide {BUY、SELL}) - 报告的订单方向。
order_type (OrderType) – The reported order type.
order_type (OrderType) - 报告的订单类型。
time_in_force (TimeInForce {GTC, IOC, FOK, GTD, DAY, AT_THE_OPEN, AT_THE_CLOSE}) – The reported order time in force.
time_in_force (TimeInForce {GTC、IOC、FOK、GTD、DAY、AT_THE_OPEN、AT_THE_CLOSE}) - 报告的订单有效时间。
order_status (OrderStatus) – The reported order status at the exchange.
order_status (OrderStatus) - 报告的交易所订单状态。
quantity (Quantity) – The reported order original quantity.
quantity (Quantity) - 报告的订单原始数量。
filled_qty (Quantity) – The reported filled quantity at the exchange.
filled_qty (Quantity) - 报告的交易所成交数量。
report_id (UUID4) – The report ID.
report_id (UUID4) - 报告 ID。
ts_accepted (int) – UNIX timestamp (nanoseconds) when the reported order was accepted.
ts_accepted (int) - 报告的订单被接受时的 UNIX 时间戳(纳秒)。
ts_last (int) – UNIX timestamp (nanoseconds) of the last order status change.
ts_last (int) - 上次订单状态更改的 UNIX 时间戳(纳秒)。
ts_init (int) – UNIX timestamp (nanoseconds) when the object was initialized.
ts_init (int) - 对象初始化时的 UNIX 时间戳(纳秒)。
client_order_id (ClientOrderId , optional) – The reported client order ID.
client_order_id (ClientOrderId,可选) - 报告的客户端订单 ID。
order_list_id (OrderListId , optional) – The reported order list ID associated with the order.
order_list_id (OrderListId,可选) - 与订单关联的报告的订单列表 ID。
contingency_type (ContingencyType, default NO_CONTINGENCY) – The reported order contingency type.
contingency_type (ContingencyType,默认 NO_CONTINGENCY) - 报告的订单意外事件类型。
expire_time (datetime , optional) – The order expiration.
expire_time (datetime,可选) - 订单到期时间。
price (Price , optional) – The reported order price (LIMIT).
price (Price,可选) - 报告的订单价格 (LIMIT)。
trigger_price (Price , optional) – The reported order trigger price (STOP).
trigger_price (Price,可选) - 报告的订单触发价格 (STOP)。
trigger_type (TriggerType, default NO_TRIGGER) – The reported order trigger type.
trigger_type (TriggerType,默认 NO_TRIGGER) - 报告的订单触发类型。
limit_offset (Decimal , optional) – The trailing offset for the order price (LIMIT).
limit_offset (Decimal,可选) - 订单价格 (LIMIT) 的追踪偏移量。
trailing_offset (Decimal , optional) – The trailing offset for the trigger price (STOP).
trailing_offset (Decimal,可选) - 触发价格 (STOP) 的追踪偏移量。
trailing_offset_type (TrailingOffsetType, default NO_TRAILING_OFFSET) – The order trailing offset type.
trailing_offset_type (TrailingOffsetType,默认 NO_TRAILING_OFFSET) - 订单追踪偏移量类型。
avg_px (Decimal , optional) – The reported order average fill price.
avg_px (Decimal,可选) - 报告的订单平均成交价格。
display_qty (Quantity , optional) – The reported order quantity displayed on the public book (iceberg).
display_qty (Quantity,可选) - 报告的公共订单簿上显示的订单数量(冰山订单)。
post_only (bool , default False) – If the reported order will only provide liquidity (make a market).
post_only (bool,默认 False) - 报告的订单是否只提供流动性(做市)。
reduce_only (bool , default False) – If the reported order carries the ‘reduce-only’ execution instruction.
reduce_only (bool,默认 False) - 报告的订单是否带有“仅减仓”执行指令。
cancel_reason (str , optional) – The reported reason for order cancellation.
cancel_reason (str,可选) - 报告的订单取消原因。
ts_triggered (int , optional) – UNIX timestamp (nanoseconds) when the object was initialized.
ts_triggered (int,可选) - 对象初始化时的 UNIX 时间戳(纳秒)。
Raises:
引发:
ValueError – If quantity is not positive (> 0).
ValueError - 如果数量不是正数 (> 0)。
ValueError – If filled_qty is negative (< 0).
ValueError - 如果 filled_qty 为负数 (< 0)。
ValueError – If trigger_price is not None and trigger_price is equal to NO_TRIGGER.
ValueError - 如果 trigger_price 不为 None 并且 trigger_price 等于 NO_TRIGGER。
ValueError – If limit_offset or trailing_offset is not None and trailing_offset_type is equal to NO_TRAILING_OFFSET.
ValueError - 如果 limit_offset 或 trailing_offset 不为 None 并且 trailing_offset_type 等于 NO_TRAILING_OFFSET。
"""
def __init__(self, account_id: AccountId, instrument_id: InstrumentId, venue_order_id: VenueOrderId, order_side: OrderSide, order_type: OrderType, time_in_force: TimeInForce, order_status: OrderStatus, quantity: Quantity, filled_qty: Quantity, report_id: UUID4, ts_accepted: int, ts_last: int, ts_init: int, client_order_id: ClientOrderId = None, order_list_id: OrderListId = None, contingency_type=ContingencyType.NO_CONTINGENCY, expire_time: datetime = None, price: Price = None, trigger_price: Price = None, trigger_type=TriggerType.NO_TRIGGER, limit_offset: Decimal = None, trailing_offset: Decimal = None, trailing_offset_type=TrailingOffsetType.NO_TRAILING_OFFSET, avg_px: Decimal = None, display_qty: Quantity = None, post_only: bool = False, reduce_only: bool = False, cancel_reason: str = None, ts_triggered: int = None):
...
Properties 属性
@property
def id(self) -> UUID4:
"""
The document message ID.
文档消息 ID。
Returns:
UUID4
"""
...
@property
def ts_init(self) -> int:
"""
UNIX timestamp (nanoseconds) when the object was initialized.
对象初始化时的 UNIX 时间戳(纳秒)。
Returns:
uint64_t
"""
...
class FillReport 成交报告
Bases: ExecutionReport
class FillReport(ExecutionReport):
"""
Represents a report of a single order fill.
表示单个订单成交的报告。
Parameters:
参数:
account_id (AccountId) – The account ID for the report.
account_id (AccountId) - 报告的账户 ID。
instrument_id (InstrumentId) – The reported instrument ID for the trade.
instrument_id (InstrumentId) - 交易的报告金融工具 ID。
venue_order_id (VenueOrderId) – The reported venue order ID (assigned by the venue) for the trade.
venue_order_id (VenueOrderId) - 交易的报告场所订单 ID(由场所分配)。
trade_id (TradeId) – The reported trade match ID (assigned by the venue).
trade_id (TradeId) - 报告的交易匹配 ID(由场所分配)。
order_side (OrderSide {BUY, SELL}) – The reported order side for the trade.
order_side (OrderSide {BUY、SELL}) - 交易的报告订单方向。
last_qty (Quantity) – The reported quantity of the trade.
last_qty (Quantity) - 报告的交易数量。
last_px (Price) – The reported price of the trade.
last_px (Price) - 报告的交易价格。
liquidity_side (LiquiditySide {NO_LIQUIDITY_SIDE, MAKER, TAKER}) – The reported liquidity side for the trade.
liquidity_side (LiquiditySide {NO_LIQUIDITY_SIDE、MAKER、TAKER}) - 交易的报告流动性方向。
report_id (UUID4) – The report ID.
report_id (UUID4) - 报告 ID。
ts_event (int) – UNIX timestamp (nanoseconds) when the trade occurred.
ts_event (int) - 交易发生的 UNIX 时间戳(纳秒)。
ts_init (int) – UNIX timestamp (nanoseconds) when the object was initialized.
ts_init (int) - 对象初始化时的 UNIX 时间戳(纳秒)。
client_order_id (ClientOrderId , optional) – The reported client order ID for the trade.
client_order_id (ClientOrderId,可选) - 交易的报告客户端订单 ID。
venue_position_id (PositionId , optional) – The reported venue position ID for the trade. If the trading venue has assigned a position ID / ticket for the trade then pass that here, otherwise pass None and the execution engine OMS will handle position ID resolution.
venue_position_id (PositionId,可选) - 交易的报告场所持仓 ID。如果交易场所已为交易分配了持仓 ID/票据,则在此处传递该 ID,否则传递 None,执行引擎 OMS 将处理持仓 ID 解析。
commission (Money , optional) – The reported commission for the trade (can be None).
commission (Money,可选) - 报告的交易佣金(可以为 None)。
Raises: ValueError – If last_qty is not positive (> 0).
引发:ValueError - 如果 last_qty 不是正数 (> 0)。
"""
def __init__(self, account_id: AccountId, instrument_id: InstrumentId, venue_order_id: VenueOrderId, trade_id: TradeId, order_side: OrderSide, last_qty: Quantity, last_px: Price, liquidity_side: LiquiditySide, report_id: UUID4, ts_event: int, ts_init: int, client_order_id: ClientOrderId = None, venue_position_id: PositionId = None, commission: Money = None):
...
Properties 属性
@property
def id(self) -> UUID4:
"""
The document message ID.
文档消息 ID。
Returns:
UUID4
"""
...
@property
def ts_init(self) -> int:
"""
UNIX timestamp (nanoseconds) when the object was initialized.
对象初始化时的 UNIX 时间戳(纳秒)。
Returns:
uint64_t
"""
...
class PositionStatusReport 持仓状态报告
Bases: ExecutionReport
class PositionStatusReport(ExecutionReport):
"""
Represents a position status at a point in time.
表示某个时间点的持仓状态。
Parameters:
参数:
account_id (AccountId) – The account ID for the report.
account_id (AccountId) - 报告的账户 ID。
instrument_id (InstrumentId) – The reported instrument ID for the position.
instrument_id (InstrumentId) - 持仓的报告金融工具 ID。
position_side (PositionSide {FLAT, LONG, SHORT}) – The reported position side at the exchange.
position_side (PositionSide {FLAT、LONG、SHORT}) - 报告的交易所持仓方向。
quantity (Quantity) – The reported position quantity at the exchange.
quantity (Quantity) - 报告的交易所持仓数量。
report_id (UUID4) – The report ID.
report_id (UUID4) - 报告 ID。
ts_last (int) – UNIX timestamp (nanoseconds) of the last position change.
ts_last (int) - 上次持仓更改的 UNIX 时间戳(纳秒)。
ts_init (int) – UNIX timestamp (nanoseconds) when the object was initialized.
ts_init (int) - 对象初始化时的 UNIX 时间戳(纳秒)。
venue_position_id (PositionId , optional) – The reported venue position ID (assigned by the venue). If the trading venue has assigned a position ID / ticket for the trade then pass that here, otherwise pass None and the execution engine OMS will handle position ID resolution.
venue_position_id (PositionId,可选) - 报告的场所持仓 ID(由场所分配)。如果交易场所已为交易分配了持仓 ID/票据,则在此处传递该 ID,否则传递 None,执行引擎 OMS 将处理持仓 ID 解析。
"""
def __init__(self, account_id: AccountId, instrument_id: InstrumentId, position_side: PositionSide, quantity: Quantity, report_id: UUID4, ts_last: int, ts_init: int, venue_position_id: PositionId = None):
...
Properties 属性
@property
def id(self) -> UUID4:
"""
The document message ID.
文档消息 ID。
Returns:
UUID4
"""
...
@property
def ts_init(self) -> int:
"""
UNIX timestamp (nanoseconds) when the object was initialized.
对象初始化时的 UNIX 时间戳(纳秒)。
Returns:
uint64_t
"""
...
class ExecutionMassStatus 执行批量状态
Bases: Document
class ExecutionMassStatus(Document):
"""
Represents an execution mass status report for an execution client - including status of all orders, trades for those orders and open positions.
表示执行客户端的执行批量状态报告 - 包括所有订单的状态、这些订单的交易和未结持仓。
Parameters:
参数:
venue (Venue) – The venue for the report.
venue (Venue) - 报告的场所。
client_id (ClientId) – The client ID for the report.
client_id (ClientId) - 报告的客户端 ID。
account_id (AccountId) – The account ID for the report.
account_id (AccountId) - 报告的账户 ID。
report_id (UUID4) – The report ID.
report_id (UUID4) - 报告 ID。
ts_init (int) – UNIX timestamp (nanoseconds) when the object was initialized.
ts_init (int) - 对象初始化时的 UNIX 时间戳(纳秒)。
"""
def __init__(self, venue: Venue, client_id: ClientId, account_id: AccountId, report_id: UUID4, ts_init: int):
...
Properties 属性
@property
def order_reports(self) -> dict[VenueOrderId, OrderStatusReport]:
"""
The order status reports.
订单状态报告。
Return type: dict[VenueOrderId, OrderStatusReport]
"""
...
@property
def fill_reports(self):
"""
The fill reports.
成交报告。
Return type: dict[VenueOrderId, list[FillReport]
"""
...
@property
def position_reports(self):
"""
The position status reports.
持仓状态报告。
Return type: dict[InstrumentId, list[PositionStatusReport]]
"""
...
@property
def id(self) -> UUID4:
"""
The document message ID.
文档消息 ID。
Returns:
UUID4
"""
...
@property
def ts_init(self) -> int:
"""
UNIX timestamp (nanoseconds) when the object was initialized.
对象初始化时的 UNIX 时间戳(纳秒)。
Returns:
uint64_t
"""
...
Methods 方法
def add_order_reports(self, reports: list[OrderStatusReport]) -> None:
"""
Add the order reports to the mass status.
将订单报告添加到批量状态。
Parameters: reports (list [OrderStatusReport ]) – The list of reports to add.
参数:reports (list [OrderStatusReport ]) - 要添加的报告列表。
Raises: TypeError – If reports contains a type other than FillReport.
引发:TypeError - 如果 reports 包含 FillReport 以外的类型。
"""
...
def add_fill_reports(self, reports: list[FillReport]) -> None:
"""
Add the fill reports to the mass status.
将成交报告添加到批量状态。
Parameters: reports (list [FillReport ]) – The list of reports to add.
参数:reports (list [FillReport ]) - 要添加的报告列表。
Raises: TypeError – If reports contains a type other than FillReport.
引发:TypeError - 如果 reports 包含 FillReport 以外的类型。
"""
...
def add_position_reports(self, reports: list[PositionStatusReport]) -> None:
"""
Add the position status reports to the mass status.
将持仓状态报告添加到批量状态。
Parameters: reports (list [PositionStatusReport ]) – The reports to add.
参数:reports (list [PositionStatusReport ]) - 要添加的报告。
"""
...
The ExecutionEngine is the central component of the entire execution stack.
执行引擎是整个执行堆栈的核心组件。
The execution engines primary responsibility is to orchestrate interactions between the ExecutionClient instances, and the rest of the platform. This includes sending commands to, and receiving events from, the trading venue endpoints via its registered execution clients.
执行引擎的主要职责是协调执行客户端实例与平台其余部分之间的交互。这包括通过其注册的执行客户端向交易场所端点发送命令以及从交易场所端点接收事件。
The engine employs a simple fan-in fan-out messaging pattern to execute TradingCommand messages, and process AccountState or OrderEvent type messages.
引擎采用简单的扇入扇出消息传递模式来执行 TradingCommand 消息,并处理 AccountState 或 OrderEvent 类型消息。
Alternative implementations can be written on top of the generic engine - which just need to override the execute and process methods.
可以在通用引擎之上编写替代实现 - 只需要覆盖 execute 和 process 方法。
class ExecutionEngine 执行引擎
Bases: Component
class ExecutionEngine(Component):
"""
Provides a high-performance execution engine for the management of many ExecutionClient instances, and the asynchronous ingest and distribution of trading commands and events.
提供高性能执行引擎,用于管理许多 ExecutionClient 实例,以及异步提取和分发交易命令和事件。
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 (ExecEngineConfig , optional) – The configuration for the instance.
config (ExecEngineConfig,可选) - 实例的配置。
Raises: TypeError – If config is not of type ExecEngineConfig.
引发:TypeError - 如果 config 的类型不是 ExecEngineConfig。
"""
def __init__(self, msgbus: MessageBus, cache: Cache, clock: Clock, config: ExecEngineConfig | None = None) -> None:
...
Properties 属性
@property
def command_count(self):
"""
The total count of commands 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 execution client registered with the engine.
返回在引擎中注册的默认执行客户端。
Return type: ClientId or None
Type: ExecutionEngine.default_client
"""
...
@property
def event_count(self):
"""
The total count of events received by the engine.
引擎接收到的事件总数。
Returns:
int
"""
...
@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 reconciliation(self) -> bool:
"""
bool
Return whether the reconciliation process will be run on start.
返回是否将在启动时运行对账进程。
Return type: bool
Type: ExecutionEngine.reconciliation
"""
...
@property
def registered_clients(self) -> list[ClientId]:
"""
list[ClientId]
Return the execution clients registered with the engine.
返回在引擎中注册的执行客户端。
Return type: list[ClientId]
Type: ExecutionEngine.registered_clients
"""
...
@property
def report_count(self) -> 'int':
"""
'int' The total count of reports received by the engine.
'int' 引擎接收到的报告总数。
Returns:
int
Type: report_count
"""
...
@property
def snapshot_orders(self):
"""
If order state snapshots should be persisted.
是否应持久化订单状态快照。
Returns:
bool
"""
...
```python
@property
def snapshot_positions(self):
"""
If position state snapshots should be persisted.
是否应持久化持仓状态快照。
Returns:
bool
"""
...
@property
def snapshot_positions_interval_secs(self):
"""
The interval (seconds) at which additional position state snapshots are persisted.
持久化其他持仓状态快照的间隔(秒)。
Returns:
double
"""
...
@property
def snapshot_positions_timer_name(self):
"""
"""
...
@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
"""
...
Methods 方法
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 check_integrity(self) -> bool:
"""
Check integrity of data within the cache and clients.
检查缓存和客户端中数据的完整性。
Returns: True if checks pass, else False.
返回值:如果检查通过,则返回 True,否则返回 False。
Return type: bool
"""
...
def check_residuals(self) -> bool:
"""
Check for any residual open state and log warnings if found.
检查是否有任何剩余的打开状态,如果找到,则记录警告。
‘Open state’ is considered to be open orders and open positions.
“打开状态”被认为是打开的订单和打开的持仓。
Returns: True if residuals exist, else False.
返回值:如果存在剩余状态,则返回 True,否则返回 False。
Return type: bool
"""
...
def connect(self) -> None:
"""
Connect the engine by calling connect on all registered clients.
通过对所有注册的客户端调用 connect 来连接引擎。
"""
...
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: ExecutionClient) -> void:
"""
Deregister the given execution client from the execution engine.
从执行引擎中取消注册给定的执行客户端。
Parameters: client (ExecutionClient) – The execution client to deregister.
参数:client (ExecutionClient) - 要取消注册的执行客户端。
Raises: ValueError – If client is not registered with the execution engine.
引发:ValueError - 如果客户端未在执行引擎中注册。
"""
...
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: TradingCommand) -> void:
"""
Execute the given command.
执行给定的命令。
Parameters: command (TradingCommand) – The command to execute.
参数:command (TradingCommand) - 要执行的命令。
"""
...
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.
如果组件未处于可执行此方法的有效状态,则组件状态将不会更改,并且将记录错误。
"""
...
def flush_db(self) -> void:
"""
Flush the execution database which permanently removes all persisted data.
刷新执行数据库,永久删除所有持久化数据。
WARNING
永久性数据丢失。
"""
...
@classmethod
def fully_qualified_name(cls) -> str:
"""
Return the fully qualified name for the components class.
返回组件类的完全限定名称。
Return type: str
"""
...
def get_external_order_claim(self, instrument_id: InstrumentId):
"""
Get any external order claim for the given instrument ID.
获取给定金融工具 ID 的任何外部订单认领。
Parameters: instrument_id (InstrumentId) – The instrument ID for the claim.
参数:instrument_id (InstrumentId) - 认领的金融工具 ID。
Return type: StrategyId or None
"""
...
def get_external_order_claims_instruments(self) -> set:
"""
Get all external order claims instrument IDs.
获取所有外部订单认领金融工具 ID。
Return type: set[InstrumentId]
"""
...
def load_cache(self) -> void:
"""
Load the cache up from the execution database.
从执行数据库加载缓存。
"""
...
def position_id_count(self, strategy_id: StrategyId) -> int:
"""
The position ID count for the given strategy ID.
给定策略 ID 的持仓 ID 计数。
Parameters: strategy_id (StrategyId) – The strategy ID for the position count.
参数:strategy_id (StrategyId) - 持仓计数的策略 ID。
Return type: int
"""
...
def process(self, event: OrderEvent) -> void:
"""
Process the given order event.
处理给定的订单事件。
Parameters: event (OrderEvent) – The order event to process.
参数:event (OrderEvent) - 要处理的订单事件。
"""
...
def reconcile_mass_status(self, report: ExecutionMassStatus) -> None:
"""
Reconcile the given execution mass status report.
协调给定的执行批量状态报告。
Parameters: report (ExecutionMassStatus) – The execution mass status report to reconcile.
参数:report (ExecutionMassStatus) - 要协调的执行批量状态报告。
"""
...
def reconcile_report(self, report: ExecutionReport) -> bool:
"""
Check the given execution report.
检查给定的执行报告。
Parameters: report (ExecutionReport) – The execution report to check.
参数:report (ExecutionReport) - 要检查的执行报告。
Returns: True if reconciliation successful, else False.
返回值:如果协调成功,则返回 True,否则返回 False。
Return type: bool
"""
...
async def reconcile_state(self, timeout_secs: float = 10.0) -> bool:
"""
Reconcile the internal execution state with all execution clients (external state).
将内部执行状态与所有执行客户端(外部状态)协调起来。
Parameters: timeout_secs (double , default 10.0) – The timeout (seconds) for reconciliation to complete.
参数:timeout_secs (double,默认 10.0) - 协调完成的超时时间(秒)。
Returns: True if states reconcile within timeout, else False.
返回值:如果状态在超时时间内协调,则返回 True,否则返回 False。
Return type: bool
Raises: ValueError – If timeout_secs is not positive (> 0).
引发:ValueError - 如果 timeout_secs 不是正数 (> 0)。
"""
...
def register_client(self, client: ExecutionClient) -> void:
"""
Register the given execution client with the execution engine.
将给定的执行客户端注册到执行引擎。
If the client.venue is None and a default routing client has not been previously registered then will be registered as such.
如果 client.venue 为 None 并且之前没有注册默认路由客户端,则将注册为默认路由客户端。
Parameters: client (ExecutionClient) – The execution client to register.
参数:client (ExecutionClient) - 要注册的执行客户端。
Raises: ValueError – If client is already registered with the execution engine.
引发:ValueError - 如果客户端已在执行引擎中注册。
"""
...
def register_default_client(self, client: ExecutionClient) -> 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 (ExecutionClient) – The client to register.
参数:client (ExecutionClient) - 要注册的客户端。
"""
...
def register_external_order_claims(self, strategy: Strategy) -> void:
"""
Register the given strategies external order claim instrument IDs (if any)
注册给定策略的外部订单认领金融工具 ID(如果有)。
Parameters: strategy (Strategy) – The strategy for the registration.
参数:strategy (Strategy) - 要注册的策略。
Raises: InvalidConfiguration – If a strategy is already registered to claim external orders for an instrument ID.
引发:InvalidConfiguration - 如果策略已注册以认领金融工具 ID 的外部订单。
"""
...
def register_oms_type(self, strategy: Strategy) -> void:
"""
Register the given trading strategies OMS (Order Management System) type.
注册给定交易策略的 OMS(订单管理系统)类型。
Parameters: strategy (Strategy) – The strategy for the registration.
参数:strategy (Strategy) - 要注册的策略。
"""
...
def register_venue_routing(self, client: ExecutionClient, venue: Venue) -> void:
"""
Register the given client to route orders 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 orders to.
venue (Venue) - 要将订单路由到的场所。
client (ExecutionClient) – The client for the venue routing.
client (ExecutionClient) - 用于场所路由的客户端。
"""
...
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 stop_clients(self) -> void:
"""
Stop the registered clients.
停止注册的客户端。
"""
...
## class OrderEmulator 订单模拟器
Bases: Actor
```python
class OrderEmulator(Actor):
"""
Provides order emulation for specified trigger types.
为指定的触发器类型提供订单模拟。
Parameters:
参数:
portfolio (PortfolioFacade) – The read-only portfolio for the order emulator.
portfolio (PortfolioFacade) - 订单模拟器的只读投资组合。
msgbus (MessageBus) – The message bus for the order emulator.
msgbus (MessageBus) - 订单模拟器的消息总线。
cache (Cache) – The cache for the order emulator.
cache (Cache) - 订单模拟器的缓存。
clock (Clock) – The clock for the order emulator.
clock (Clock) - 订单模拟器的时钟。
config (OrderEmulatorConfig , optional) – The configuration for the order emulator.
config (OrderEmulatorConfig,可选) - 订单模拟器的配置。
"""
def __init__(self, portfolio: PortfolioFacade, msgbus: MessageBus, cache: Cache, clock: Clock, config: OrderEmulatorConfig | None = None):
...
Properties 属性
@property
def cache(self) :
"""
The read-only cache for the actor.
actor 的只读缓存。
Returns:
CacheFacade
"""
...
@property
def clock(self):
"""
The actors clock.
actor 的时钟。
Returns:
Clock
"""
...
@property
def command_count(self):
"""
The total count of commands received by the emulator.
模拟器收到的命令总数。
Returns:
int
"""
...
@property
def config(self):
"""
The actors configuration.
actor 的配置。
Returns:
NautilusConfig
"""
...
@property
def debug(self):
"""
If debug mode is active (will provide extra debug logging).
如果调试模式处于活动状态(将提供额外的调试日志)。
Returns:
bool
"""
...
@property
def event_count(self):
"""
The total count of events received by the emulator.
模拟器收到的事件总数。
Returns:
int
"""
...
@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 log(self) :
"""
The actors logger.
actor 的日志记录器。
Returns:
Logger
"""
...
@property
def msgbus(self):
"""
The message bus for the actor (if registered).
actor 的消息总线(如果已注册)。
Returns:
MessageBus or None
"""
...
@property
def portfolio(self):
"""
The read-only portfolio for the actor.
actor 的只读投资组合。
Returns:
PortfolioFacade
"""
...
@property
def registered_indicators(self):
"""
Return the registered indicators for the strategy.
返回策略的已注册指标。
Return type: list[Indicator]
"""
...
@property
def state(self) -> ComponentState:
"""
ComponentState
Return the components current state.
返回组件的当前状态。
Return type: ComponentState
Type: Component.state
"""
...
@property
def subscribed_quotes(self) -> list[InstrumentId]:
"""
list[InstrumentId]
Return the subscribed quote feeds for the emulator.
返回模拟器订阅的报价源。
Return type: list[InstrumentId]
Type: OrderEmulator.subscribed_quotes
"""
...
@property
def subscribed_trades(self) -> list[InstrumentId]:
"""
list[InstrumentId]
Return the subscribed trade feeds for the emulator.
返回模拟器订阅的交易源。
Return type: list[InstrumentId]
Type: OrderEmulator.subscribed_trades
"""
...
@property
def trader_id(self):
"""
The trader ID associated with the component.
与组件关联的交易者 ID。
Returns:
TraderId
"""
...
@property
def type(self):
"""
The components type.
组件类型。
Returns:
type
"""
...
Methods 方法
def active_task_ids(self) -> list:
"""
Return the active task identifiers.
返回活动的 task 标识符。
Return type: list[TaskId]
"""
...
def add_synthetic(self, synthetic: SyntheticInstrument) -> void:
"""
Add the created synthetic instrument to the cache.
将创建的合成金融工具添加到缓存中。
Parameters: synthetic (SyntheticInstrument) – The synthetic instrument to add to the cache.
参数:synthetic (SyntheticInstrument) - 要添加到缓存中的合成金融工具。
Raises: KeyError – If synthetic is already in the cache.
引发:KeyError - 如果合成金融工具已存在于缓存中。
"""
...
def cancel_all_tasks(self) -> void:
"""
Cancel all queued and active tasks.
取消所有排队和活动的 task。
"""
...
def cancel_task(self, task_id: TaskId) -> void:
"""
Cancel the task with the given task_id (if queued or active).
取消具有给定 task_id 的任务(如果已排队或活动)。
If the task is not found then a warning is logged.
如果未找到任务,则会记录警告。
Parameters: task_id (TaskId) – The task identifier.
参数:task_id (TaskId) – 任务标识符。
"""
...
def create_matching_core(self, instrument_id: InstrumentId, price_increment: Price):
"""
Create an internal matching core for the given instrument.
为给定的金融工具创建一个内部匹配核心。
Parameters:
参数:
instrument_id (InstrumentId) – The instrument ID for the matching core.
instrument_id (InstrumentId) - 匹配核心的金融工具 ID。
price_increment (Price) – The minimum price increment (tick size) for the matching core.
price_increment (Price) - 匹配核心的最小价格增量(刻度大小)。
Return type: MatchingCore
Raises: KeyError – If a matching core for the given instrument_id already exists.
引发:KeyError - 如果给定 instrument_id 的匹配核心已存在。
"""
...
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_warning_event(self, event) -> void:
"""
Deregister the given event type from warning log levels.
从警告日志级别取消注册给定的事件类型。
Parameters: event (type) – The event class to deregister.
参数:event (type) - 要取消注册的事件类。
"""
...
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: TradingCommand) -> void:
"""
Execute the given command.
执行给定的命令。
Parameters: command (TradingCommand) – The command to execute.
参数:command (TradingCommand) - 要执行的命令。
"""
...
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 get_matching_core(self, instrument_id: InstrumentId):
"""
Return the emulators matching core for the given instrument ID.
返回给定金融工具 ID 的模拟器的匹配核心。
Return type: MatchingCore or None
"""
...
def get_submit_order_commands(self) -> dict:
"""
Return the emulators cached submit order commands.
返回模拟器缓存的提交订单命令。
Return type: dict[ClientOrderId, SubmitOrder]
"""
...
def handle_bar(self, bar: Bar) -> void:
"""
Handle the given bar data.
处理给定的 bar 数据。
If state is RUNNING then passes to on_bar.
如果状态为 RUNNING,则传递给 on_bar。
Parameters: bar (Bar) – The bar received.
参数:bar (Bar) - 接收到的 bar。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def handle_bars(self, bars: list) -> void:
"""
Handle the given historical bar data by handling each bar individually.
通过单独处理每个 bar 来处理给定的历史 bar 数据。
Parameters: bars (list [Bar ]) – The bars to handle.
参数:bars (list [Bar ]) - 要处理的 bar。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def handle_data(self, data: Data) -> void:
"""
Handle the given data.
处理给定的数据。
If state is RUNNING then passes to on_data.
如果状态为 RUNNING,则传递给 on_data。
Parameters: data (Data) – The data received.
参数:data (Data) - 接收到的数据。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def handle_event(self, event: Event) -> void:
"""
Handle the given event.
处理给定的事件。
Parameters: event (Event) – The event received.
参数:event (Event) - 接收到的事件。
"""
...
def handle_historical_data(self, data) -> void:
"""
Handle the given historical data.
处理给定的历史数据。
Parameters: data (Data) – The historical data received.
参数:data (Data) - 接收到的历史数据。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def handle_instrument(self, instrument: Instrument) -> void:
"""
Handle the given instrument.
处理给定的金融工具。
Passes to on_instrument if state is RUNNING.
如果状态为 RUNNING,则传递给 on_instrument。
Parameters: instrument (Instrument) – The instrument received.
参数:instrument (Instrument) - 接收到的金融工具。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def handle_instrument_close(self, update: InstrumentClose) -> void:
"""
Handle the given instrument close update.
处理给定的金融工具关闭更新。
If state is RUNNING then passes to on_instrument_close.
如果状态为 RUNNING,则传递给 on_instrument_close。
Parameters: update (InstrumentClose) – The update received.
参数:update (InstrumentClose) - 接收到的更新。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def handle_instrument_status(self, data: InstrumentStatus) -> void:
"""
Handle the given instrument status update.
处理给定的金融工具状态更新。
If state is RUNNING then passes to on_instrument_status.
如果状态为 RUNNING,则传递给 on_instrument_status。
Parameters: data (InstrumentStatus) – The status update received.
参数:data (InstrumentStatus) - 接收到的状态更新。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def handle_instruments(self, instruments: list) -> void:
"""
Handle the given instruments data by handling each instrument individually.
通过单独处理每个金融工具来处理给定的金融工具数据。
Parameters: instruments (list [Instrument ]) – The instruments received.
参数:instruments (list [Instrument ]) - 接收到的金融工具。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def handle_order_book(self, order_book: OrderBook) -> void:
"""
Handle the given order book.
处理给定的订单簿。
Passes to on_order_book if state is RUNNING.
如果状态为 RUNNING,则传递给 on_order_book。
Parameters: order_book (OrderBook) – The order book received.
参数:order_book (OrderBook) - 接收到的订单簿。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def handle_order_book_deltas(self, deltas) -> void:
"""
"""
...
def handle_quote_tick(self, tick: QuoteTick) -> void:
"""
"""
...
def handle_quote_ticks(self, ticks: list) -> void:
"""
Handle the given historical quote tick data by handling each tick individually.
通过单独处理每个 tick 来处理给定的历史报价 tick 数据。
Parameters: ticks (list [QuoteTick ]) – The ticks received.
参数:ticks (list [QuoteTick ]) - 接收到的 tick。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def handle_trade_tick(self, tick: TradeTick) -> void:
"""
"""
...
def handle_trade_ticks(self, ticks: list) -> void:
"""
Handle the given historical trade tick data by handling each tick individually.
通过单独处理每个 tick 来处理给定的历史交易 tick 数据。
Parameters: ticks (list [TradeTick ]) – The ticks received.
参数:ticks (list [TradeTick ]) - 接收到的 tick。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def has_active_tasks(self) -> bool:
"""
Return a value indicating whether there are any active tasks.
返回值指示是否有任何活动的 task。
Return type: bool
"""
...
def has_any_tasks(self) -> bool:
"""
Return a value indicating whether there are any queued or active tasks.
返回值指示是否有任何排队或活动的 task。
Return type: bool
"""
...
def has_pending_requests(self) -> bool:
"""
Return whether the actor is pending processing for any requests.
返回 actor 是否正在等待处理任何请求。
Returns: True if any requests are pending, else False.
返回值:如果有任何请求正在等待处理,则返回 True,否则返回 False。
Return type: bool
"""
...
def has_queued_tasks(self) -> bool:
"""
Return a value indicating whether there are any queued tasks.
返回值指示是否有任何排队的 task。
Return type: bool
"""
...
def indicators_initialized(self) -> bool:
"""
Return a value indicating whether all indicators are initialized.
返回值指示是否所有指标都已初始化。
Returns: True if all initialized, else False
返回值:如果所有指标都已初始化,则返回 True,否则返回 False。
Return type: bool
"""
...
def is_pending_request(self, request_id: UUID4) -> bool:
"""
Return whether the request for the given identifier is pending processing.
返回给定标识符的请求是否正在等待处理。
Parameters: request_id (UUID4) – The request ID to check.
参数:request_id (UUID4) - 要检查的请求 ID。
Returns: True if request is pending, else False.
返回值:如果请求正在等待处理,则返回 True,否则返回 False。
Return type: bool
"""
...
def load(self, state: dict) -> void:
"""
Load the actor/strategy state from the give state dictionary.
从给定的状态字典加载 actor/strategy 状态。
Calls on_load and passes the state.
调用 on_load 并传递状态。
Parameters: state (dict *[*str , object ]) – The state dictionary.
参数:state (dict *[*str , object ]) - 状态字典。
Raises: RuntimeError – If actor/strategy is not registered with a trader.
引发:RuntimeError - 如果 actor/strategy 未在交易者处注册。
Warning:
Exceptions raised will be caught, logged, and reraised.
引发的异常将被捕获、记录并重新引发。
"""
...
def on_bar(self, bar: Bar) -> void:
"""
Actions to be performed when running and receives a bar.
运行时执行的操作以及接收到的 bar。
Parameters: bar (Bar) – The bar received.
参数:bar (Bar) - 接收到的 bar。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_data(self, data: Data) -> void:
"""
Actions to be performed when running and receives data.
运行时执行的操作以及接收到的数据。
Parameters: data (Data) – The data received.
参数:data (Data) - 接收到的数据。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_degrade(self) -> void:
"""
Actions to be performed on degrade.
降级时执行的操作。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
Should be overridden in the actor implementation.
应该在 actor 实现中重写。
"""
...
def on_dispose(self) -> void:
"""
"""
...
def on_event(self, event: Event) -> void:
"""
Handle the given event.
处理给定的事件。
Parameters: event (Event) – The received event to handle.
参数:event (Event) - 要处理的接收到的事件。
"""
...
def on_fault(self) -> void:
"""
Actions to be performed on fault.
出现故障时执行的操作。
Cleanup any resources used by the actor here.
在此处清理 actor 使用的任何资源。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
Should be overridden in the actor implementation.
应该在 actor 实现中重写。
"""
...
def on_historical_data(self, data) -> void:
"""
Actions to be performed when running and receives historical data.
运行时执行的操作以及接收到的历史数据。
Parameters: data (Data) – The historical data received.
参数:data (Data) - 接收到的历史数据。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_instrument(self, instrument: Instrument) -> void:
"""
Actions to be performed when running and receives an instrument.
运行时执行的操作以及接收到的金融工具。
Parameters: instrument (Instrument) – The instrument received.
参数:instrument (Instrument) - 接收到的金融工具。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_instrument_close(self, update: InstrumentClose) -> void:
"""
Actions to be performed when running and receives an instrument close update.
运行时执行的操作以及接收到的金融工具关闭更新。
Parameters: update (InstrumentClose) – The instrument close received.
参数:update (InstrumentClose) - 接收到的金融工具关闭。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_instrument_status(self, data: InstrumentStatus) -> void:
"""
Actions to be performed when running and receives an instrument status update.
运行时执行的操作以及接收到的金融工具状态更新。
Parameters: data (InstrumentStatus) – The instrument status update received.
参数:data (InstrumentStatus) - 接收到的金融工具状态更新。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_load(self, state: dict) -> void:
"""
Actions to be performed when the actor state is loaded.
加载 actor 状态时执行的操作。
Saved state values will be contained in the give state dictionary.
保存的状态值将包含在给定的状态字典中。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_order_book(self, order_book: OrderBook) -> void:
"""
Actions to be performed when running and receives an order book.
运行时执行的操作以及接收到的订单簿。
Parameters: order_book (OrderBook) – The order book received.
参数:order_book (OrderBook) - 接收到的订单簿。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_order_book_deltas(self, deltas) -> void:
"""
"""
...
def on_quote_tick(self, tick: QuoteTick) -> void:
"""
"""
...
def on_reset(self) -> void:
"""
"""
...
def on_resume(self) -> void:
"""
Actions to be performed on resume.
恢复时执行的操作。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_save(self) -> dict:
"""
Actions to be performed when the actor state is saved.
保存 actor 状态时执行的操作。
Create and return a state dictionary of values to be saved.
创建并返回要保存的值的状态字典。
Returns: The strategy state dictionary.
返回值:策略状态字典。
Return type: dict[str, bytes]
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def on_start(self) -> void:
"""
"""
...
def on_stop(self) -> void:
"""
"""
...
def on_trade_tick(self, tick: TradeTick) -> void:
"""
"""
...
def pending_requests(self) -> set:
"""
Return the request IDs which are currently pending processing.
返回当前正在等待处理的请求 ID。
Return type: set[UUID4]
"""
...
def publish_data(self, data_type: DataType, data: Data) -> void:
"""
Publish the given data to the message bus.
将给定的数据发布到消息总线。
Parameters:
参数:
data_type (DataType) – The data type being published.
data_type (DataType) - 正在发布的数据类型。
data (Data) – The data to publish.
data (Data) - 要发布的数据。
"""
...
def publish_signal(self, name: str, value, ts_event: int=0) -> void:
"""
Publish the given value as a signal to the message bus.
将给定的值作为信号发布到消息总线。
Parameters:
参数:
name (str) – The name of the signal being published. The signal name is case-insensitive and will be capitalized (e.g., ‘example’ becomes ‘SignalExample’).
name (str) - 正在发布的信号的名称。信号名称不区分大小写,并且将大写(例如,“example”变为“SignalExample”)。
value (object) – The signal data to publish.
value (object) - 要发布的信号数据。
ts_event (uint64_t , optional) – UNIX timestamp (nanoseconds) when the signal event occurred. If None then will timestamp current time.
ts_event (uint64_t,可选) - 信号事件发生时的 UNIX 时间戳(纳秒)。如果为 None,则将使用当前时间作为时间戳。
"""
...
def queue_for_executor(self, func: Callable, args: tuple=None, kwargs: dict=None):
"""
Queues the callable func to be executed as fn(*args, **kwargs) sequentially.
将可调用函数 func 排队,以便按顺序执行为 fn(*args, **kwargs)。
Parameters:
参数:
func (Callable) – The function to be executed.
func (Callable) - 要执行的函数。
args (positional arguments) – The positional arguments for the call to func.
args(位置参数) - 对 func 的调用的位置参数。
kwargs (arbitrary keyword arguments) – The keyword arguments for the call to func.
kwargs(任意关键字参数) - 对 func 的调用的关键字参数。
Raises: TypeError – If func is not of type Callable.
引发:TypeError - 如果 func 的类型不是 Callable。
"""
...
def queued_task_ids(self) -> list:
"""
Return the queued task identifiers.
返回排队的 task 标识符。
Return type: list[TaskId]
"""
...
def register_base(self, portfolio: PortfolioFacade, msgbus: MessageBus, cache: CacheFacade, clock: Clock) -> void:
"""
Register with a trader.
向交易者注册。
Parameters:
参数:
portfolio (PortfolioFacade) – The read-only portfolio for the actor.
portfolio (PortfolioFacade) - actor 的只读投资组合。
msgbus (MessageBus) – The message bus for the actor.
msgbus (MessageBus) - actor 的消息总线。
cache (CacheFacade) – The read-only cache for the actor.
cache (CacheFacade) - actor 的只读缓存。
clock (Clock) – The clock for the actor.
clock (Clock) - actor 的时钟。
Warning:
System method (not intended to be called by user code).
系统方法(不打算由用户代码调用)。
"""
...
def register_executor(self, loop, executor: Executor) -> void:
"""
Register the given Executor for the actor.
为 actor 注册给定的 Executor。
Parameters:
参数:
loop (asyncio.AsbtractEventLoop) – The event loop of the application.
loop (asyncio.AsbtractEventLoop) - 应用程序的事件循环。
executor (concurrent.futures.Executor) – The executor to register.
executor (concurrent.futures.Executor) - 要注册的执行器。
Raises: TypeError – If executor is not of type concurrent.futures.Executor
引发:TypeError - 如果 executor 的类型不是 concurrent.futures.Executor。
"""
...
def register_indicator_for_bars(self, bar_type: BarType, indicator: Indicator) -> void:
"""
Register the given indicator with the actor/strategy to receive bar data for the given bar type.
向 actor/strategy 注册给定的指标,以便接收给定 bar 类型的 bar 数据。
Parameters:
参数:
bar_type (BarType) – The bar type for bar updates.
bar_type (BarType) - bar 更新的 bar 类型。
indicator (Indicator) – The indicator to register.
indicator (Indicator) - 要注册的指标。
"""
...
def register_indicator_for_quote_ticks(self, instrument_id: InstrumentId, indicator: Indicator) -> void:
"""
Register the given indicator with the actor/strategy to receive quote tick data for the given instrument ID.
向 actor/strategy 注册给定的指标,以便接收给定金融工具 ID 的报价 tick 数据。
Parameters:
参数:
instrument_id (InstrumentId) – The instrument ID for tick updates.
instrument_id (InstrumentId) - tick 更新的金融工具 ID。
indicator (Indicator) – The indicator to register.
indicator (Indicator) - 要注册的指标。
"""
...
def register_indicator_for_trade_ticks(self, instrument_id: InstrumentId, indicator) -> void:
"""
Register the given indicator with the actor/strategy to receive trade tick data for the given instrument ID.
向 actor/strategy 注册给定的指标,以便接收给定金融工具 ID 的交易 tick 数据。
Parameters:
参数:
instrument_id (InstrumentId) – The instrument ID for tick updates.
instrument_id (InstrumentId) - tick 更新的金融工具 ID。
indicator (indicator) – The indicator to register.
indicator (indicator) - 要注册的指标。
"""
...
def register_warning_event(self, event) -> void:
"""
Register the given event type for warning log levels.
为警告日志级别注册给定的事件类型。
Parameters: event (type) – The event class to register.
参数:event (type) - 要注册的事件类。
"""
...
def request_bars(self, bar_type: BarType, start: datetime=None, end: datetime=None, client_id: ClientId=None, callback=None) -> UUID4:
"""
Request historical Bar data.
请求历史 Bar 数据。
If end is None then will request up to the most recent data.
如果 end 为 None,则将请求最多到最新数据。
Parameters:
参数:
bar_type (BarType) – The bar type for the request.
bar_type (BarType) - 请求的 bar 类型。
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.
```python
end (datetime,可选) - 请求时间范围的结束日期时间(UTC)。包含性取决于各个数据客户端的实现。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
callback (Callable [ [UUID4 ] , None ] , optional) – The registered callback, to be called with the request ID when the response has completed processing.
callback (Callable [ [UUID4 ] , None ],可选) - 注册的回调函数,当响应完成处理时,将使用请求 ID 调用该回调函数。
Returns: The request_id for the request.
返回值:请求的 request_id。
Return type: UUID4
Raises:
引发:
ValueError – If start and end are not None and start is >= end.
ValueError - 如果 start 和 end 不为 None 并且 start >= end。
TypeError – If callback is not None and not of type Callable.
TypeError - 如果 callback 不为 None 并且类型不是 Callable。
"""
...
def request_data(self, data_type: DataType, client_id: ClientId, callback=None) -> UUID4:
"""
Request custom data for the given data type from the given data client.
从给定的数据客户端请求给定数据类型的自定义数据。
Parameters:
参数:
data_type (DataType) – The data type for the request.
data_type (DataType) - 请求的数据类型。
client_id (ClientId) – The data client ID.
client_id (ClientId) - 数据客户端 ID。
callback (Callable [ [UUID4 ] , None ] , optional) – The registered callback, to be called with the request ID when the response has completed processing.
callback (Callable [ [UUID4 ] , None ],可选) - 注册的回调函数,当响应完成处理时,将使用请求 ID 调用该回调函数。
Returns: The request_id for the request.
返回值:请求的 request_id。
Return type: UUID4
Raises: TypeError – If callback is not None and not of type Callable.
引发:TypeError - 如果 callback 不为 None 并且类型不是 Callable。
"""
...
def request_instrument(self, instrument_id: InstrumentId, start: datetime=None, end: datetime=None, client_id: ClientId=None, callback=None) -> UUID4:
"""
Request Instrument data for the given instrument ID.
请求给定金融工具 ID 的金融工具数据。
If end is None then will request up to the most recent data.
如果 end 为 None,则将请求最多到最新数据。
Parameters:
参数:
instrument_id (InstrumentId) – The instrument ID for the request.
instrument_id (InstrumentId) - 请求的金融工具 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)。包含性取决于各个数据客户端的实现。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
callback (Callable [ [UUID4 ] , None ] , optional) – The registered callback, to be called with the request ID when the response has completed processing.
callback (Callable [ [UUID4 ] , None ],可选) - 注册的回调函数,当响应完成处理时,将使用请求 ID 调用该回调函数。
Returns: The request_id for the request.
返回值:请求的 request_id。
Return type: UUID4
Raises:
引发:
ValueError – If start and end are not None and start is >= end.
ValueError - 如果 start 和 end 不为 None 并且 start >= end。
TypeError – If callback is not None and not of type Callable.
TypeError - 如果 callback 不为 None 并且类型不是 Callable。
"""
...
def request_instruments(self, venue: Venue, start: datetime=None, end: datetime=None, client_id: ClientId=None, callback=None) -> UUID4:
"""
Request all Instrument data for the given venue.
请求给定场所的所有金融工具数据。
If end is None then will request up to the most recent data.
如果 end 为 None,则将请求最多到最新数据。
Parameters:
参数:
venue (Venue) – The venue for the request.
venue (Venue) - 请求的场所。
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)。包含性取决于各个数据客户端的实现。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
callback (Callable [ [UUID4 ] , None ] , optional) – The registered callback, to be called with the request ID when the response has completed processing.
callback (Callable [ [UUID4 ] , None ],可选) - 注册的回调函数,当响应完成处理时,将使用请求 ID 调用该回调函数。
Returns: The request_id for the request.
返回值:请求的 request_id。
Return type: UUID4
Raises:
引发:
ValueError – If start and end are not None and start is >= end.
ValueError - 如果 start 和 end 不为 None 并且 start >= end。
TypeError – If callback is not None and not of type Callable.
TypeError - 如果 callback 不为 None 并且类型不是 Callable。
"""
...
def request_order_book_snapshot(self, instrument_id: InstrumentId, limit: int, client_id: ClientId=None, callback=None) -> UUID4:
"""
Request an order book snapshot.
请求订单簿快照。
Parameters:
参数:
instrument_id (InstrumentId) – The instrument ID for the order book snapshot request.
instrument_id (InstrumentId) - 订单簿快照请求的金融工具 ID。
limit (int , optional) – The limit on the depth of the order book snapshot (default is None).
limit (int,可选) - 订单簿快照深度的限制(默认为 None)。
client_id (ClientId , optional) – The specific client ID for the command. If None, it will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
callback (Callable [ [UUID4 ] , None ] , optional) – The registered callback, to be called with the request ID when the response has completed processing.
callback (Callable [ [UUID4 ] , None ],可选) - 注册的回调函数,当响应完成处理时,将使用请求 ID 调用该回调函数。
Returns: The request_id for the request.
返回值:请求的 request_id。
Return type: UUID4
Raises:
引发:
ValueError – If the instrument_id is None.
ValueError - 如果 instrument_id 为 None。
TypeError – If callback is not None and not of type Callable.
TypeError - 如果 callback 不为 None 并且类型不是 Callable。
"""
...
def request_quote_ticks(self, instrument_id: InstrumentId, start: datetime=None, end: datetime=None, client_id: ClientId=None, callback=None) -> UUID4:
"""
Request historical QuoteTick data.
请求历史报价 Tick 数据。
If end is None then will request up to the most recent data.
如果 end 为 None,则将请求最多到最新数据。
Parameters:
参数:
instrument_id (InstrumentId) – The tick instrument ID for the request.
instrument_id (InstrumentId) - 请求的 tick 金融工具 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)。包含性取决于各个数据客户端的实现。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
callback (Callable [ [UUID4 ] , None ] , optional) – The registered callback, to be called with the request ID when the response has completed processing.
callback (Callable [ [UUID4 ] , None ],可选) - 注册的回调函数,当响应完成处理时,将使用请求 ID 调用该回调函数。
Returns: The request_id for the request.
返回值:请求的 request_id。
Return type: UUID4
Raises:
引发:
ValueError – If start and end are not None and start is >= end.
ValueError - 如果 start 和 end 不为 None 并且 start >= end。
TypeError – If callback is not None and not of type Callable.
TypeError - 如果 callback 不为 None 并且类型不是 Callable。
"""
...
def request_trade_ticks(self, instrument_id: InstrumentId, start: datetime=None, end: datetime=None, client_id: ClientId=None, callback=None) -> UUID4:
"""
Request historical TradeTick data.
请求历史交易 Tick 数据。
If end is None then will request up to the most recent data.
如果 end 为 None,则将请求最多到最新数据。
Parameters:
参数:
instrument_id (InstrumentId) – The tick instrument ID for the request.
instrument_id (InstrumentId) - 请求的 tick 金融工具 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)。包含性取决于各个数据客户端的实现。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
callback (Callable [ [UUID4 ] , None ] , optional) – The registered callback, to be called with the request ID when the response has completed processing.
callback (Callable [ [UUID4 ] , None ],可选) - 注册的回调函数,当响应完成处理时,将使用请求 ID 调用该回调函数。
Returns: The request_id for the request.
返回值:请求的 request_id。
Return type: UUID4
Raises:
引发:
ValueError – If start and end are not None and start is >= end.
ValueError - 如果 start 和 end 不为 None 并且 start >= end。
TypeError – If callback is not None and not of type Callable.
TypeError - 如果 callback 不为 None 并且类型不是 Callable。
"""
...
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 run_in_executor(self, func: Callable, args: tuple=None, kwargs: dict=None):
"""
Schedules the callable func to be executed as fn(*args, **kwargs).
计划可调用函数 func 以 fn(*args, **kwargs) 的形式执行。
Parameters:
参数:
func (Callable) – The function to be executed.
func (Callable) - 要执行的函数。
args (positional arguments) – The positional arguments for the call to func.
args(位置参数) - 对 func 的调用的位置参数。
kwargs (arbitrary keyword arguments) – The keyword arguments for the call to func.
kwargs(任意关键字参数) - 对 func 的调用的关键字参数。
Returns: The unique task identifier for the execution. This also corresponds to any future objects memory address.
返回值:执行的唯一 task 标识符。这也对应于任何 future 对象的内存地址。
Return type: TaskId
Raises: TypeError – If func is not of type Callable.
引发:TypeError - 如果 func 的类型不是 Callable。
"""
...
def save(self) -> dict:
"""
Return the actor/strategy state dictionary to be saved.
返回要保存的 actor/strategy 状态字典。
Calls on_save.
调用 on_save。
Raises: RuntimeError – If actor/strategy is not registered with a trader.
引发:RuntimeError - 如果 actor/strategy 未在交易者处注册。
Warning:
Exceptions raised will be caught, logged, and reraised.
引发的异常将被捕获、记录并重新引发。
"""
...
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 unsubscribe_bars(self, bar_type: BarType, client_id: ClientId=None) -> void:
"""
Unsubscribe from streaming Bar data for the given bar type.
取消订阅给定 bar 类型的流式 Bar 数据。
Parameters:
参数:
bar_type (BarType) – The bar type to unsubscribe from.
bar_type (BarType) - 要取消订阅的 bar 类型。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
"""
...
def unsubscribe_data(self, data_type: DataType, client_id: ClientId=None) -> void:
"""
Unsubscribe from data of the given data type.
取消订阅给定数据类型的数据。
Parameters:
参数:
data_type (DataType) – The data type to unsubscribe from.
data_type (DataType) - 要取消订阅的数据类型。
client_id (ClientId , optional) – The data client ID. If supplied then an Unsubscribe command will be sent to the data client.
client_id (ClientId,可选) - 数据客户端 ID。如果提供,则将向数据客户端发送 Unsubscribe 命令。
"""
...
def unsubscribe_instrument(self, instrument_id: InstrumentId, client_id: ClientId=None) -> void:
"""
Unsubscribe from update Instrument data for the given instrument ID.
取消订阅给定金融工具 ID 的更新金融工具数据。
Parameters:
参数:
instrument_id (InstrumentId) – The instrument to unsubscribe from.
instrument_id (InstrumentId) - 要取消订阅的金融工具。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
"""
...
def unsubscribe_instrument_status(self, instrument_id: InstrumentId, client_id: ClientId=None) -> void:
"""
Unsubscribe to status updates of the given venue.
取消订阅给定场所的状态更新。
Parameters:
参数:
instrument_id (InstrumentId) – The instrument to unsubscribe to status updates for.
instrument_id (InstrumentId) - 要取消订阅状态更新的金融工具。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从场所推断出来。
"""
...
def unsubscribe_instruments(self, venue: Venue, client_id: ClientId=None) -> void:
"""
Unsubscribe from update Instrument data for the given venue.
取消订阅给定场所的更新金融工具数据。
Parameters:
参数:
venue (Venue) – The venue for the subscription.
venue (Venue) - 订阅的场所。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从场所推断出来。
"""
...
def unsubscribe_order_book_at_interval(self, instrument_id: InstrumentId, interval_ms: int=1000, client_id: ClientId=None) -> void:
"""
Unsubscribe from an OrderBook at a specified interval for the given instrument ID.
以指定的间隔取消订阅给定金融工具 ID 的订单簿。
The interval must match the previously subscribed interval.
间隔必须与之前订阅的间隔匹配。
Parameters:
参数:
instrument_id (InstrumentId) – The order book instrument to subscribe to.
instrument_id (InstrumentId) - 要订阅的订单簿金融工具。
interval_ms (int) – The order book snapshot interval in milliseconds.
interval_ms (int) - 订单簿快照间隔(以毫秒为单位)。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
"""
...
def unsubscribe_order_book_deltas(self, instrument_id: InstrumentId, client_id: ClientId=None) -> void:
"""
Unsubscribe the order book deltas stream for the given instrument ID.
取消订阅给定金融工具 ID 的订单簿增量流。
Parameters:
参数:
instrument_id (InstrumentId) – The order book instrument to subscribe to.
instrument_id (InstrumentId) - 要订阅的订单簿金融工具。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
"""
...
def unsubscribe_quote_ticks(self, instrument_id: InstrumentId, client_id: ClientId=None) -> void:
"""
Unsubscribe from streaming QuoteTick data for the given instrument ID.
取消订阅给定金融工具 ID 的流式报价 Tick 数据。
Parameters:
参数:
instrument_id (InstrumentId) – The tick instrument to unsubscribe from.
instrument_id (InstrumentId) - 要取消订阅的 tick 金融工具。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
"""
...
def unsubscribe_trade_ticks(self, instrument_id: InstrumentId, client_id: ClientId=None) -> void:
"""
Unsubscribe from streaming TradeTick data for the given instrument ID.
取消订阅给定金融工具 ID 的流式交易 Tick 数据。
Parameters:
参数:
instrument_id (InstrumentId) – The tick instrument ID to unsubscribe from.
instrument_id (InstrumentId) - 要取消订阅的 tick 金融工具 ID。
client_id (ClientId , optional) – The specific client ID for the command. If None then will be inferred from the venue in the instrument ID.
client_id (ClientId,可选) - 命令的特定客户端 ID。如果为 None,则将从金融工具 ID 中的场所推断出来。
"""
...
def update_synthetic(self, synthetic: SyntheticInstrument) -> void:
"""
Update the synthetic instrument in the cache.
更新缓存中的合成金融工具。
Parameters: synthetic (SyntheticInstrument) – The synthetic instrument to update in the cache.
参数:synthetic (SyntheticInstrument) - 要在缓存中更新的合成金融工具。
Raises: KeyError – If synthetic does not already exist in the cache.
引发:KeyError - 如果合成金融工具在缓存中不存在。
"""
...
The ExecutionEngine is the central component of the entire execution stack.
ExecutionEngine 是整个执行堆栈的核心组件。
The execution engines primary responsibility is to orchestrate interactions between the ExecutionClient instances, and the rest of the platform. This includes sending commands to, and receiving events from, the trading venue endpoints via its registered execution clients.
执行引擎的主要职责是协调执行客户端实例与平台其余部分之间的交互。这包括通过其注册的执行客户端向交易场所端点发送命令以及从交易场所端点接收事件。
The engine employs a simple fan-in fan-out messaging pattern to execute TradingCommand messages, and process AccountState or OrderEvent type messages.
引擎采用简单的扇入扇出消息传递模式来执行 TradingCommand 消息,并处理 AccountState 或 OrderEvent 类型消息。
Alternative implementations can be written on top of the generic engine - which just need to override the execute and process methods.
可以在通用引擎之上编写替代实现 - 只需要覆盖 execute 和 process 方法。
class ExecutionEngine 执行引擎
Bases: Component
class ExecutionEngine(Component):
"""
Provides a high-performance execution engine for the management of many ExecutionClient instances, and the asynchronous ingest and distribution of trading commands and events.
提供高性能执行引擎,用于管理许多 ExecutionClient 实例,以及异步提取和分发交易命令和事件。
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 (ExecEngineConfig , optional) – The configuration for the instance.
config (ExecEngineConfig,可选) - 实例的配置。
Raises: TypeError – If config is not of type ExecEngineConfig.
引发:TypeError - 如果 config 的类型不是 ExecEngineConfig。
"""
def __init__(self, msgbus: MessageBus, cache: Cache, clock: Clock, config: ExecEngineConfig | None = None) -> None:
...
Properties 属性
@property
def command_count(self):
"""
The total count of commands 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 execution client registered with the engine.
返回在引擎中注册的默认执行客户端。
Return type: ClientId or None
Type: ExecutionEngine.default_client
"""
...
@property
def event_count(self):
"""
The total count of events received by the engine.
引擎收到的事件总数。
Returns:
int
"""
...
@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 reconciliation(self) -> bool:
"""
bool
Return whether the reconciliation process will be run on start.
返回是否将在启动时运行对账进程。
Return type: bool
Type: ExecutionEngine.reconciliation
"""
...
@property
def registered_clients(self) -> list[ClientId]:
"""
list[ClientId]
Return the execution clients registered with the engine.
返回在引擎中注册的执行客户端。
Return type: list[ClientId]
Type: ExecutionEngine.registered_clients
"""
...
@property
def report_count(self) -> 'int':
"""
'int' The total count of reports received by the engine.
'int' 引擎接收到的报告总数。
Returns:
int
Type: report_count
"""
...
@property
def snapshot_orders(self):
"""
If order state snapshots should be persisted.
是否应持久化订单状态快照。
Returns:
bool
"""
...
@property
def snapshot_positions(self):
"""
If position state snapshots should be persisted.
是否应持久化持仓状态快照。
Returns:
bool
"""
...
@property
def snapshot_positions_interval_secs(self):
"""
The interval (seconds) at which additional position state snapshots are persisted.
持久化其他持仓状态快照的间隔(秒)。
Returns:
double
"""
...
@property
def snapshot_positions_timer_name(self):
"""
"""
...
@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
"""
...
Methods 方法
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 check_integrity(self) -> bool:
"""
Check integrity of data within the cache and clients.
检查缓存和客户端中数据的完整性。
Returns: True if checks pass, else False.
返回值:如果检查通过,则返回 True,否则返回 False。
Return type: bool
"""
...
def check_residuals(self) -> bool:
"""
Check for any residual open state and log warnings if found.
检查是否有任何剩余的打开状态,如果找到,则记录警告。
‘Open state’ is considered to be open orders and open positions.
“打开状态”被认为是打开的订单和打开的持仓。
Returns: True if residuals exist, else False.
返回值:如果存在剩余状态,则返回 True,否则返回 False。
Return type: bool
"""
...
def connect(self) -> None:
"""
Connect the engine by calling connect on all registered clients.
通过对所有注册的客户端调用 connect 来连接引擎。
"""
...
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: ExecutionClient) -> void:
"""
Deregister the given execution client from the execution engine.
从执行引擎中取消注册给定的执行客户端。
Parameters: client (ExecutionClient) – The execution client to deregister.
参数:client (ExecutionClient) - 要取消注册的执行客户端。
Raises: ValueError – If client is not registered with the execution engine.
引发:ValueError - 如果客户端未在执行引擎中注册。
"""
...
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: TradingCommand) -> void:
"""
Execute the given command.
执行给定的命令。
Parameters: command (TradingCommand) – The command to execute.
参数:command (TradingCommand) - 要执行的命令。
"""
...
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.
```python
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.
如果组件未处于可执行此方法的有效状态,则组件状态将不会更改,并且将记录错误。
"""
...
def flush_db(self) -> void:
"""
Flush the execution database which permanently removes all persisted data.
刷新执行数据库,永久删除所有持久化数据。
WARNING
永久性数据丢失。
"""
...
@classmethod
def fully_qualified_name(cls) -> str:
"""
Return the fully qualified name for the components class.
返回组件类的完全限定名称。
Return type: str
"""
...
def get_external_order_claim(self, instrument_id: InstrumentId):
"""
Get any external order claim for the given instrument ID.
获取给定金融工具 ID 的任何外部订单认领。
Parameters: instrument_id (InstrumentId) – The instrument ID for the claim.
参数:instrument_id (InstrumentId) - 认领的金融工具 ID。
Return type: StrategyId or None
"""
...
def get_external_order_claims_instruments(self) -> set:
"""
Get all external order claims instrument IDs.
获取所有外部订单认领金融工具 ID。
Return type: set[InstrumentId]
"""
...
def load_cache(self) -> void:
"""
Load the cache up from the execution database.
从执行数据库加载缓存。
"""
...
def position_id_count(self, strategy_id: StrategyId) -> int:
"""
The position ID count for the given strategy ID.
给定策略 ID 的持仓 ID 计数。
Parameters: strategy_id (StrategyId) – The strategy ID for the position count.
参数:strategy_id (StrategyId) - 持仓计数的策略 ID。
Return type: int
"""
...
def process(self, event: OrderEvent) -> void:
"""
Process the given order event.
处理给定的订单事件。
Parameters: event (OrderEvent) – The order event to process.
参数:event (OrderEvent) - 要处理的订单事件。
"""
...
def reconcile_mass_status(self, report: ExecutionMassStatus) -> None:
"""
Reconcile the given execution mass status report.
协调给定的执行批量状态报告。
Parameters: report (ExecutionMassStatus) – The execution mass status report to reconcile.
参数:report (ExecutionMassStatus) - 要协调的执行批量状态报告。
"""
...
def reconcile_report(self, report: ExecutionReport) -> bool:
"""
Check the given execution report.
检查给定的执行报告。
Parameters: report (ExecutionReport) – The execution report to check.
参数:report (ExecutionReport) - 要检查的执行报告。
Returns: True if reconciliation successful, else False.
返回值:如果协调成功,则返回 True,否则返回 False。
Return type: bool
"""
...
async def reconcile_state(self, timeout_secs: float = 10.0) -> bool:
"""
Reconcile the internal execution state with all execution clients (external state).
将内部执行状态与所有执行客户端(外部状态)协调起来。
Parameters: timeout_secs (double , default 10.0) – The timeout (seconds) for reconciliation to complete.
参数:timeout_secs (double,默认 10.0) - 协调完成的超时时间(秒)。
Returns: True if states reconcile within timeout, else False.
返回值:如果状态在超时时间内协调,则返回 True,否则返回 False。
Return type: bool
Raises: ValueError – If timeout_secs is not positive (> 0).
引发:ValueError - 如果 timeout_secs 不是正数 (> 0)。
"""
...
def register_client(self, client: ExecutionClient) -> void:
"""
Register the given execution client with the execution engine.
将给定的执行客户端注册到执行引擎。
If the client.venue is None and a default routing client has not been previously registered then will be registered as such.
如果 client.venue 为 None 并且之前没有注册默认路由客户端,则将注册为默认路由客户端。
Parameters: client (ExecutionClient) – The execution client to register.
参数:client (ExecutionClient) - 要注册的执行客户端。
Raises: ValueError – If client is already registered with the execution engine.
引发:ValueError - 如果客户端已在执行引擎中注册。
"""
...
def register_default_client(self, client: ExecutionClient) -> 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 (ExecutionClient) – The client to register.
参数:client (ExecutionClient) - 要注册的客户端。
"""
...
def register_external_order_claims(self, strategy: Strategy) -> void:
"""
Register the given strategies external order claim instrument IDs (if any)
注册给定策略的外部订单认领金融工具 ID(如果有)。
Parameters: strategy (Strategy) – The strategy for the registration.
参数:strategy (Strategy) - 要注册的策略。
Raises: InvalidConfiguration – If a strategy is already registered to claim external orders for an instrument ID.
引发:InvalidConfiguration - 如果策略已注册以认领金融工具 ID 的外部订单。
"""
...
def register_oms_type(self, strategy: Strategy) -> void:
"""
Register the given trading strategies OMS (Order Management System) type.
注册给定交易策略的 OMS(订单管理系统)类型。
Parameters: strategy (Strategy) – The strategy for the registration.
参数:strategy (Strategy) - 要注册的策略。
"""
...
def register_venue_routing(self, client: ExecutionClient, venue: Venue) -> void:
"""
Register the given client to route orders 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 orders to.
venue (Venue) - 要将订单路由到的场所。
client (ExecutionClient) – The client for the venue routing.
client (ExecutionClient) - 用于场所路由的客户端。
"""
...
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 stop_clients(self) -> void:
"""
Stop the registered clients.
停止注册的客户端。
"""
...
Messages 消息
class BatchCancelOrders 批量取消订单
Bases: TradingCommand
class BatchCancelOrders(TradingCommand):
"""
Represents a command to batch cancel orders working on a venue for an instrument.
表示批量取消对金融工具在场所工作的订单的命令。
Parameters:
参数:
trader_id (TraderId) – The trader ID for the command.
trader_id (TraderId) - 命令的交易者 ID。
strategy_id (StrategyId) – The strategy ID for the command.
strategy_id (StrategyId) - 命令的策略 ID。
instrument_id (InstrumentId) – The instrument ID for the command.
instrument_id (InstrumentId) - 命令的金融工具 ID。
cancels (list [CancelOrder ]) – The inner list of cancel order commands.
cancels (list [CancelOrder ]) - 取消订单命令的内部列表。
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 时间戳(纳秒)。
client_id (ClientId , optional) – The execution client ID for the command.
client_id (ClientId,可选) - 命令的执行客户端 ID。
Raises:
引发:
ValueError – If cancels is empty.
ValueError - 如果 cancels 为空。
ValueError – If cancels contains a type other than CancelOrder.
ValueError - 如果 cancels 包含 CancelOrder 以外的类型。
"""
def __init__(self, trader_id: TraderId, strategy_id: StrategyId, instrument_id: InstrumentId, cancels: list, command_id: UUID4, ts_init: int, client_id: ClientId = None):
...
Properties 属性
@property
def cancels(self):
"""
"""
...
@property
def client_id(self):
"""
The execution client ID for the command.
命令的执行客户端 ID。
Returns:
ClientId or None
"""
...
@property
def id(self) -> UUID4:
"""
The command message ID.
命令消息 ID。
Returns:
UUID4
"""
...
@property
def instrument_id(self) -> InstrumentId:
"""
The instrument ID associated with the command.
与命令关联的金融工具 ID。
Returns:
InstrumentId
"""
...
@property
def strategy_id(self) -> StrategyId:
"""
The strategy ID associated with the command.
与命令关联的策略 ID。
Returns:
StrategyId
"""
...
@property
def trader_id(self) -> TraderId:
"""
The trader ID associated with the command.
与命令关联的交易者 ID。
Returns:
TraderId
"""
...
@property
def ts_init(self) -> int:
"""
UNIX timestamp (nanoseconds) when the object was initialized.
对象初始化时的 UNIX 时间戳(纳秒)。
Returns:
uint64_t
"""
...
Methods 方法
@staticmethod
def from_dict(values: dict):
"""
Return a batch cancel order command from the given dict values.
从给定的 dict 值返回批量取消订单命令。
Parameters: values (dict *[*str , object ]) – The values for initialization.
参数:values (dict *[*str,object]) - 初始化的值。
Return type: BatchCancelOrders
"""
...
@staticmethod
def to_dict(obj: 'BatchCancelOrders'):
"""
Return a dictionary representation of this object.
返回此对象的字典表示形式。
Return type: dict[str, object]
"""
...
class CancelAllOrders 取消所有订单
Bases: TradingCommand
class CancelAllOrders(TradingCommand):
"""
Represents a command to cancel all orders for an instrument.
表示取消金融工具的所有订单的命令。
Parameters:
参数:
trader_id (TraderId) – The trader ID for the command.
trader_id (TraderId) - 命令的交易者 ID。
strategy_id (StrategyId) – The strategy ID for the command.
strategy_id (StrategyId) - 命令的策略 ID。
instrument_id (InstrumentId) – The instrument ID for the command.
instrument_id (InstrumentId) - 命令的金融工具 ID。
order_side (OrderSide) – The order side for the command.
order_side (OrderSide) - 命令的订单方向。
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 时间戳(纳秒)。
client_id (ClientId , optional) – The execution client ID for the command.
client_id (ClientId,可选) - 命令的执行客户端 ID。
"""
def __init__(self, trader_id: TraderId, strategy_id: StrategyId, instrument_id: InstrumentId, order_side: OrderSide, command_id: UUID4, ts_init: int, client_id: ClientId = None):
...
Properties 属性
@property
def client_id(self):
"""
The execution client ID for the command.
命令的执行客户端 ID。
Returns:
ClientId or None
"""
...
@property
def id(self) -> UUID4:
"""
The command message ID.
命令消息 ID。
Returns:
UUID4
"""
...
@property
def instrument_id(self) -> InstrumentId:
"""
The instrument ID associated with the command.
与命令关联的金融工具 ID。
Returns:
InstrumentId
"""
...
@property
def order_side(self) -> OrderSide:
"""
The order side for the command.
命令的订单方向。
Returns:
OrderSide
"""
...
@property
def strategy_id(self) -> StrategyId:
"""
The strategy ID associated with the command.
与命令关联的策略 ID。
Returns:
StrategyId
"""
...
@property
def trader_id(self) -> TraderId:
"""
The trader ID associated with the command.
与命令关联的交易者 ID。
Returns:
TraderId
"""
...
@property
def ts_init(self) -> int:
"""
UNIX timestamp (nanoseconds) when the object was initialized.
对象初始化时的 UNIX 时间戳(纳秒)。
Returns:
uint64_t
"""
...
Methods 方法
@staticmethod
def from_dict(values: dict):
"""
Return a cancel order command from the given dict values.
从给定的 dict 值返回取消订单命令。
Parameters: values (dict *[*str , object ]) – The values for initialization.
参数:values (dict *[*str,object]) - 初始化的值。
Return type: CancelAllOrders
"""
...
@staticmethod
def to_dict(obj: 'CancelAllOrders'):
"""
Return a dictionary representation of this object.
返回此对象的字典表示形式。
Return type: dict[str, object]
"""
...
class CancelOrder 取消订单
Bases: TradingCommand
class CancelOrder(TradingCommand):
"""
Represents a command to cancel an order.
表示取消订单的命令。
Parameters:
参数:
trader_id (TraderId) – The trader ID for the command.
trader_id (TraderId) - 命令的交易者 ID。
strategy_id (StrategyId) – The strategy ID for the command.
strategy_id (StrategyId) - 命令的策略 ID。
instrument_id (InstrumentId) – The instrument ID for the command.
instrument_id (InstrumentId) - 命令的金融工具 ID。
client_order_id (ClientOrderId) – The client order ID to cancel.
client_order_id (ClientOrderId) - 要取消的客户端订单 ID。
venue_order_id (VenueOrderId, optional with no default so None must be passed explicitly) – The venue order ID (assigned by the venue) to cancel.
venue_order_id (VenueOrderId,可选,没有默认值,因此必须显式传递 None) - 要取消的场所订单 ID(由场所分配)。
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 时间戳(纳秒)。
client_id (ClientId , optional) – The execution client ID for the command.
client_id (ClientId,可选) - 命令的执行客户端 ID。
"""
def __init__(self, trader_id: TraderId, strategy_id: StrategyId, instrument_id: InstrumentId, client_order_id: ClientOrderId, venue_order_id: VenueOrderId | None, command_id: UUID4, ts_init: int, client_id: ClientId = None):
...
Properties 属性
@property
def client_id(self):
"""
The execution client ID for the command.
命令的执行客户端 ID。
Returns:
ClientId or None
"""
...
@property
def client_order_id(self) -> ClientOrderId:
"""
The client order ID associated with the command.
与命令关联的客户端订单 ID。
Returns:
ClientOrderId
"""
...
@property
def id(self) -> UUID4:
"""
The command message ID.
命令消息 ID。
Returns:
UUID4
"""
...
@property
def instrument_id(self) -> InstrumentId:
"""
The instrument ID associated with the command.
与命令关联的金融工具 ID。
Returns:
InstrumentId
"""
...
@property
def strategy_id(self) -> StrategyId:
"""
The strategy ID associated with the command.
与命令关联的策略 ID。
Returns:
StrategyId
"""
...
@property
def trader_id(self) -> TraderId:
"""
The trader ID associated with the command.
与命令关联的交易者 ID。
Returns:
TraderId
"""
...
@property
def ts_init(self) -> int:
"""
UNIX timestamp (nanoseconds) when the object was initialized.
对象初始化时的 UNIX 时间戳(纳秒)。
Returns:
uint64_t
"""
...
@property
def venue_order_id(self):
"""
The venue order ID associated with the command.
与命令关联的场所订单 ID。
Returns:
VenueOrderId or None
"""
...
Methods 方法
@staticmethod
def from_dict(values: dict):
"""
Return a cancel order command from the given dict values.
从给定的 dict 值返回取消订单命令。
Parameters: values (dict *[*str , object ]) – The values for initialization.
参数:values (dict *[*str,object]) - 初始化的值。
Return type: CancelOrder
"""
...
@staticmethod
def to_dict(obj: 'CancelOrder'):
"""
Return a dictionary representation of this object.
返回此对象的字典表示形式。
Return type: dict[str, object]
"""
...
class ModifyOrder 修改订单
Bases: TradingCommand
class ModifyOrder(TradingCommand):
"""
Represents a command to modify the properties of an existing order.
表示修改现有订单属性的命令。
Parameters:
参数:
trader_id (TraderId) – The trader ID for the command.
trader_id (TraderId) - 命令的交易者 ID。
strategy_id (StrategyId) – The strategy ID for the command.
strategy_id (StrategyId) - 命令的策略 ID。
instrument_id (InstrumentId) – The instrument ID for the command.
instrument_id (InstrumentId) - 命令的金融工具 ID。
client_order_id (ClientOrderId) – The client order ID to update.
client_order_id (ClientOrderId) - 要更新的客户端订单 ID。
venue_order_id (VenueOrderId, optional with no default so None must be passed explicitly) – The venue order ID (assigned by the venue) to update.
venue_order_id (VenueOrderId,可选,没有默认值,因此必须显式传递 None) - 要更新的场所订单 ID(由场所分配)。
quantity (Quantity, optional with no default so None must be passed explicitly) – The quantity for the order update.
quantity (Quantity,可选,没有默认值,因此必须显式传递 None) - 订单更新的数量。
price (Price, optional with no default so None must be passed explicitly) – The price for the order update.
price (Price,可选,没有默认值,因此必须显式传递 None) - 订单更新的价格。
trigger_price (Price, optional with no default so None must be passed explicitly) – The trigger price for the order update.
trigger_price (Price,可选,没有默认值,因此必须显式传递 None) - 订单更新的触发价格。
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 时间戳(纳秒)。
client_id (ClientId , optional) – The execution client ID for the command.
client_id (ClientId,可选) - 命令的执行客户端 ID。
"""
def __init__(self, trader_id: TraderId, strategy_id: StrategyId, instrument_id: InstrumentId, client_order_id: ClientOrderId, venue_order_id: VenueOrderId | None, quantity: Quantity | None, price: Price | None, trigger_price: Price | None, command_id: UUID4, ts_init: int, client_id: ClientId = None):
...
Properties 属性
@property
def client_id(self):
"""
The execution client ID for the command.
命令的执行客户端 ID。
Returns:
ClientId or None
"""
...
@property
def client_order_id(self) -> ClientOrderId:
"""
The client order ID associated with the command.
与命令关联的客户端订单 ID。
Returns:
ClientOrderId
"""
...
@property
def id(self) -> UUID4:
"""
The command message ID.
命令消息 ID。
Returns:
UUID4
"""
...
@property
def instrument_id(self) -> InstrumentId:
"""
The instrument ID associated with the command.
与命令关联的金融工具 ID。
Returns:
InstrumentId
"""
...
@property
def price(self):
"""
The updated price for the command.
命令的更新价格。
Returns:
Price or None
"""
...
@property
def quantity(self):
"""
The updated quantity for the command.
命令的更新数量。
Returns:
Quantity or None
"""
...
@property
def strategy_id(self) -> StrategyId:
"""
The strategy ID associated with the command.
与命令关联的策略 ID。
Returns:
StrategyId
"""
...
@property
def trader_id(self) -> TraderId:
"""
The trader ID associated with the command.
与命令关联的交易者 ID。
Returns:
TraderId
"""
...
@property
def trigger_price(self):
"""
The updated trigger price for the command.
命令的更新触发价格。
Returns:
Price or None
"""
...
@property
def ts_init(self) -> int:
"""
UNIX timestamp (nanoseconds) when the object was initialized.
对象初始化时的 UNIX 时间戳(纳秒)。
Returns:
uint64_t
"""
...
@property
def venue_order_id(self):
"""
The venue order ID associated with the command.
与命令关联的场所订单 ID。
Returns:
VenueOrderId or None
"""
...
Methods 方法
@staticmethod
def from_dict(values: dict):
"""
Return a modify order command from the given dict values.
从给定的 dict 值返回修改订单命令。
Parameters: values (dict *[*str , object ]) – The values for initialization.
参数:values (dict *[*str,object]) - 初始化的值。
Return type: ModifyOrder
"""
...
@staticmethod
def to_dict(obj: 'ModifyOrder'):
"""
Return a dictionary representation of this object.
返回此对象的字典表示形式。
Return type: dict[str, object]
"""
...
class QueryOrder 查询订单
Bases: TradingCommand
class QueryOrder(TradingCommand):
"""
Represents a command to query an order.
表示查询订单的命令。
Parameters:
参数:
trader_id (TraderId) – The trader ID for the command.
trader_id (TraderId) - 命令的交易者 ID。
strategy_id (StrategyId) – The strategy ID for the command.
strategy_id (StrategyId) - 命令的策略 ID。
instrument_id (InstrumentId) – The instrument ID for the command.
instrument_id (InstrumentId) - 命令的金融工具 ID。
client_order_id (ClientOrderId) – The client order ID for the order to query.
client_order_id (ClientOrderId) - 要查询的订单的客户端订单 ID。
venue_order_id (VenueOrderId, optional with no default so None must be passed explicitly) – The venue order ID (assigned by the venue) to query.
venue_order_id (VenueOrderId,可选,没有默认值,因此必须显式传递 None) - 要查询的场所订单 ID(由场所分配)。
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 时间戳(纳秒)。
client_id (ClientId , optional) – The execution client ID for the command.
client_id (ClientId,可选) - 命令的执行客户端 ID。
"""
def __init__(self, trader_id: TraderId, strategy_id: StrategyId, instrument_id: InstrumentId, client_order_id: ClientOrderId, venue_order_id: VenueOrderId | None, command_id: UUID4, ts_init: int, client_id: ClientId = None):
...
Properties 属性
@property
def client_id(self):
"""
The execution client ID for the command.
命令的执行客户端 ID。
Returns:
ClientId or None
"""
...
@property
def client_order_id(self) -> ClientOrderId:
"""
The client order ID for the order to query.
要查询的订单的客户端订单 ID。
Returns:
ClientOrderId
"""
...
@property
def id(self) -> UUID4:
"""
The command message ID.
命令消息 ID。
Returns:
UUID4
"""
...
@property
def instrument_id(self) -> InstrumentId:
"""
The instrument ID associated with the command.
与命令关联的金融工具 ID。
Returns:
InstrumentId
"""
...
@property
def strategy_id(self) -> StrategyId:
"""
The strategy ID associated with the command.
与命令关联的策略 ID。
Returns:
StrategyId
"""
...
@property
def trader_id(self) -> TraderId:
"""
The trader ID associated with the command.
与命令关联的交易者 ID。
Returns:
TraderId
"""
...
@property
def ts_init(self) -> int:
"""
UNIX timestamp (nanoseconds) when the object was initialized.
对象初始化时的 UNIX 时间戳(纳秒)。
Returns:
uint64_t
"""
...
@property
def venue_order_id(self):
"""
The venue order ID for the order to query.
要查询的订单的场所订单 ID。
Returns:
VenueOrderId or None
"""
...
Methods 方法
@staticmethod
def from_dict(values: dict):
"""
Return a query order command from the given dict values.
从给定的 dict 值返回查询订单命令。
Parameters: values (dict *[*str , object ]) – The values for initialization.
参数:values (dict *[*str,object]) - 初始化的值。
Return type: QueryOrder
"""
...
@staticmethod
def to_dict(obj: 'QueryOrder'):
"""
Return a dictionary representation of this object.
返回此对象的字典表示形式。
Return type: dict[str, object]
"""
...
class SubmitOrder 提交订单
Bases: TradingCommand
class SubmitOrder(TradingCommand):
"""
Represents a command to submit the given order.
表示提交给定订单的命令。
Parameters:
参数:
trader_id (TraderId) – The trader ID for the command.
trader_id (TraderId) - 命令的交易者 ID。
strategy_id (StrategyId) – The strategy ID for the command.
strategy_id (StrategyId) - 命令的策略 ID。
order (Order) – The order to submit.
order (Order) - 要提交的订单。
command_id (UUID4) – The commands ID.
command_id (UUID4) - 命令的 ID。
ts_init (uint64_t) – UNIX timestamp (nanoseconds) when the object was initialized.
ts_init (uint64_t) - 对象初始化时的 UNIX 时间戳(纳秒)。
position_id (PositionId , optional) – The position ID for the command.
position_id (PositionId,可选) - 命令的持仓 ID。
client_id (ClientId , optional) – The execution client ID for the command.
client_id (ClientId,可选) - 命令的执行客户端 ID。
"""
def __init__(self, trader_id: TraderId, strategy_id: StrategyId, order: Order, command_id: UUID4, ts_init: int, position_id: PositionId | None = None, client_id=None):
...
Properties 属性
@property
def client_id(self):
"""
The execution client ID for the command.
命令的执行客户端 ID。
Returns:
ClientId or None
"""
...
@property
def exec_algorithm_id(self):
"""
The execution algorithm ID for the order.
订单的执行算法 ID。
Returns:
ExecAlgorithmId or None
"""
...
@property
def id(self) -> UUID4:
"""
The command message ID.
命令消息 ID。
Returns:
UUID4
"""
...
@property
def instrument_id(self) -> InstrumentId:
"""
The instrument ID associated with the command.
与命令关联的金融工具 ID。
Returns:
InstrumentId
"""
...
@property
def order(self) -> Order:
"""
The order to submit.
要提交的订单。
Returns:
Order
"""
...
@property
def position_id(self):
"""
The position ID to associate with the order.
要与订单关联的持仓 ID。
Returns:
PositionId or None
"""
...
@property
def strategy_id(self) -> StrategyId:
"""
The strategy ID associated with the command.
与命令关联的策略 ID。
Returns:
StrategyId
"""
...
@property
def trader_id(self) -> TraderId:
"""
The trader ID associated with the command.
与命令关联的交易者 ID。
Returns:
TraderId
"""
...
@property
def ts_init(self) -> int:
"""
UNIX timestamp (nanoseconds) when the object was initialized.
对象初始化时的 UNIX 时间戳(纳秒)。
Returns:
uint64_t
"""
...
Methods 方法
@staticmethod
def from_dict(values: dict):
"""
Return a submit order command from the given dict values.
从给定的 dict 值返回提交订单命令。
Parameters: values (dict *[*str , object ]) – The values for initialization.
参数:values (dict *[*str,object]) - 初始化的值。
Return type: SubmitOrder
"""
...
@staticmethod
def to_dict(obj: 'SubmitOrder'):
"""
Return a dictionary representation of this object.
返回此对象的字典表示形式。
Return type: dict[str, object]
"""
...
class SubmitOrderList 提交订单列表
Bases: TradingCommand
class SubmitOrderList(TradingCommand):
"""
Represents a command to submit an order list consisting of an order batch/bulk of related parent-child contingent orders.
表示提交订单列表的命令,该列表由一批相关的父子意外事件订单组成。
This command can correspond to a NewOrderList message for the FIX protocol.
此命令可以对应于 FIX 协议的 NewOrderList 消息。
Parameters:
参数:
trader_id (TraderId) – The trader ID for the command.
trader_id (TraderId) - 命令的交易者 ID。
strategy_id (StrategyId) – The strategy ID for the command.
strategy_id (StrategyId) - 命令的策略 ID。
order_list (OrderList) – The order list to submit.
order_list (OrderList) - 要提交的订单列表。
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 时间戳(纳秒)。
position_id (PositionId , optional) – The position ID for the command.
position_id (PositionId,可选) - 命令的持仓 ID。
client_id (ClientId , optional) – The execution client ID for the command.
client_id (ClientId,可选) - 命令的执行客户端 ID。
"""
def __init__(self, trader_id: TraderId, strategy_id: StrategyId, order_list: OrderList, command_id: UUID4, ts_init: int, position_id: PositionId | None = None, client_id=None):
...
Properties 属性
@property
def client_id(self):
"""
The execution client ID for the command.
命令的执行客户端 ID。
Returns:
ClientId or None
"""
...
@property
def exec_algorithm_id(self):
"""
The execution algorithm ID for the order list.
订单列表的执行算法 ID。
Returns:
ExecAlgorithmId or None
"""
...
@property
def has_emulated_order(self):
"""
If the contained order_list holds at least one emulated order.
如果包含的 order_list 至少包含一个模拟订单。
Returns:
bool
"""
...
@property
def id(self) -> UUID4:
"""
The command message ID.
命令消息 ID。
Returns:
UUID4
"""
...
@property
def instrument_id(self) -> InstrumentId:
"""
The instrument ID associated with the command.
与命令关联的金融工具 ID。
Returns:
InstrumentId
"""
...
@property
def order_list(self) -> OrderList:
"""
The order list to submit.
要提交的订单列表。
Returns:
OrderList
"""
...
@property
def position_id(self):
"""
The position ID to associate with the orders.
要与订单关联的持仓 ID。
Returns:
PositionId or None
"""
...
@property
def strategy_id(self) -> StrategyId:
"""
The strategy ID associated with the command.
与命令关联的策略 ID。
Returns:
StrategyId
"""
...
@property
def trader_id(self) -> TraderId:
"""
The trader ID associated with the command.
与命令关联的交易者 ID。
Returns:
TraderId
"""
...
@property
def ts_init(self) -> int:
"""
UNIX timestamp (nanoseconds) when the object was initialized.
对象初始化时的 UNIX 时间戳(纳秒)。
Returns:
uint64_t
"""
...
Methods 方法
@staticmethod
def from_dict(values: dict):
"""
Return a submit order list command from the given dict values.
从给定的 dict 值返回提交订单列表命令。
Parameters: values (dict *[*str , object ]) – The values for initialization.
参数:values (dict *[*str,object]) - 初始化的值。
Return type: SubmitOrderList
"""
...
@staticmethod
def to_dict(obj: 'SubmitOrderList'):
"""
Return a dictionary representation of this object.
返回此对象的字典表示形式。
Return type: dict[str, object]
"""
...
Reports 报告
class ExecutionReport 执行报告
Bases: Document
class ExecutionReport(Document):
"""
The base class for all execution reports.
所有执行报告的基类。
"""
def __init__(self):
...
Properties 属性
@property
def id(self) -> UUID4:
"""
The document message ID.
文档消息 ID。
Returns:
UUID4
"""
...
@property
def ts_init(self) -> int:
"""
UNIX timestamp (nanoseconds) when the object was initialized.
对象初始化时的 UNIX 时间戳(纳秒)。
Returns:
uint64_t
"""
...
class OrderStatusReport 订单状态报告
Bases: ExecutionReport
class OrderStatusReport(ExecutionReport):
"""
Represents an order status at a point in time.
表示某个时间点的订单状态。
Parameters:
参数:
account_id (AccountId) – The account ID for the report.
account_id (AccountId) - 报告的账户 ID。
instrument_id (InstrumentId) – The instrument ID for the report.
instrument_id (InstrumentId) - 报告的金融工具 ID。
venue_order_id (VenueOrderId) – The reported order ID (assigned by the venue).
venue_order_id (VenueOrderId) - 报告的订单 ID(由场所分配)。
order_side (OrderSide {BUY, SELL}) – The reported order side.
order_side (OrderSide {BUY、SELL}) - 报告的订单方向。
order_type (OrderType) – The reported order type.
order_type (OrderType) - 报告的订单类型。
time_in_force (TimeInForce {GTC, IOC, FOK, GTD, DAY, AT_THE_OPEN, AT_THE_CLOSE}) – The reported order time in force.
time_in_force (TimeInForce {GTC、IOC、FOK、GTD、DAY、AT_THE_OPEN、AT_THE_CLOSE}) - 报告的订单有效时间。
order_status (OrderStatus) – The reported order status at the exchange.
order_status (OrderStatus) - 报告的交易所订单状态。
quantity (Quantity) – The reported order original quantity.
quantity (Quantity) - 报告的订单原始数量。
filled_qty (Quantity) – The reported filled quantity at the exchange.
filled_qty (Quantity) - 报告的交易所成交数量。
report_id (UUID4) – The report ID.
report_id (UUID4) - 报告 ID。
ts_accepted (int) – UNIX timestamp (nanoseconds) when the reported order was accepted.
ts_accepted (int) - 报告的订单被接受时的 UNIX 时间戳(纳秒)。
ts_last (int) – UNIX timestamp (nanoseconds) of the last order status change.
ts_last (int) - 上次订单状态更改的 UNIX 时间戳(纳秒)。
ts_init (int) – UNIX timestamp (nanoseconds) when the object was initialized.
ts_init (int) - 对象初始化时的 UNIX 时间戳(纳秒)。
client_order_id (ClientOrderId , optional) – The reported client order ID.
client_order_id (ClientOrderId,可选) - 报告的客户端订单 ID。
order_list_id (OrderListId , optional) – The reported order list ID associated with the order.
order_list_id (OrderListId,可选) - 与订单关联的报告的订单列表 ID。
contingency_type (ContingencyType, default NO_CONTINGENCY) – The reported order contingency type.
contingency_type (ContingencyType,默认 NO_CONTINGENCY) - 报告的订单意外事件类型。
expire_time (datetime , optional) – The order expiration.
expire_time (datetime,可选) - 订单到期时间。
price (Price , optional) – The reported order price (LIMIT).
price (Price,可选) - 报告的订单价格 (LIMIT)。
trigger_price (Price , optional) – The reported order trigger price (STOP).
trigger_price (Price,可选) - 报告的订单触发价格 (STOP)。
trigger_type (TriggerType, default NO_TRIGGER) – The reported order trigger type.
trigger_type (TriggerType,默认 NO_TRIGGER) - 报告的订单触发类型。
limit_offset (Decimal , optional) – The trailing offset for the order price (LIMIT).
limit_offset (Decimal,可选) - 订单价格 (LIMIT) 的追踪偏移量。
trailing_offset (Decimal , optional) – The trailing offset for the trigger price (STOP).
trailing_offset (Decimal,可选) - 触发价格 (STOP) 的追踪偏移量。
trailing_offset_type (TrailingOffsetType, default NO_TRAILING_OFFSET) – The order trailing offset type.
trailing_offset_type (TrailingOffsetType,默认 NO_TRAILING_OFFSET) - 订单追踪偏移量类型。
avg_px (Decimal , optional) – The reported order average fill price.
avg_px (Decimal,可选) - 报告的订单平均成交价格。
display_qty (Quantity , optional) – The reported order quantity displayed on the public book (iceberg).
display_qty (Quantity,可选) - 报告的公共订单簿上显示的订单数量(冰山订单)。
post_only (bool , default False) – If the reported order will only provide liquidity (make a market).
post_only (bool,默认 False) - 报告的订单是否只提供流动性(做市)。
reduce_only (bool , default False) – If the reported order carries the ‘reduce-only’ execution instruction.
reduce_only (bool,默认 False) - 报告的订单是否带有“仅减仓”执行指令。
cancel_reason (str , optional) – The reported reason for order cancellation.
cancel_reason (str,可选) - 报告的订单取消原因。
ts_triggered (int , optional) – UNIX timestamp (nanoseconds) when the object was initialized.
ts_triggered (int,可选) - 对象初始化时的 UNIX 时间戳(纳秒)。
Raises:
引发:
ValueError – If quantity is not positive (> 0).
ValueError - 如果数量不是正数 (> 0)。
ValueError – If filled_qty is negative (< 0).
ValueError - 如果 filled_qty 为负数 (< 0)。
ValueError – If trigger_price is not None and trigger_price is equal to NO_TRIGGER.
ValueError - 如果 trigger_price 不为 None 并且 trigger_price 等于 NO_TRIGGER。
ValueError – If limit_offset or trailing_offset is not None and trailing_offset_type is equal to NO_TRAILING_OFFSET.
ValueError - 如果 limit_offset 或 trailing_offset 不为 None 并且 trailing_offset_type 等于 NO_TRAILING_OFFSET。
"""
def __init__(self, account_id: AccountId, instrument_id: InstrumentId, venue_order_id: VenueOrderId, order_side: OrderSide, order_type: OrderType, time_in_force: TimeInForce, order_status: OrderStatus, quantity: Quantity, filled_qty: Quantity, report_id: UUID4, ts_accepted: int, ts_last: int, ts_init: int, client_order_id: ClientOrderId = None, order_list_id: OrderListId = None, contingency_type=ContingencyType.NO_CONTINGENCY, expire_time: datetime = None, price: Price = None, trigger_price: Price = None, trigger_type=TriggerType.NO_TRIGGER, limit_offset: Decimal = None, trailing_offset: Decimal = None, trailing_offset_type=TrailingOffsetType.NO_TRAILING_OFFSET, avg_px: Decimal = None, display_qty: Quantity = None, post_only: bool = False, reduce_only: bool = False, cancel_reason: str = None, ts_triggered: int = None):
...
Properties 属性
@property
def id(self) -> UUID4:
"""
The document message ID.
文档消息 ID。
Returns:
UUID4
"""
...
@property
def ts_init(self) -> int:
"""
UNIX timestamp (nanoseconds) when the object was initialized.
对象初始化时的 UNIX 时间戳(纳秒)。
Returns:
uint64_t
"""
...
class FillReport 成交报告
Bases: ExecutionReport
class FillReport(ExecutionReport):
"""
Represents a report of a single order fill.
表示单个订单成交的报告。
Parameters:
参数:
account_id (AccountId) – The account ID for the report.
account_id (AccountId) - 报告的账户 ID。
instrument_id (InstrumentId) – The reported instrument ID for the trade.
instrument_id (InstrumentId) - 交易的报告金融工具 ID。
venue_order_id (VenueOrderId) – The reported venue order ID (assigned by the venue) for the trade.
venue_order_id (VenueOrderId) - 交易的报告场所订单 ID(由场所分配)。
trade_id (TradeId) – The reported trade match ID (assigned by the venue).
trade_id (TradeId) - 报告的交易匹配 ID(由场所分配)。
order_side (OrderSide {BUY, SELL}) – The reported order side for the trade.
order_side (OrderSide {BUY、SELL}) - 交易的报告订单方向。
last_qty (Quantity) – The reported quantity of the trade.
last_qty (Quantity) - 报告的交易数量。
last_px (Price) – The reported price of the trade.
last_px (Price) - 报告的交易价格。
liquidity_side (LiquiditySide {NO_LIQUIDITY_SIDE, MAKER, TAKER}) – The reported liquidity side for the trade.
liquidity_side (LiquiditySide {NO_LIQUIDITY_SIDE、MAKER、TAKER}) - 交易的报告流动性方向。
report_id (UUID4) – The report ID.
report_id (UUID4) - 报告 ID。
ts_event (int) – UNIX timestamp (nanoseconds) when the trade occurred.
ts_event (int) - 交易发生的 UNIX 时间戳(纳秒)。
ts_init (int) – UNIX timestamp (nanoseconds) when the object was initialized.
ts_init (int) - 对象初始化时的 UNIX 时间戳(纳秒)。
client_order_id (ClientOrderId , optional) – The reported client order ID for the trade.
client_order_id (ClientOrderId,可选) - 交易的报告客户端订单 ID。
venue_position_id (PositionId , optional) – The reported venue position ID for the trade. If the trading venue has assigned a position ID / ticket for the trade then pass that here, otherwise pass None and the execution engine OMS will handle position ID resolution.
```python
venue_position_id (PositionId,可选) - 交易的报告场所持仓 ID。如果交易场所已为交易分配了持仓 ID/票据,则在此处传递该 ID,否则传递 None,执行引擎 OMS 将处理持仓 ID 解析。
commission (Money , optional) – The reported commission for the trade (can be None).
commission (Money,可选) - 报告的交易佣金(可以为 None)。
Raises: ValueError – If last_qty is not positive (> 0).
引发:ValueError - 如果 last_qty 不是正数 (> 0)。
"""
def __init__(self, account_id: AccountId, instrument_id: InstrumentId, venue_order_id: VenueOrderId, trade_id: TradeId, order_side: OrderSide, last_qty: Quantity, last_px: Price, liquidity_side: LiquiditySide, report_id: UUID4, ts_event: int, ts_init: int, client_order_id: ClientOrderId = None, venue_position_id: PositionId = None, commission: Money = None):
...
Properties 属性
@property
def id(self) -> UUID4:
"""
The document message ID.
文档消息 ID。
Returns:
UUID4
"""
...
@property
def ts_init(self) -> int:
"""
UNIX timestamp (nanoseconds) when the object was initialized.
对象初始化时的 UNIX 时间戳(纳秒)。
Returns:
uint64_t
"""
...
class PositionStatusReport 持仓状态报告
Bases: ExecutionReport
class PositionStatusReport(ExecutionReport):
"""
Represents a position status at a point in time.
表示某个时间点的持仓状态。
Parameters:
参数:
account_id (AccountId) – The account ID for the report.
account_id (AccountId) - 报告的账户 ID。
instrument_id (InstrumentId) – The reported instrument ID for the position.
instrument_id (InstrumentId) - 持仓的报告金融工具 ID。
position_side (PositionSide {FLAT, LONG, SHORT}) – The reported position side at the exchange.
position_side (PositionSide {FLAT、LONG、SHORT}) - 报告的交易所持仓方向。
quantity (Quantity) – The reported position quantity at the exchange.
quantity (Quantity) - 报告的交易所持仓数量。
report_id (UUID4) – The report ID.
report_id (UUID4) - 报告 ID。
ts_last (int) – UNIX timestamp (nanoseconds) of the last position change.
ts_last (int) - 上次持仓更改的 UNIX 时间戳(纳秒)。
ts_init (int) – UNIX timestamp (nanoseconds) when the object was initialized.
ts_init (int) - 对象初始化时的 UNIX 时间戳(纳秒)。
venue_position_id (PositionId , optional) – The reported venue position ID (assigned by the venue). If the trading venue has assigned a position ID / ticket for the trade then pass that here, otherwise pass None and the execution engine OMS will handle position ID resolution.
venue_position_id (PositionId,可选) - 报告的场所持仓 ID(由场所分配)。如果交易场所已为交易分配了持仓 ID/票据,则在此处传递该 ID,否则传递 None,执行引擎 OMS 将处理持仓 ID 解析。
"""
def __init__(self, account_id: AccountId, instrument_id: InstrumentId, position_side: PositionSide, quantity: Quantity, report_id: UUID4, ts_last: int, ts_init: int, venue_position_id: PositionId = None):
...
Properties 属性
@property
def id(self) -> UUID4:
"""
The document message ID.
文档消息 ID。
Returns:
UUID4
"""
...
@property
def ts_init(self) -> int:
"""
UNIX timestamp (nanoseconds) when the object was initialized.
对象初始化时的 UNIX 时间戳(纳秒)。
Returns:
uint64_t
"""
...
class ExecutionMassStatus 执行批量状态
Bases: Document
class ExecutionMassStatus(Document):
"""
Represents an execution mass status report for an execution client - including status of all orders, trades for those orders and open positions.
表示执行客户端的执行批量状态报告 - 包括所有订单的状态、这些订单的交易和未结持仓。
Parameters:
参数:
venue (Venue) – The venue for the report.
venue (Venue) - 报告的场所。
client_id (ClientId) – The client ID for the report.
client_id (ClientId) - 报告的客户端 ID。
account_id (AccountId) – The account ID for the report.
account_id (AccountId) - 报告的账户 ID。
report_id (UUID4) – The report ID.
report_id (UUID4) - 报告 ID。
ts_init (int) – UNIX timestamp (nanoseconds) when the object was initialized.
ts_init (int) - 对象初始化时的 UNIX 时间戳(纳秒)。
"""
def __init__(self, venue: Venue, client_id: ClientId, account_id: AccountId, report_id: UUID4, ts_init: int):
...
Properties 属性
@property
def order_reports(self) -> dict:
"""
The order status reports.
订单状态报告。
Return type: dict[VenueOrderId, OrderStatusReport]
"""
...
@property
def fill_reports(self):
"""
The fill reports.
成交报告。
Return type: dict[VenueOrderId, list[FillReport]]
"""
...
@property
def position_reports(self):
"""
The position status reports.
持仓状态报告。
Return type: dict[InstrumentId, list[PositionStatusReport]]
"""
...
@property
def id(self) -> UUID4:
"""
The document message ID.
文档消息 ID。
Returns:
UUID4
"""
...
@property
def ts_init(self) -> int:
"""
UNIX timestamp (nanoseconds) when the object was initialized.
对象初始化时的 UNIX 时间戳(纳秒)。
Returns:
uint64_t
"""
...
Methods 方法
def add_order_reports(self, reports: list) -> None:
"""
Add the order reports to the mass status.
将订单报告添加到批量状态。
Parameters: reports (list [OrderStatusReport ]) – The list of reports to add.
参数:reports (list [OrderStatusReport ]) - 要添加的报告列表。
Raises: TypeError – If reports contains a type other than FillReport.
引发:TypeError - 如果 reports 包含 FillReport 以外的类型。
"""
...
def add_fill_reports(self, reports: list) -> None:
"""
Add the fill reports to the mass status.
将成交报告添加到批量状态。
Parameters: reports (list [FillReport ]) – The list of reports to add.
参数:reports (list [FillReport ]) - 要添加的报告列表。
Raises: TypeError – If reports contains a type other than FillReport.
引发:TypeError - 如果 reports 包含 FillReport 以外的类型。
"""
...
def add_position_reports(self, reports: list[PositionStatusReport]) -> None:
"""
Add the position status reports to the mass status.
将持仓状态报告添加到批量状态。
Parameters: reports (list [PositionStatusReport ]) – The reports to add.
参数:reports (list [PositionStatusReport ]) - 要添加的报告。
"""
...