Skip to content
All library documents

Managing Commodity Futures Positions and Trading Hours in CTP

Article Strategy library · Author: edwardgyw

Summary

This document describes a JavaScript library for managing commodity futures positions through a CTP exchange interface. Its functions aggregate positions by contract and direction, submit or close orders, cancel pending orders, and report account balance changes. Users can supply a limit price or let the library use the best available quote, with order size constrained by contract limits and displayed depth.

It also provides a trading-hours check covering daytime sessions, several night-session schedules, weekends, and user-defined holiday dates, plus a connection retry helper. The example opens and closes a short position, but the document supplies no performance results or evidence that the methods improve execution. The trading-hours logic relies on local date and time handling, and the holiday list is manually configured; session rules and order behavior should therefore be checked against the relevant exchange and broker before use.

Key ideas

  • The position manager aggregates contract holdings by long or short direction before calculating average entry price and profit.
  • Opening and closing routines submit orders in contract-sized portions and cancel pending orders while checking for fills.
  • A user-supplied limit price can be used for entries and exits, while omitted prices are derived from the order book.
  • Trading availability is estimated from configured daytime and night sessions, weekends, and a manually maintained holiday list.
  • The connection helper retries contract setup before giving up, but the example provides no evidence of trading performance.

Tags

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