This project implements a limit order book simulator with price-time priority (FIFO) matching, designed to replicate how modern electronic markets execute trades.
It focuses on correctness of order matching and accurate market microstructure behaviour, rather than latency optimization and interactive UI.
This simulator supports both market and limit orders, partial filling, order cancellation and trade generation. It also has a simulator that allows users to generate random trades and observe how the orderbook evolves.
The project uses a CLI-based interface similar to real-world exchange systems.
A limit order book (LOB) is the core data structure used by electronic exchanges to match buyers and sellers, thus executing trades.
- Bids: Buy orders, sorted by highest price first
- Asks: Sell orders, sorted by lowest price first
- Price-time priority: Orders are matched first by price, then on a first-come-first-serve basis.
- Maker vs taker: Resting orders provide liquidity (makers), incoming orders consume it (takers)
- Trade splitting: A single order may execute across multiple resting orders, generating multiple trades at the same price.
- Price-time priority (FIFO)
- Market and limit orders
- Order cancellation
- Automatic random trade generation
- Static market snapshot visualizations (depth and trade tape)
Order-book-simulator/
│
├── core/
│ ├── __init__.py
│ ├── order.py # Order lifecycle and state management
│ ├── price_level.py # FIFO queue of orders at a single price
│ ├── order_book.py # Price-time priority matching engine
│ ├── exchange.py # Order submission, cancellation, trade coordination
│ ├── trade.py # Executed trade representation
│ └── enums.py # Order side, type, and status enums
│
├── simulator/
│ ├── __init__.py
│ └── simulator.py # Randomized order flow generator
│
├── visualization/
│ ├── __init__.py
│ └── plots.py # Static Plotly depth and trade tape plots
│
├── main.py # CLI interface for interacting with the exchange
├── README.md # Project documentation
├── requirements.txt # Python dependencies
└── LICENSE # MIT License
git clone https://github.com/prakhar2k06/Order-Book-Simulator.git
cd Order-Book-Simulator
pip install -r requirements.txt
python main.py
Note: Selecting View market snapshot will open the Plotly depth and trade tape visualizations in a separate browser window.
- Order modification ability
- Interactive web-based GUI with with live visuals
- Market impact modelling
- Event replay
This project is licensed under the MIT License.
