Live trading - Loren1166/NautilusTrader- GitHub Wiki
Live trading 实时交易
info 信息
We are currently working on this article.
我们目前正在撰写本文。
Live trading in NautilusTrader enables traders to deploy their backtested strategies in a real-time trading environment with no code changes. This seamless transition from backtesting to live trading is a cornerstone of the platform's design, ensuring consistency and reliability. Even so, there are still some key differences to be aware of between backtesting and live trading.
NautilusTrader 中的实时交易使交易者能够在实时交易环境中部署其回测策略,而无需更改代码。从回测到实时交易的这种无缝过渡是平台设计的基石,可确保一致性和可靠性。即便如此,回测和实时交易之间仍然存在一些关键差异需要注意。
This guide provides an overview of the live trading process and its key aspects.
本指南概述了实时交易流程及其关键方面。
Configuration 配置
When operating a live trading system, configuring your execution engine and strategies properly is essential for ensuring performance, reliability, and accuracy. The following is an overview of the key concepts and settings involved for live configuration.
运行实时交易系统时,正确配置执行引擎和策略对于确保性能、可靠性和准确性至关重要。以下是实时配置涉及的关键概念和设置的概述。
Execution Engine configuration 执行引擎配置
The
LiveExecEngineConfig
sets up the live execution engine, managing order processing, execution events, and reconciliation with trading venues. The following outlines the main configuration options.
LiveExecEngineConfig
设置实时执行引擎,管理订单处理、执行事件以及与交易平台的对账。以下概述了主要的配置选项。
info 信息
See also the LiveExecEngineConfig API Reference for further details.
有关更多详细信息,另请参阅 LiveExecEngineConfig API 参考。
Reconciliation 对账
Purpose: Ensures that the system state remains consistent with the trading venue by recovering any missed events, such as order and position status updates.
目的: 通过恢复任何错过的事件(例如订单和头寸状态更新)来确保系统状态与交易平台保持一致。
Settings:
设置:
reconciliation
: (defaultTrue
): Activates reconciliation at startup, aligning the system's internal state with the execution venue's state.reconciliation
:(默认值True
):在启动时激活对账,将系统的内部状态与执行平台的状态对齐。reconciliation_lookback_mins
: Specifies how far back (in minutes) the system should request past events to reconcile. This provides recovery for uncached execution state.reconciliation_lookback_mins
:指定系统应请求多长时间(以分钟为单位)的过去事件进行对账。这为未缓存的执行状态提供恢复。
info 信息
See also Execution reconciliation for further details.
有关更多详细信息,另请参阅执行对账。
Order filtering 订单过滤
Purpose: Manages which order events and reports should be processed by the system to avoid conflicts with other trading nodes and unnecessary data handling.
目的: 管理系统应处理哪些订单事件和报告,以避免与其他交易节点发生冲突并避免不必要的数据处理。
Settings:
设置:
filter_unclaimed_external_orders
: (defaultFalse
) Filters out unclaimed external orders, which can help prevent irrelevant external orders from impacting the strategy.filter_unclaimed_external_orders
:(默认值False
)过滤掉未声明的外部订单,这有助于防止不相关的外部订单影响策略。filter_position_reports
: (defaultFalse
) Filters out position status reports, which is useful in scenarios where multiple nodes are trading the same instruments on the same account, thus avoiding conflicting position data.filter_position_reports
:(默认值False
)过滤掉头寸状态报告,这在多个节点在同一账户上交易相同Instrument的情况下很有用,从而避免头寸数据冲突。
In-flight order checks 进行中订单检查
Purpose: Regularly checks the status of in-flight orders (orders that have been submitted, modified or canceled but not yet confirmed) to ensure they are processed correctly and promptly.
目的: 定期检查进行中订单(已提交、修改或取消但尚未确认的订单)的状态,以确保它们得到正确及时的处理。
Settings:
设置:
inflight_check_interval_ms
: (default 2,000 ms) Determines how frequently the system checks the status of in-flight orders.inflight_check_interval_ms
:(默认值 2,000 毫秒)确定系统检查进行中订单状态的频率。inflight_check_threshold_ms
: (default 5,000 ms) Sets the time threshold after which an in-flight order is considered for a status check with the venue. Adjusting this setting is particularly important if you are colocated with the venue, to avoid potential race conditions.inflight_check_threshold_ms
:(默认值 5,000 毫秒)设置时间阈值,在此阈值之后,将考虑使用交易平台对进行中订单进行状态检查。如果您与交易平台共处一地,则调整此设置尤为重要,以避免潜在的竞争条件。
Queue management 队列管理
Purpose: Handles the internal buffering of orders and events to ensure smooth processing and to prevent system overloads.
目的: 处理订单和事件的内部缓冲,以确保平稳处理并防止系统过载。
Settings:
设置:
qsize
(default 100,000): Sets the size of the internal queue buffers, which helps in managing the flow of data within the engine.qsize
(默认值 100,000):设置内部队列缓冲区的大小,这有助于管理引擎内的数据流。
Strategy configuration 策略配置
The
StrategyConfig
class outlines the configuration for trading strategies, ensuring that each strategy operates with the correct parameters and manages orders effectively. The following outlines the main configuration options.
StrategyConfig
类概述了交易策略的配置,确保每个策略都使用正确的参数并有效地管理订单。以下概述了主要的配置选项。
info 信息
See also the StrategyConfig API Reference for further details.
有关更多详细信息,另请参阅 StrategyConfig API 参考。
Strategy identification 策略标识
Purpose: Provides unique identifiers for each strategy to prevent conflicts and ensure proper tracking of orders.
目的: 为每个策略提供唯一标识符,以防止冲突并确保正确跟踪订单。
Settings:
设置:
strategy_id
: A unique ID for the strategy, ensuring it can be distinctly identified.strategy_id
:策略的唯一 ID,确保可以明确识别它。order_id_tag
: A unique tag for the strategy's orders, differentiates orders from multiple strategies.order_id_tag
:策略订单的唯一标签,用于区分来自多个策略的订单。
Order Management System (OMS) type 订单管理系统 (OMS) 类型
Purpose: Defines how the order management system handles position IDs, influencing how orders are processed and tracked.
目的: 定义订单管理系统如何处理头寸 ID,从而影响订单的处理和跟踪方式。
Settings:
设置:
oms_type
: Specifies the type of OMS, which dictates the handling of position IDs and impacts the overall order processing flow.oms_type
:指定 OMS 的类型,它决定了头寸 ID 的处理方式并影响整个订单处理流程。
External order claims 外部订单声明
Purpose: Enables the strategy to claim external orders based on specified instrument IDs, ensuring that relevant external orders are associated with the correct strategy.
目的: 使策略能够根据指定的Instrument ID 声明外部订单,从而确保将相关的外部订单与正确的策略相关联。
Settings:
设置:
external_order_claims
: Lists instrument IDs for external orders that the strategy should claim, helping to manage and track these orders accurately.external_order_claims
:列出策略应声明的外部订单的Instrument ID,有助于准确管理和跟踪这些订单。
Contingent order management 附带订单管理
Purpose: Automates the management of contingent orders, such as One-Updates-the-Other (OUO) and One-Cancels-the-Other (OCO) orders, ensuring they are handled correctly.
目的: 自动管理附带订单,例如一对一更新 (OUO) 和一对一取消 (OCO) 订单,确保它们得到正确处理。
Settings:
设置:
manage_contingent_orders
: (defaultFalse
) If enabled, the strategy will automatically manage contingent orders, reducing the need for manual intervention.manage_contingent_orders
:(默认值False
)如果启用,策略将自动管理附带订单,从而减少手动干预的需要。
GTD (Good-Till-Date) expiry management GTD(有效期至日期)到期管理
Purpose: Ensures that orders with GTD time-in-force instructions are managed properly, with timers reactivated as necessary.
目的: 确保正确管理具有 GTD 有效期指令的订单,并在必要时重新激活计时器。
Settings:
设置:
manage_gtd_expiry
: (defaultFalse
) If enabled, the strategy will manage GTD expirations, ensuring that orders remain active as intended.manage_gtd_expiry
:(默认值False
)如果启用,策略将管理 GTD 到期,确保订单按预期保持活动状态。
By configuring these parameters thoughtfully, you can ensure that your trading system operates efficiently, handles orders correctly, and remains resilient in the face of potential issues, such as lost events or conflicting data.
通过仔细配置这些参数,您可以确保您的交易系统高效运行,正确处理订单,并在面对潜在问题(例如事件丢失或数据冲突)时保持弹性。