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 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
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
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.7.tar.gz.
File metadata
- Download URL: order_matching-0.3.7.tar.gz
- Upload date:
- Size: 80.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0eb634555e309340031d1fe5f89e29a1d33693b28e761550c26a6f20402af4f9
|
|
| MD5 |
829d49665280767f19702083f47a7d5a
|
|
| BLAKE2b-256 |
1d3c4e9c1e73ac7c9be28b4ab3926c97f2412a5a50fa14bc5400fd6378a9b949
|
Provenance
The following attestation bundles were made for order_matching-0.3.7.tar.gz:
Publisher:
workflow.yaml on khrapovs/OrderBookMatchingEngine
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
order_matching-0.3.7.tar.gz -
Subject digest:
0eb634555e309340031d1fe5f89e29a1d33693b28e761550c26a6f20402af4f9 - Sigstore transparency entry: 151294663
- Sigstore integration time:
-
Permalink:
khrapovs/OrderBookMatchingEngine@0defe5db659e21d06f2a23bf147cdd7f149bf9c4 -
Branch / Tag:
refs/tags/0.3.7 - Owner: https://github.com/khrapovs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yaml@0defe5db659e21d06f2a23bf147cdd7f149bf9c4 -
Trigger Event:
push
-
Statement type:
File details
Details for the file order_matching-0.3.7-py3-none-any.whl.
File metadata
- Download URL: order_matching-0.3.7-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 |
87917d862625e4b1c56cfd9d54d272769fa1ef81c8682947e15826e6da66d448
|
|
| MD5 |
ba589a2f9028a13bc78ff0924097b149
|
|
| BLAKE2b-256 |
c7f5ed9213c35bc078e46f19d906fdc1e99cf78c7a7e1a76ead85f770314fa48
|
Provenance
The following attestation bundles were made for order_matching-0.3.7-py3-none-any.whl:
Publisher:
workflow.yaml on khrapovs/OrderBookMatchingEngine
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
order_matching-0.3.7-py3-none-any.whl -
Subject digest:
87917d862625e4b1c56cfd9d54d272769fa1ef81c8682947e15826e6da66d448 - Sigstore transparency entry: 151294665
- Sigstore integration time:
-
Permalink:
khrapovs/OrderBookMatchingEngine@0defe5db659e21d06f2a23bf147cdd7f149bf9c4 -
Branch / Tag:
refs/tags/0.3.7 - Owner: https://github.com/khrapovs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yaml@0defe5db659e21d06f2a23bf147cdd7f149bf9c4 -
Trigger Event:
push
-
Statement type: