Skip to content

prakhar2k06/Order-Book-Simulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Order-Book-Simulator

Order Book CLI
CLI-based order book view

Overview

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.

What is an Order Book?

A limit order book (LOB) is the core data structure used by electronic exchanges to match buyers and sellers, thus executing trades.

Key concepts:

  • 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.

Features

  • Price-time priority (FIFO)
  • Market and limit orders
  • Order cancellation
  • Automatic random trade generation
  • Static market snapshot visualizations (depth and trade tape)

Project Structure

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

Setup and Running Instructions

1. Clone the repository

git clone https://github.com/prakhar2k06/Order-Book-Simulator.git

2. Change directory

cd Order-Book-Simulator

3. Install requirements

pip install -r requirements.txt

4. Run CLI

python main.py

Note: Selecting View market snapshot will open the Plotly depth and trade tape visualizations in a separate browser window.

Future Improvements

  • Order modification ability
  • Interactive web-based GUI with with live visuals
  • Market impact modelling
  • Event replay

License

This project is licensed under the MIT License.

About

No description or website provided.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages