Order Book Matching Engine
Project description
Order Book Matching Engine
Overview
This package is a simple order book matching engine implementation in Python. Its main features are:
- price-time priority
- limit and market orders
- order cancellation and expiration
- conversion into pandas DataFrame of orders, executed trades, order book summary
Install
pip install order-matching
Documentation
khrapovs.github.io/OrderBookMatchingEngine
Usage
>>> from datetime import datetime, timedelta
>>> from pprint import pp
>>> import pandas as pd
>>> from order_matching.matching_engine import MatchingEngine
>>> from order_matching.order import LimitOrder
>>> from order_matching.side import Side
>>> from order_matching.orders import Orders
>>> matching_engine = MatchingEngine(seed=123)
>>> timestamp = datetime(2023, 1, 1)
>>> transaction_timestamp = timestamp + timedelta(days=1)
>>> buy_order = LimitOrder(side=Side.BUY, price=1.2, size=2.3, timestamp=timestamp, order_id="a", trader_id="x")
>>> sell_order = LimitOrder(side=Side.SELL, price=0.8, size=1.6, timestamp=timestamp, order_id="b", trader_id="y")
>>> executed_trades = matching_engine.match(orders=Orders([buy_order, sell_order]), timestamp=transaction_timestamp)
>>> pp(executed_trades.trades)
[Trade(side=SELL,
price=1.2,
size=1.6,
incoming_order_id='b',
book_order_id='a',
execution=LIMIT,
trade_id='c4da537c-1651-4dae-8486-7db30d67b366',
timestamp=datetime.datetime(2023, 1, 2, 0, 0))]
Related Projects
Contribute
Install project in editable mode and sync all dependencies:
uv sync --all-groups --all-extras
and use pre-commit to make sure that your code is formatted and linted automatically:
uv run prek install
Run tests:
uv run pytest
Run benchmark and see the result either in the terminal or as a plot in benchmark_history.svg:
./benchmark.sh
Build and serve documentation website:
uv run mkdocs serve
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file order_matching-0.3.15.tar.gz.
File metadata
- Download URL: order_matching-0.3.15.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be07f96aacdf4d6ef3a7957e66605c8c315ae0235c27c8a434858a80ce6889f2
|
|
| MD5 |
d97d0e520a2c18d21d8a45c1e962a221
|
|
| BLAKE2b-256 |
c620e3ebd042b8b71ba22af5223febd65d955b43f9da4506ad0136fcd652edb6
|
File details
Details for the file order_matching-0.3.15-py3-none-any.whl.
File metadata
- Download URL: order_matching-0.3.15-py3-none-any.whl
- Upload date:
- Size: 11.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30180efb246fc63de4534721e381f51eaaf9f11753a60d6cf07d6d824f7a7917
|
|
| MD5 |
5d878a7209d56bb59d0edd8d9d4b9238
|
|
| BLAKE2b-256 |
716e2fcf3f2078ea8f5a057a09c2792c257aeea130cc157c2a380131ea7884c4
|