PatternFoundry
← Back to Docs

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:

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:

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:

Retail Agents

Retail agents represent individual traders. They:

Momentum Agents

Momentum agents chase price movement. They:

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:

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:

Note

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:

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:

SignalInterpretation
Large resting bidPotential support level - but may be spoofed (pulled before fill)
Large resting askPotential 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 wideningUncertainty - market makers pulling back, expect volatility
Rapid book replenishmentStrong market maker presence - price likely to mean-revert
Tip

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.