Limit Order Book
This is a header-only C++ implementation of the limit order book with a price-time priority matching policy for reception of market data streams. The C++ library is the primary product; a C API and a Python package with Cython bindings to the C++ book are also provided.
The technical report explains the design's prior work, matching semantics, implementation limits, and reproducible evaluation. Its LaTeX source and raw measurements are included.
Usage
C++
The library is header-only and requires C++14. It depends on three header-only
libraries that are vendored in vendor/ and installed with it:
binary-search-tree, doubly-linked-list, and robin-map. Every method
below provides the limit_order_book::limit_order_book target, or the include
path, so that this works:
#include "limit_order_book.hpp"
int main() {
LOB::LimitOrderBook book;
book.limit(LOB::Side::Sell, 1, 100, 50);
book.limit(LOB::Side::Buy, 2, 40, 50); // crosses and partially fills
return book.best_sell() == 50 ? 0 : 1;
}
CMake FetchContent
Add the library to a CMake project without installing it. Pin GIT_TAG to a
release tag or commit:
include(FetchContent)
FetchContent_Declare(
limit_order_book
GIT_REPOSITORY https://github.com/Kautenja/limit-order-book.git
GIT_TAG master
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(limit_order_book)
target_link_libraries(my_app PRIVATE limit_order_book::limit_order_book)
As a subproject, the library builds no tests, benchmarks, or shared library.
add_subdirectory on a copy of this repository works the same way.
LOB_BUILD_EXAMPLES is deprecated and has no effect. It remains accepted
with a default of OFF for compatibility with existing CMake configurations.
System Installation
Install the headers, a CMake package, and a pkg-config file. This requires CMake 3.21 or later and a C++14 compiler:
git clone https://github.com/Kautenja/limit-order-book.git
cd limit-order-book
cmake -S . -B .build/cmake -DLOB_BUILD_TESTS=OFF -DLOB_BUILD_PYTHON_LIBRARY=OFF
cmake --install .build/cmake --prefix /usr/local
Use any prefix, such as "${HOME}/.local", and sudo when the prefix needs
it. The install puts every header in include/limit_order_book/, the CMake
package in share/cmake/limit_order_book/, the pkg-config file in
share/pkgconfig/, and the licenses in share/doc/limit_order_book/. Then
use the package from CMake:
find_package(limit_order_book 3 CONFIG REQUIRED)
target_link_libraries(my_app PRIVATE limit_order_book::limit_order_book)
or from any build system through pkg-config:
c++ -std=c++14 $(pkg-config --cflags limit_order_book) my_app.cpp
Copying The Headers
Copy include/ and the include/ directories of the three vendored
dependencies into your project, and add all four to the include path.
C
The C API in include/limit_order_book_c.h is
a C99 header that wraps the book in an opaque LOB_LimitOrderBook handle.
Build and install it with LOB_BUILD_C_LIBRARY=ON. C consumers do not need
Python or Cython:
cmake -S . -B .build/cmake -DLOB_BUILD_TESTS=OFF \
-DLOB_BUILD_PYTHON_LIBRARY=OFF -DLOB_BUILD_C_LIBRARY=ON
cmake --build .build/cmake
cmake --install .build/cmake --prefix /usr/local
The install adds limit_order_book_c.h to include/limit_order_book/, the
liblimit_order_book shared library to lib/, and a
limit_order_book_c.pc pkg-config file to lib/pkgconfig/. Because the
package now holds a compiled library, the CMake package moves to
lib/cmake/limit_order_book/. Link the limit_order_book::c target:
find_package(limit_order_book 3 CONFIG REQUIRED COMPONENTS c)
target_link_libraries(my_app PRIVATE limit_order_book::c)
or use pkg-config:
cc $(pkg-config --cflags limit_order_book_c) my_app.c \
$(pkg-config --libs limit_order_book_c)
A FetchContent or add_subdirectory consumer gets limit_order_book::c by
setting LOB_BUILD_C_LIBRARY to ON before adding the project.
Python
The preferred Python installation of limit-order-book is from pip:
pip install limit-order-book
Wheels are published for CPython 3.13 and 3.14 on Linux (x64, arm64), macOS (x64, arm64), and Windows (x64). Other platforms build from the source distribution and need a C++14 compiler and Python development headers. The source build installs Cython as an isolated build dependency; installed wheels do not need Cython or a separate C API shared library.
The public LimitOrderBook class calls C++ through the compiled
limit_order_book._native extension. Existing imports and methods are
preserved:
from limit_order_book import LimitOrderBook
book = LimitOrderBook()
book.limit_sell(order_id=1, quantity=100, price=50)
book.market_buy(order_id=2, quantity=40)
assert book.volume_sell(50) == 60
Usage Caveats
Windows
You'll need to install the Visual-Studio 17.0 tools for Windows installation. The Visual Studio Community package provides these tools for free.
Development
See the documentation index for contributor guidance, style guides, and reference material.
main.sh wraps the CMake and Python commands; run ./main.sh -h for
the full list. Development needs CMake 3.21 or later, a C++14 compiler, Git
(CMake fetches Catch2 for the tests), and Python 3.13 or later. Set up a
virtual environment with the build tools:
./main.sh install
Testing
To run the C++ and Python test suites, run:
./main.sh test
To run them separately, run ./main.sh test-cpp or ./main.sh test-python.
The C++ suite runs through ctest; the Python suite runs against the Cython
extension that the CMake build copies into limit_order_book/. The C++-only
commands do not require Python or Cython. To check that
the installed CMake package and FetchContent both work for a consumer
project, run:
./main.sh test-package
Benchmarking
To run the C++ benchmarks, run:
./main.sh benchmark
Arguments after benchmark go to the Catch2 runner, such as a test name.
To benchmark Python queries, order entry/cancellation, and matching:
./main.sh benchmark-python --loops 100000 --repeats 9 --output /tmp/lob-before.json
# Rebuild after changing the bindings, then compare on the same machine.
./main.sh benchmark-python --loops 100000 --repeats 9 --compare /tmp/lob-before.json
The runner reports median and minimum/maximum nanoseconds per Python method call, checks final book state outside the timed region, and compares matched runs. See Python bindings for the build contract and measurement procedure.
Each measured iteration uses an independent empty book, with book construction and cleanup outside the timed workload. Results from the earlier benchmarks that reused book state are not directly comparable.
Build Outputs
Native and Python build outputs go to the root .build/: the CMake build in
.build/cmake/, Python builds in .build/python/, and distributions from
./main.sh deployment in .build/dist/. Build the technical report with
make -C docs/whitepaper; its PDF is
docs/whitepaper/.build/limit-order-book.pdf. Both .build directories are
ignored by Git. To remove the build outputs, run:
./main.sh clean
Releasing
The CI workflow runs the C++ suites and the
installed-package and FetchContent checks on Linux, macOS, and Windows, and
the Python suite and distribution builds for CPython 3.13 and 3.14 on the same
platforms. It also builds the technical report from the archived evidence.
It runs on pull requests, pushes to master, and tag pushes.
To release, update VERSION in the project() call of
CMakeLists.txt, which sets both the C++ package and the
Python package versions, then push a tag that matches it, optionally prefixed
with v. Tag CI waits for the report and package checks, then creates or
updates a GitHub release with the distributions and limit-order-book.pdf.
Manually published releases also build and attach their tag's report through
the report workflow. Publish that release to
start the
Publish to PyPI workflow, which builds the
sdist and wheels and uploads them through the pypi environment's trusted
publisher. A release created by the CI workflow's token does not trigger
another workflow, so if publishing does not start, dispatch the workflow
manually against the release tag:
gh workflow run publish.yml --ref <tag>
Citation
Please use the same limit-order-book citation for the software and its
technical report, including the implementation
analysis and measurements. They are one project with one preferred citation.
Download CITATION.bib or copy the BibTeX entry below. CITATION.cff provides the same preferred citation for GitHub's Cite this repository feature. Please also identify the software version or commit used in your research, and the report revision and evidence manifest when referring to measurements.
@misc{kauten-limit-order-book-2019,
author = {Christian Kauten},
howpublished = {GitHub},
title = {{L}imit {O}rder {B}ook: A Price-Time Priority Matching Engine for {C++}, {C}, and {P}ython},
URL = {https://github.com/Kautenja/limit-order-book},
year = {2019},
}
Licensing
The repository declares the MIT License. See
LICENSING.md for the scope of that grant, the licenses of the
vendored dependencies, and the third-party reference material in
docs/references/.
Metadata
Release files for limit-order-book 3.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| limit_order_book-3.0.0.tar.gz | 85.3 kB | With provenance | Details for limit_order_book-3.0.0.tar.gz |
Built distributions (wheels)
Total release size: 650.7 kB
Release files / limit_order_book-3.0.0.tar.gz
| Download URL | limit_order_book-3.0.0.tar.gz |
|---|---|
| Size | 85.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
60ed5a714b46a18a2e5e2bc52dab537e1c961b475d54985a2e34a5bcacfc0d52
|
|
BLAKE2b-256 checksum How to use checksums |
c28f349b31cfd7b7b4f12584fb5480e5964568ea199730ca5fb4c91f67d8bda6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.
Transparency logRelease files / limit_order_book-3.0.0-cp314-cp314-win_amd64.whl
| Download URL | limit_order_book-3.0.0-cp314-cp314-win_amd64.whl |
|---|---|
| Size | 58.1 kB |
| Tags | CPython 3.14 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
17d67e81042f9b0fa08ae77a8f51d410d44a7df14092677e981fa2fddef673d6
|
|
BLAKE2b-256 checksum How to use checksums |
21bd41aa1200aa1d8759dd1d0435efc5f1c90d87c5eb8ca348a02c8a044ae5a8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.
Transparency logRelease files / limit_order_book-3.0.0-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | limit_order_book-3.0.0-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 60.8 kB |
| Tags | CPython 3.14 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
f3deac8f089a62064b989d86e938098c59eaaaee0a9be897b6164944875c5873
|
|
BLAKE2b-256 checksum How to use checksums |
e2a2e61ee495b85245f7ad39614dd8240102c1a47f16748a051b0c13c6637764
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.
Transparency logRelease files / limit_order_book-3.0.0-cp314-cp314-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
| Download URL | limit_order_book-3.0.0-cp314-cp314-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl |
|---|---|
| Size | 59.8 kB |
| Tags | CPython 3.14 Linux glibc 2.24+ ARM64 Linux glibc 2.28+ ARM64 |
|
SHA-256 checksum How to use checksums |
0df0778a8fa6d6181433608ec0f785c2d567b445cdc2a71c1234650f772ad558
|
|
BLAKE2b-256 checksum How to use checksums |
cfbf6cae44599e794549733cb0fedddd8a70d7560a0a26ae3251c79f21a838fb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.
Transparency logRelease files / limit_order_book-3.0.0-cp314-cp314-macosx_11_0_arm64.whl
| Download URL | limit_order_book-3.0.0-cp314-cp314-macosx_11_0_arm64.whl |
|---|---|
| Size | 50.9 kB |
| Tags | CPython 3.14 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
9eded1bf202fc806f703db6e974a8daa625c5a2eb12b147f1d6d36724f3698dc
|
|
BLAKE2b-256 checksum How to use checksums |
556a842f676cc9276ae6054262c13ed5b525ce6a3e5d84f3d217558644c36b0d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.
Transparency logRelease files / limit_order_book-3.0.0-cp314-cp314-macosx_10_15_x86_64.whl
| Download URL | limit_order_book-3.0.0-cp314-cp314-macosx_10_15_x86_64.whl |
|---|---|
| Size | 54.3 kB |
| Tags | CPython 3.14 macOS 10.15+ x86-64 |
|
SHA-256 checksum How to use checksums |
6fb9407bd804cabf457960f032f28e363a266fd4fc31a93462b14f83168f2f0a
|
|
BLAKE2b-256 checksum How to use checksums |
5cc29c2ab4a1e4a1b2e9b5f5be92f8271d1056734fc9464ae47d41331d87e7e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.
Transparency logRelease files / limit_order_book-3.0.0-cp313-cp313-win_amd64.whl
| Download URL | limit_order_book-3.0.0-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 56.7 kB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
30ad12b456f2a4d33d15404f2e03792ef3bcd0042e2bc33c0b0a4742e531601c
|
|
BLAKE2b-256 checksum How to use checksums |
220122f5922aa5a0c817b120b83ca777126f8d66af629fb2584b3fc64d64b0e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.
Transparency logRelease files / limit_order_book-3.0.0-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | limit_order_book-3.0.0-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 60.8 kB |
| Tags | CPython 3.13 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
56f0d9cbbe92cd93daba44053f38b2854f4cbfeb344abf91404e1ab0a6ed741f
|
|
BLAKE2b-256 checksum How to use checksums |
8c5de397017971c9410ae35c967f23035fd6d6c3d969a3442baa29226acb7843
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.
Transparency logRelease files / limit_order_book-3.0.0-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
| Download URL | limit_order_book-3.0.0-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl |
|---|---|
| Size | 59.6 kB |
| Tags | CPython 3.13 Linux glibc 2.24+ ARM64 Linux glibc 2.28+ ARM64 |
|
SHA-256 checksum How to use checksums |
b9373963eb970f90a9e9ba2fa5e734c9f29a41cefee96d094cf6f4adc34cc7bd
|
|
BLAKE2b-256 checksum How to use checksums |
3d1285c85d32d8fafc7b3fe7fb9197c00986916506344c5983d80a4b4d889ef5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.
Transparency logRelease files / limit_order_book-3.0.0-cp313-cp313-macosx_11_0_arm64.whl
| Download URL | limit_order_book-3.0.0-cp313-cp313-macosx_11_0_arm64.whl |
|---|---|
| Size | 50.6 kB |
| Tags | CPython 3.13 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
fef7fc696f471a942d2a454890f840c8c51e58e6af0ea01866df4593a03fae92
|
|
BLAKE2b-256 checksum How to use checksums |
ecea24354676e6d0293aeaa52ec3e74f48d3904bb68b85343f22e4ae9c8cabaf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.
Transparency logRelease files / limit_order_book-3.0.0-cp313-cp313-macosx_10_13_x86_64.whl
| Download URL | limit_order_book-3.0.0-cp313-cp313-macosx_10_13_x86_64.whl |
|---|---|
| Size | 53.9 kB |
| Tags | CPython 3.13 macOS 10.13+ x86-64 |
|
SHA-256 checksum How to use checksums |
fbdeeca44f30bb6c77fa41f224635fecd5241b4b79945889a5b32e7c4099b747
|
|
BLAKE2b-256 checksum How to use checksums |
62434ec0ad15310b8dec9d65fa24115a7b80fde3c65b3eb3d3154575ac8f566d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.
Transparency logSecurity for limit-order-book 3.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 11 files in this release have been uploaded with provenance metadata.
Attestation for limit_order_book-3.0.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.