An interactive market microstructure laboratory.
Mercer is a browser-based synthetic exchange. A seeded mathematical model creates limit orders, market orders, and cancellations; a price-time matching engine turns that flow into trades and prices; the interface exposes the process as it happens.
It is not a historical market feed, an investing product, or a trading venue. Mercer places an inventory-aware market maker inspired by Avellaneda and Stoikov inside a broader synthetic limit-order book so its behavior can be inspected.
seed + market rules
|
v
stochastic order flow
|
v
price-time matching
|
v
book state + trades + microprice
|
v
Liveline chart + exact FIFO ladder
Prices remain integer ticks inside the engine. Orders execute at the best price first and follow FIFO order within each price level. A native Web Worker owns the simulation clock and publishes immutable snapshots to the interface.
Let
Top-of-book imbalance measures which queue is heavier:
Mercer uses the microprice as its primary live value:
If the spread is
The microprice therefore leans toward the side whose best queue has more quantity, making pressure visible before a price level disappears.
Limit arrivals, market orders, and cancellations each have a state-dependent
hazard
The waiting time to the next event is exponentially distributed:
The event type is selected by its share of the total rate:
The simulated clock jumps directly from one order-book event to the next. Two
seeded xoshiro128** streams keep scheduling and event details reproducible.
For midpoint
Mercer uses the finite-horizon spread approximation:
Here
Quotes are placed around
A long position lowers the reservation price and encourages selling; a short position raises it and encourages buying. The maker submits through the same matching engine as every other participant.
Mercer includes deterministic scenarios for balanced flow, liquidity shocks, one-sided pressure, cancellation spikes, large meta-orders, tick-size changes, and different market-maker risk policies.
Twin mode runs a control and one-parameter intervention from aligned seeded random streams. This makes the effect of a single market rule visible without changing the rest of the experiment.
- Next.js 16.3, React 19.2, and TypeScript.
- A deterministic engine isolated under
src/engine. - A native Web Worker for simulation and clock control.
- Liveline 0.0.7 for the Canvas-rendered temporal chart.
- An exact order-book ladder for price levels, aggregate depth, and FIFO queues.
- Node's built-in test runner for matching, determinism, scenarios, and model invariants.
This project uses pnpm.
pnpm install
pnpm devOpen http://localhost:3000.
Run the release checks with:
pnpm test
pnpm typecheck
pnpm lint
pnpm buildThe inventory-aware quoting policy is based on Marco Avellaneda and Sasha Stoikov's paper, High-frequency trading in a limit order book. Mercer's surrounding stochastic exchange is a qualitative synthetic model, not an empirical calibration or a reproduction of every assumption in the paper.