Managing Frequent Orders with Event-Driven State Tracking
Summary
The discussion considers whether a strategy handling frequent submissions and cancellations should manage orders through the framework’s event loop or use a separate thread. The proposed approach is event-driven: submit orders, track active order identifiers and states, then use order callbacks to respond to fills, cancellations, or orders that remain unfilled. It also describes timeout-based cancellation, batch cancellation across contracts, and checks to avoid duplicate orders at similar prices.
The response favors this design for integration with the trading framework and to reduce thread-safety and synchronization problems. It argues that a separate thread can add complexity and may be constrained by Python’s execution model, while reserving separate-thread handling for specialized cases. The original poster raises concerns about many instruments, partial fills, and processing delays, but the discussion does not resolve them with measurements or a detailed partial-fill design. The examples are illustrative and require careful order-state handling in a live system.
Key ideas
- Order callbacks can drive cancellation and resubmission decisions while keeping order state in an active-order map.
- Timeout checks can cancel orders that remain active beyond a chosen interval.
- Batch cancellation and duplicate-order checks can help manage multiple instruments.
- The response recommends event-driven handling to limit cross-thread synchronization risks.
- The discussion leaves latency and partial-fill behavior without measured evidence or a complete treatment.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.