Order Book & Microstructure
How the Simulated Order Book Works
PatternFoundry's order book is a full limit order book simulation - not a simple random walk. Multiple autonomous agents submit, cancel, and modify orders in real-time, creating emergent price behavior that mirrors real market microstructure.
The order book maintains:
- Bid side - All resting buy orders, sorted by price (highest first)
- Ask side - All resting sell orders, sorted by price (lowest first)
- Trade tape - Record of all executed trades with time, price, size, and aggressor side
When an aggressive order (market order or limit order that crosses the spread) arrives, it matches against resting orders at the best available price. If the aggressive order is larger than the resting liquidity at the best price, it "walks the book" - filling at progressively worse prices until fully filled. This creates realistic slippage.
Agent Types
Four types of simulated agents interact in the order book:
Market Makers
Market makers continuously quote both sides of the book, providing liquidity. They:
- Maintain bid and ask quotes within a configurable spread of the mid-price
- Adjust quotes based on inventory (skew toward reducing position)
- Widen spreads during high volatility (uncertainty)
- Cancel and replace quotes as the mid-price moves
Market makers are the primary source of resting liquidity and are responsible for the bid-ask spread.
Institutional Agents
Institutional agents represent large directional traders (hedge funds, asset managers). They:
- Submit large orders that move price
- Trade with persistence - once they start buying/selling, they continue in the same direction (modeling TWAP/VWAP execution)
- Create sustained directional pressure that drives trends
- May use limit orders to minimize market impact (iceberg behavior)
Retail Agents
Retail agents represent individual traders. They:
- Submit small, randomly-directed orders
- Add noise and background liquidity
- Have no persistence - each order is independent
- Primarily use market orders (aggressive)
Momentum Agents
Momentum agents chase price movement. They:
- Buy when price is rising, sell when price is falling
- Create positive feedback loops that accelerate moves
- Contribute to trend continuation and stop cascades
- Activate more strongly during high-volatility periods
Hawkes Self-Excitation (Trade Clustering)
Real markets exhibit trade clustering - trades tend to arrive in bursts rather than uniformly. PatternFoundry models this using a Hawkes process, a self-exciting point process where each event increases the probability of subsequent events.
The intensity (rate of order arrivals) at time t is:
λ(t) = λ₀ + Σ α · e^(-β(t - tᵢ))
Where:
- λ₀ (Base Intensity) - Background arrival rate when no excitation is present
- α (Alpha) - Jump in intensity caused by each trade
- β (Beta) - Exponential decay rate of excitation
- tᵢ - Times of previous trades
This creates realistic bursts of activity: a single trade triggers more trades, which trigger even more, creating cascading activity that naturally decays back to baseline. This is visible in the tape as clusters of rapid trades followed by quiet periods.
Price Impact from Order Flow
Price impact in PatternFoundry follows realistic market microstructure principles:
- Temporary impact - Large aggressive orders push price away from equilibrium. The impact is proportional to order size relative to available liquidity.
- Permanent impact - Sustained directional flow (institutional persistence) shifts the equilibrium price permanently.
- Book depletion - When one side of the book is consumed faster than it's replenished, price moves rapidly in that direction (vacuum/air pocket).
- Spread dynamics - After a large trade depletes liquidity, the spread widens temporarily until market makers replenish quotes.
Your own orders in the simulator also experience realistic price impact. A large market order will slip through multiple price levels if insufficient liquidity exists at the best price.
Liquidity Pools (Support/Resistance)
Liquidity pools model the tendency for orders to accumulate at specific price levels, creating support and resistance:
- Pools are placed at psychologically significant levels (round numbers, previous highs/lows)
- They attract price via the Strength parameter - higher strength means price is more likely to gravitate toward pool levels
- When price reaches a pool, the concentrated liquidity can either absorb the move (support/resistance holds) or, if overwhelmed, create a breakout with acceleration (stop cascade)
- The Count parameter determines how many pools exist in the visible range
This creates realistic chart patterns: price bouncing between levels, false breakouts, and genuine breakouts with follow-through.
DOM Panel Interpretation
Reading the DOM (Depth of Market) panel effectively:
| Signal | Interpretation |
|---|---|
| Large resting bid | Potential support level - but may be spoofed (pulled before fill) |
| Large resting ask | Potential resistance level |
| Thin book (low size) | Price can move quickly through these levels - low liquidity zone |
| Aggressive buying (trades hitting ask) | Bullish pressure - buyers willing to pay the spread |
| Aggressive selling (trades hitting bid) | Bearish pressure - sellers willing to cross the spread |
| Spread widening | Uncertainty - market makers pulling back, expect volatility |
| Rapid book replenishment | Strong market maker presence - price likely to mean-revert |
Watch for "iceberg" behavior - a price level that keeps getting refilled after being consumed. This indicates a large institutional order being worked at that level and is a strong directional signal.
PatternFoundry