Skip to content

Capstone · C++ Programming (modern C++ and DSA)

Capstone: a stock exchange order book

Capstoneexpert· about 16 hours· 10 steps

The brief

Build the heart of a stock exchange: a limit order book that matches buy and sell orders by price and then by time, handles cancels and bad input, reports VWAP, passes its unit tests under AddressSanitizer and processes a million orders in well under ten seconds. It is a complete CMake project with a README, ready for GitHub and your CV.

Why it matters

Order books are what NSE and BSE run for every listed share, and what trading firms, brokers and fintechs in Mumbai, Bengaluru and Gurugram build and test in C++. Interviewers for C++ roles in trading and low-latency systems ask about exactly this design: which containers, what each operation costs, and how you proved it correct and fast. A clean, tested order book on GitHub is one of the strongest C++ portfolio projects you can show.

Skills you practise

  • CMake with libraries, programs and ctest
  • std::map with std::greater, std::deque, std::unordered_map
  • std::optional and std::string_view
  • exceptions for bad input
  • unit tests
  • AddressSanitizer and UBSan
  • benchmarking with <chrono>
  • writing a README

You need

  • g++ 11 or newer (MinGW-w64 via MSYS2 on Windows, build-essential on Ubuntu, Xcode command line tools on macOS, where g++ runs Apple clang)
  • CMake 3.20 or newer (cmake --version), with Make or Ninja; on Windows MSYS2 (pacman -S mingw-w64-ucrt-x86_64-cmake) or the Visual Studio generator
  • A bash shell (Git Bash on Windows; WSL for the sanitizer step)
  • A GitHub account if you want to publish it (optional)

What you will have at the end

A GitHub-ready CMake project: an order book library with price-time matching, cancels and error handling, the obook replay and benchmark tool, two test programs passing under ctest and the sanitizers, and a README with the design and performance.

How it is marked (rubric, 100 points)
Correct matchingEvery replay check passes: price-time priority, trades at the resting price, partial fills, cancels, errors and VWAP.35
Tests and toolingTwo test programs under ctest, clean with warnings on, clean under AddressSanitizer and UBSan.25
Design and performanceSensible containers with known costs, no needless copies, a million orders in well under ten seconds in Release.20
PresentationA clear README (what, how to build, design, numbers) and code a reviewer can follow.20

0/10 steps done

Step 1 of 10

The project builds

cmake builds obook_core, obook, parse_tests and book_tests with no warnings, and ctest knows both test programs.

Save the files in one folder (the .txt files are the order files you will replay). Write CMakeLists.txt: a library obook_core from orders.cpp, the program obook and two test programs, each linked to the library, with warnings on for every target. Register both test programs with add_test after enable_testing(). The stubs compile, so a correct CMakeLists.txt gives a clean build now.

add_library(obook_core orders.cpp)
target_include_directories(obook_core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

add_executable(obook main.cpp)
target_link_libraries(obook PRIVATE obook_core)

enable_testing()
foreach(t parse_tests book_tests)
  string(REPLACE "_tests" "_test.cpp" src ${t})
  add_executable(${t} ${src})
  target_link_libraries(${t} PRIVATE obook_core)
  add_test(NAME ${t} COMMAND ${t})
endforeach()
One library, one program and two test programs; add the warning options for every target too.
Run this on your machine, then paste the output below
$ cmake -S . -B build; cmake --build build --clean-first
Your notes: CMakeLists.txt, orders.h, orders.cpp, main.cpp, parse_test.cpp, book_test.cpp, README.md

Write down each command you ran. It goes into your project summary.