-
Notifications
You must be signed in to change notification settings - Fork 0
Emulated Orders
The platform makes it possible to emulate most order types locally, regardless of whether the type is supported on a trading venue. The logic and code paths for order emulation are exactly the same for all environment contexts and utilize a common
OrderEmulator
component.该平台可以在本地模拟大多数订单类型,无论交易平台是否支持该类型。所有环境上下文中订单模拟的逻辑和代码路径完全相同,并且使用通用的
OrderEmulator
组件。
There is no limitation on the number of emulated orders you can have per running instance.
每个正在运行的实例可以拥有的模拟订单数量没有限制。
The only requirement to emulate an order is to pass a
TriggerType
to theemulation_trigger
parameter of anOrder
constructor, orOrderFactory
creation method. The following emulation trigger types are currently supported:模拟订单的唯一要求是将
TriggerType
传递给Order
构造函数或OrderFactory
创建方法的emulation_trigger
参数。当前支持以下模拟触发类型:
DEFAULT
(which is the same asBID_ASK
)DEFAULT
(与BID_ASK
相同)BID_ASK
(emulated using quote ticks)BID_ASK
(使用报价模拟)LAST
(emulated using trade ticks)LAST
(使用交易模拟)
Emulated orders are subject to the same risk controls as 'regular' orders, and can be modified and canceled by a trading strategy in the normal way. They will also be included when canceling all orders.
模拟订单与“常规”订单受到相同的风险控制,并且可以通过交易策略以正常方式进行修改和取消。取消所有订单时,它们也将包含在内。
An emulated order will retain its original client order ID throughout its entire life cycle, making it easy to query through the cache.
模拟订单将在其整个生命周期中保留其原始客户端订单 ID,从而可以轻松地通过缓存进行查询。
An emulated order will progress through the following stages:
模拟订单将经历以下阶段:
- Submitted by a
Strategy
through thesubmit_order
method. 通过submit_order
方法由Strategy
提交。- Then sent to the
RiskEngine
for pre-trade risk checks (it may be denied at this point). 然后发送到RiskEngine
以进行交易前风险检查(此时可能会被拒绝)。- Then sent to the
OrderEmulator
where it is held / emulated. 然后发送到OrderEmulator
,在那里它被持有/模拟。
The following will occur for an emulated order now held by the
OrderEmulator
component:对于现在由
OrderEmulator
组件持有的模拟订单,将发生以下情况:
- The original
SubmitOrder
command will be cached. 原始SubmitOrder
命令将被缓存。- The emulated order will be processed inside a local
MatchingCore
component. 模拟订单将在本地MatchingCore
组件内部进行处理。- The
OrderEmulator
will subscribe to any needed market data (if not already) to update the matching core.OrderEmulator
将订阅任何需要的市场数据(如果尚未订阅)以更新匹配核心。- The emulated order can be modified (by the trader) and updated (by the market) until released or canceled. 在发布或取消之前,模拟订单可以由交易者修改,也可以由市场更新。
Once an emulated order is triggered / matched locally based on the arrival of data, the following release actions will occur:
一旦根据数据的到达在本地触发/匹配模拟订单,将发生以下发布操作:
- The order will be transformed to either a
MARKET
orLIMIT
order (see below table) through an additionalOrderInitialized
event. 该订单将通过一个额外的OrderInitialized
事件转换为MARKET
或LIMIT
订单(见下表)。- The orders
emulation_trigger
will be set toNONE
(it will no longer be treated as an emulated order by any component). 订单的emulation_trigger
将设置为NONE
(它将不再被任何组件视为模拟订单)。- The order attached to the original
SubmitOrder
command will be sent back to theRiskEngine
for additional checks since any modification/updates. 自任何修改/更新以来,附加到原始SubmitOrder
命令的订单将被发送回RiskEngine
以进行其他检查。- If not denied, then the command will continue to the
ExecutionEngine
and on to the trading venue via anExecutionClient
as normal. 如果没有被拒绝,则该命令将继续发送到ExecutionEngine
,然后通过ExecutionClient
正常发送到交易平台。
The following table lists which order types are possible to emulate, and which order type they transform to when being released for submission to the trading venue.
下表列出了可以模拟的订单类型,以及在发布以提交到交易平台时它们转换为哪种订单类型。
Order types | Can emulate | Released type |
---|---|---|
MARKET | - | |
MARKET_TO_LIMIT | - | |
LIMIT | ✓ | MARKET |
STOP_MARKET | ✓ | MARKET |
STOP_LIMIT | ✓ | LIMIT |
MARKET_IF_TOUCHED | ✓ | MARKET |
LIMIT_IF_TOUCHED | ✓ | LIMIT |
TRAILING_STOP_MARKET | ✓ | MARKET |
TRAILING_STOP_LIMIT | ✓ | LIMIT |
When writing trading strategies, it may be necessary to know the state of emulated orders in the system. It's possible to query for emulated orders through the following
Cache
methods:在编写交易策略时,可能需要了解系统中模拟订单的状态。可以通过以下
Cache
方法查询模拟订单:
self.cache.orders_emulated(...)
self.cache.is_order_emulated(...)
self.cache.orders_emulated_count(...)
See the full API reference for additional details.
有关其他详细信息,请参阅完整的 API 参考。
You can also query order objects directly:
您还可以直接查询订单对象:
order.is_emulated
If either of these return
False
, then the order has been released from theOrderEmulator
, and so is no longer considered an emulated order.如果其中任何一个返回
False
,则该订单已从OrderEmulator
中释放,因此不再被视为模拟订单。
It's not advised to hold a local reference to an emulated order, as the order object will be transformed when/if the emulated order is released. You should rely on the
Cache
which is made for the job.不建议保留对模拟订单的本地引用,因为如果/当模拟订单被释放时,订单对象将被转换。您应该依赖于为此工作而设计的
Cache
。
If a running system either crashes or shuts down with active emulated orders, then they will be reloaded inside the
OrderEmulator
from any configured cache database.如果正在运行的系统在具有活动模拟订单的情况下崩溃或关闭,则它们将从任何已配置的缓存数据库重新加载到
OrderEmulator
中。