Skip to content
All library documents

Trading Data Structures and Grid Position Average Price Accounting

Code Quant course library

Summary

The document defines common records used to represent ticks, bars, orders, fills, positions, accounts, contracts, and trading requests. Fields capture instrument identity, exchange, time, prices, volumes, order state, and selected contract properties. Derived identifiers link records to instruments, gateways, orders, trades, or positions; order helpers can generate cancellation and query requests.

It also presents a grid position calculator that updates only when an order is fully filled. It tracks signed position, average price, and profit state, adjusting the average as positions are added, reduced, or crossed through zero. The formulas incorporate a configurable grid step when trade direction changes against an existing position. The code supplies no worked examples or performance evidence, and its accounting assumptions should be checked against the specific grid strategy and execution model using it.

Key ideas

  • Tick records include last trade information, intraday statistics, and several levels of bid and ask prices and sizes.
  • Bar, order, fill, position, account, and contract records organize core trading state.
  • Order records can identify active orders and produce cancellation or query requests.
  • The grid calculator ignores orders that are not fully filled.
  • Its average-price updates account for position additions, reductions, reversals, and a configurable grid step.

Tags

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