Hash Map Market Depth for Resilient Best Bid and Ask Tracking
Summary
This document describes a market-depth implementation that stores bid and ask quantities by price tick in hash maps and tracks the current best bid and ask separately. It supports both aggregated level-two depth and level-three order records, with operations for depth updates, order changes, snapshots, and clearing levels. The stated design motivation is resilience to missing depth updates: when a best price is removed, the implementation searches remaining levels to refresh the best price rather than relying on a sorted map that may retain stale levels.
The code also maintains outer tick bounds to help search for replacement prices and converts prices and quantities using configured tick and lot sizes. Included tests exercise order modification and deletion behavior, providing implementation-level examples rather than trading evidence. The document does not report throughput benchmarks or establish correctness under every feed failure pattern. Hash maps also do not inherently provide sorted iteration, so the best-price search logic and its boundary state are central to the design. This is infrastructure for market-data processing and backtesting, not a trading strategy.
Key ideas
- The implementation stores bid and ask quantities by price tick in hash maps.
- It tracks best prices explicitly and searches for replacement levels when a best price is removed.
- It is designed to refresh depth state when updates are missing, addressing a stated stale-price concern with a tree-based approach.
- The code handles level-two depth and level-three order records, with tick and lot size conversions.
- Included tests illustrate order modification and deletion behavior but do not provide performance benchmarks.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.