Skip to content
All library documents

Converting Futures Orders Across Today and Prior-Day Positions

Code Quant course library

Summary

The material explains how an order-management component adapts close orders to futures position rules. It maintains separate long and short holdings, splitting each into positions opened today and positions carried from earlier sessions. Incoming position snapshots set those quantities, while executions adjust them according to trade direction and whether the trade opens or closes exposure. Active close orders reserve holdings so multiple pending orders do not claim the same available quantity.

For exchanges that require explicit close-today and close-yesterday instructions, a requested close is checked against unreserved holdings and divided into the applicable portions; an oversized request is rejected. A separate locking mode may close an eligible earlier-session position and open any remainder, or open the whole order when today's opposing position exists. The logic also skips conversion for net-position contracts and passes through requests for other exchanges. The material provides implementation detail but no empirical performance evidence. It depends on accurate contract metadata, position updates, and order lifecycle events, and does not discuss recovery from inconsistent or missing state.

Key ideas

  • Track long and short exposure separately, including quantities opened today and held from prior sessions.
  • Subtract pending close orders from available holdings to avoid reserving the same position twice.
  • Split close requests between today and prior-session offsets where exchange rules require the distinction.
  • Reject close requests that exceed the available opposing position.
  • Locking logic can combine a close of prior exposure with an opening order for the remainder.
  • Conversion depends on contract position mode and exchange-specific offset behavior.

Tags

From a private course collection; the original is not published.