Skip to content
All library documents

Handling Delayed Position Updates in CTA Order Callbacks

Article vn.py community

Summary

The discussion explains a timing issue in CTA strategies using the CTP interface: order status updates may arrive before trade updates, and the position is updated with the trade notification. A strategy that reacts to a fully filled order inside its order callback can therefore read a stale position and submit a closing order for the wrong quantity.

For ordinary bar-driven strategies, the recommended pattern is to make trading decisions in the bar callback, where earlier trade notifications should already have updated the position. Strategies that must act directly on callbacks can instead use the order’s traded quantity, make position-dependent decisions in the trade callback, or track outstanding orders before submitting more. The advice describes event sequencing and callback design, not a trading signal or performance-tested strategy; the timing assumptions may depend on the gateway and implementation.

Key ideas

  • CTP may report a fully filled order before delivering the associated trade update that changes the position.
  • A position read in the order callback can consequently lag the actual fills.
  • Bar-driven logic usually avoids this race by making decisions after earlier fill notifications have been processed.
  • Callback-driven strategies can use the order’s filled quantity or wait for the trade callback before acting.
  • Tracking in-flight orders helps prevent premature or duplicate submissions.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.