Converting Position Offsets for Close-Today and Close-Yesterday Rules
Summary
This code tracks long and short holdings, separating each side into today’s and prior-day positions. It updates those amounts from position snapshots and trades, and it keeps active orders so that quantities committed to closing positions are treated as frozen and unavailable. This supports order conversion for exchanges and contract types with different position-offset requirements.
For one exchange, a close request is rejected if available holdings are insufficient, otherwise split between close-today and close-yesterday quantities when needed. A separate lock mode can close eligible prior-day positions before opening the remaining quantity, or open directly when today’s opposing position exists. These routines illustrate order-management mechanics rather than a trading signal. They provide no test evidence, and correctness depends on accurate position, trade, and active-order updates.
Key ideas
- Holdings are tracked separately for long and short positions, with today and prior-day quantities distinguished.
- Active closing orders freeze available position quantities; opening orders do not.
- Close requests can be split across today and prior-day offsets to meet exchange rules.
- Lock mode may close eligible opposing prior-day holdings and open any remaining quantity.
- The conversion logic depends on accurate position, trade, and order updates.
Tags
From a private course collection; the original is not published.