Order Book Matching Engine
Project description
Order Book Matching Engine
Install
pip install order-matching
Usage
>>> 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)
>>> print(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'))]
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
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
order-matching-0.3.1.tar.gz
(18.7 kB
view hashes)
Built Distribution
Close
Hashes for order_matching-0.3.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01c7bae8f4e7f32688c755c7454cdccc5eedcfd7e735dc131cc60cf936e3fb39 |
|
MD5 | f56540826b1d915fd716aa31e1d607bc |
|
BLAKE2b-256 | c87cdff25a7939315e623aea201c33eff48badbdf7bbc23e2566caeb5b957dcd |