project / August 13, 2026 / 4 min read

MicroSim

A pure standard-library stock market simulator with exact order matching, simulated traders, and a live web dashboard.

On this page
  1. Problem
  2. Approach
  3. Architecture
  4. Lessons Learned

Problem

Understanding how buyers and sellers interact in a market usually requires either live market data or complicated software. Live data only shows what already happened, so you cannot test what would change if traders behaved differently. At the same time, many market simulators suffer from timing glitches or rounding errors that make tests impossible to repeat exactly.

Approach

MicroSim is a self-contained market simulator built around strict repeatability:

  • Exact repeatability: The same starting seed always produces the exact same sequence of trades and prices.
  • Integer calculations: Prices use whole ticks and time uses microseconds. Rounding errors from decimals never enter order matching.
  • First-come, first-served matching: Orders fill strictly by best price and arrival time, matching how real electronic exchanges work.
  • Simulated traders: The market includes random buyers and sellers, an automated market maker providing buy and sell quotes, and momentum and trend-following strategies.
  • Independent playback speed: Running the simulation in slow motion (0.25×), fast forward (180×), or as fast as possible in the background does not change the sequence of trades.

Architecture

  • Matching engine: A complete limit order book written using only standard Python, with zero extra dependencies.
  • Event scheduler: A queue that steps through trades in simulated microsecond time.
  • Live dashboard: A lightweight FastAPI web app showing live price charts, order book depth, and individual trader profits.
  • Testing tools: Command-line tools to run batches of experiments and compare different trading strategies against a baseline.

Lessons Learned

Using whole numbers for prices and an explicit queue for time eliminates the random drift that plagues many simulations. Comparing strategy runs against the exact same seed makes it easy to see whether a change actually improved trading performance or was just random luck.

View the project on GitHub.

Harris Oldroyd · Independent builder who explains AI from first principles

If this was worth your time, follow along for new experiments, benchmarks, and explanations.