-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Feature Request
Problem Statement
When stopping trading strategies based on trading conditions, rather than shutdown, active in-flight or racing orders may persist in the market. This issue arises when using a simple sequence of cancel_all_orders followed by close_all_positions, which does not adequately handle orders that are still in transit or in the process of execution.
Proposed Solution
Implement a robust market exit process for trading strategies to ensure all in-flight orders and open positions are fully resolved before shutdown or restart. The process should be integrated into the existing strategy lifecycle as follows:
a. Any component can publish an exit command targeting a specific strategy.
b. Exit Process:
- The strategy invokes self.on_market_exit to initiate the exit sequence.
- Execute a consistent, iterative market exit procedure:
- Wait for in-flight orders status change (configure inflight_check_interval_ms for low latency).
- Wait until all active orders are confirmed canceled.
- Ensure all positions are fully closed before proceeding.
- Invoke self.after_market_exit to customise the exit process.
c. Incorporate the market exit process into the existing strategy shutdown workflow.