Skip to content
All library documents

Vector-Based Order Book Storage for a Bounded Price Range

Code Stratmill research code

Summary

The document presents an implementation of a limit order book that stores level-two depth in bid and ask vectors over a configured range of price ticks. It maps prices to array indices using the tick size, aggregates quantities at each level, and tracks best bid and ask prices. When updates remove depth at the current best price, helper routines scan the relevant range to locate the next occupied level. Orders outside the configured range are recorded for level-three tracking but do not contribute to the depth vectors.

This design is intended to reduce overhead compared with a hash-map depth representation when calculations focus near the mid-price. The code also handles order additions, modifications, deletions, snapshots, and clearing depth, with tests illustrating level-three order changes. Its performance benefit is stated as a design rationale; the excerpt supplies no benchmark results. Because storage is bounded, book state beyond the range of interest is not represented in the vectors, and users must choose a range suitable for their application.

Key ideas

  • The implementation maps a bounded range of price ticks to bid and ask quantity vectors.
  • It maintains best-price ticks and searches for the next occupied level when top-level depth disappears.
  • Orders outside the configured range are excluded from vector depth aggregation.
  • The design targets faster order-book calculations near the mid-price than a hash-map approach.
  • The excerpt includes behavioral tests but no performance benchmarks.

Tags

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