Skip to content

A compact limit order book and matching engine simulator designed to model exchange behavior. It runs events deterministically, logs precise timing, and makes it easy to experiment with order flow, matching rules, and latency effects.

Notifications You must be signed in to change notification settings

aboderinsamuel/hft-simulator

Repository files navigation

Mini Trading System (C++)

A small, beginner-friendly simulation of how real electronic trading systems work. This project includes:

  • A market data feed (simulated prices)
  • A limit order book
  • A matching engine (matches buy & sell orders)
  • UDP networking to broadcast trades
  • Latency measurement (microseconds)

It’s a simplified version of how exchanges like NASDAQ/NYSE actually behave.

How the System Works

FeedHandler → generates fake market prices
TradingSystem → creates random buy/sell orders
MatchingEngine → matches orders using price–time priority
Trades → logged + sent out via UDP

Components

FeedHandler

Simulates live market data for AAPL, GOOGL, MSFT, AMZN.

OrderBook

Stores and sorts bids/asks with price-time priority.

MatchingEngine

Matches orders when best bid ≥ best ask and generates trades.

UDPMessenger

Broadcasts trades using UDP in CSV format.

TradingSystem

Coordinates everything, generates random orders, measures latency, prints summary.

Build & Run

mkdir build && cd build
cmake ..
make
./trading_system

Output Example

[FEED] AAPL @ 152.34 x 3421
[ORDER] Buy AAPL 320 @ 151.42 (Latency: 10.54 μs)
[TRADE] AAPL 100 @ 152.10 (E2E: 24.31 μs)

Latency stats + order book summary printed at end.

About

A compact limit order book and matching engine simulator designed to model exchange behavior. It runs events deterministically, logs precise timing, and makes it easy to experiment with order flow, matching rules, and latency effects.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published