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
order-book-matching-engine.readthedocs.io
Usage
>>> 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 = pd.Timestamp("2023-01-01")
>>> transaction_timestamp = timestamp + pd.Timedelta(1, unit="D")
>>> 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=Timestamp('2023-01-02 00:00:00'))]
Related Projects
Contribute
Create a virtual environment and activate it:
python -m venv venv
source venv/bin/activate
Install development dependencies:
pip install -e .[dev]
and use pre-commit to make sure that your code is formatted using black and isort automatically:
pre-commit install
Run tests:
pip install -e .[test]
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:
pip install -e .[doc]
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
File details
Details for the file order_matching-0.3.6.tar.gz
.
File metadata
- Download URL: order_matching-0.3.6.tar.gz
- Upload date:
- Size: 80.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a165195e8f6987a3ff2f8fde02e3e96c0c3a8b4e00ff9358eb321012820b26e1 |
|
MD5 | 671d48c0f8b91abaf23bc6a079c97308 |
|
BLAKE2b-256 | 90036f90422dc9a0f0b5dd0fabce9337c83a7f865ca61326fb0b1805ca3e8326 |
Provenance
The following attestation bundles were made for order_matching-0.3.6.tar.gz
:
Publisher:
workflow.yaml
on khrapovs/OrderBookMatchingEngine
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
order_matching-0.3.6.tar.gz
- Subject digest:
a165195e8f6987a3ff2f8fde02e3e96c0c3a8b4e00ff9358eb321012820b26e1
- Sigstore transparency entry: 150465407
- Sigstore integration time:
- Predicate type:
File details
Details for the file order_matching-0.3.6-py3-none-any.whl
.
File metadata
- Download URL: order_matching-0.3.6-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b9c7e13ddb82fc50b1c9de0b09b199bf8eb5f8f307d0885d137b677bc0aacc6 |
|
MD5 | d18398e53524be88196c37ebab8f8a71 |
|
BLAKE2b-256 | 16dff1a7caa1c26983648445d6e3de052bc01963b94b8b579ff83c3eb3d93953 |
Provenance
The following attestation bundles were made for order_matching-0.3.6-py3-none-any.whl
:
Publisher:
workflow.yaml
on khrapovs/OrderBookMatchingEngine
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
order_matching-0.3.6-py3-none-any.whl
- Subject digest:
6b9c7e13ddb82fc50b1c9de0b09b199bf8eb5f8f307d0885d137b677bc0aacc6
- Sigstore transparency entry: 150465408
- Sigstore integration time:
- Predicate type: