Fast & minimalist fixed decimal precision limit-order-book (LOB) implementation in pure Python with almost no dependencies.
Project description
fastlob | Fast Limit-Order-Book in Python
Fast & minimalist fixed decimal precision limit-order-book (LOB) implementation in pure Python with almost no dependencies.
Package currently in development, bugs are expected.
The goal is to build an efficient easy to use package with a clean and comprehensible API.
We aim to keep it minimalist and simple, while keeping reasonable performances (for a pure Python implementation). We intend the final project to contain no more than ~1000 lines of code.
We implement three types of orders: FOK, GTC and GTD. Every order is defined as a limit order, but will be executed as a market order if its price matches the best (bid or ask) limit price in the book.
In the case of GTD orders, the book only supports whole seconds for the order expiry (order can not be set to expire in 3.8 seconds, it will be rounded to 4).
Installation
The package is now available on PyPI, you can simply install it using
pip install fastlob
Otherwise, one can install it from source
git clone git@github.com:mrochk/fastlob.git
cd fastlob
pip install -r requirements.txt
pip install .
To run the tests and check that everything is okay, run make test or python3 -m unittest discover test.
Usage
This book runs at a fixed decimal precision through the Python decimal package. The precision can be set via the PYLOB_DECIMAL_PRECISION environment variable, the default value is 2.
# example.py
import time, logging
from fastlob import Orderbook, OrderParams, OrderSide, OrderType
lob = Orderbook(name='ABCD', log_level=logging.INFO) # init lob
lob.start() # start background processes
# every order must be created this way
params = OrderParams(
side=OrderSide.BID, # is it a buy or sell order
price=123.32, quantity=3.42, # by default runs at 2 digits decimal precision
otype=OrderType.GTD, # good-till-date order
expiry=time.time() + 120 # order will expire in two minutes
# since order is GTD, expiry must be set to some future timestamp
)
# -> at this point an exception will be raised if invalid attributes are provided
result = lob(params) # let the book process the order
assert result.success() # result object can be used to see various infos about the order execution
# order uuid is used to query our order after it's been placed
status, quantity_left = lob.get_order_status(result.orderid())
print(f'Current order status: {status.name}, quantity left: {quantity_left}.\n')
lob.render() # pretty-print the book
lob.stop() # stop the background processes
Contribute
As mentioned earlier, this package is still in early development, and contributions are more than welcome.
The main tasks that have to be done are:
- More and better testing for edge cases. Tests for the 3 types of orders have to be written.
- Benchmarking / profiling.
Lines count:
93 fastlob/engine/engine.py
1 fastlob/engine/__init__.py
18 fastlob/utils/utils.py
1 fastlob/utils/__init__.py
61 fastlob/result/result.py
0 fastlob/result/__init__.py
81 fastlob/order/params.py
1 fastlob/order/__init__.py
95 fastlob/order/order.py
47 fastlob/enums/enums.py
1 fastlob/enums/__init__.py
19 fastlob/consts/consts.py
0 fastlob/consts/__init__.py
99 fastlob/limit/limit.py
1 fastlob/limit/__init__.py
127 fastlob/side/side.py
1 fastlob/side/__init__.py
4 fastlob/__init__.py
471 fastlob/lob/orderbook.py
0 fastlob/lob/__init__.py
1121 total
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 fastlob-0.0.6.tar.gz.
File metadata
- Download URL: fastlob-0.0.6.tar.gz
- Upload date:
- Size: 43.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
54ac0945bf3c6a27a436c3bad2db093d78c42bca7c1cb8c0d72c1aace48567b3
|
|
| MD5 |
7afb9e5381b9453bc0c2fbfadb8581ed
|
|
| BLAKE2b-256 |
3c57c63c0ae3af24edbf2f3ec6317b77ac1f1e092490962fc504784fbf3e74f7
|
Provenance
The following attestation bundles were made for fastlob-0.0.6.tar.gz:
Publisher:
python-publish.yml on mrochk/fastlob
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastlob-0.0.6.tar.gz -
Subject digest:
54ac0945bf3c6a27a436c3bad2db093d78c42bca7c1cb8c0d72c1aace48567b3 - Sigstore transparency entry: 178261836
- Sigstore integration time:
-
Permalink:
mrochk/fastlob@d26b946e6e914aeb24aeaac4234883d4964f8fd0 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/mrochk
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@d26b946e6e914aeb24aeaac4234883d4964f8fd0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file fastlob-0.0.6-py3-none-any.whl.
File metadata
- Download URL: fastlob-0.0.6-py3-none-any.whl
- Upload date:
- Size: 18.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d30835a867bf86fd5c2f70f19c12e4e3a60fb5115c26c69bd9c9bdda50334845
|
|
| MD5 |
4c9afe7da910342e6acc0c0663f7bd49
|
|
| BLAKE2b-256 |
1efa01a49f8dc19fda000d718be348d44b69672f73a05b4aba26f439b3e2732b
|
Provenance
The following attestation bundles were made for fastlob-0.0.6-py3-none-any.whl:
Publisher:
python-publish.yml on mrochk/fastlob
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastlob-0.0.6-py3-none-any.whl -
Subject digest:
d30835a867bf86fd5c2f70f19c12e4e3a60fb5115c26c69bd9c9bdda50334845 - Sigstore transparency entry: 178261839
- Sigstore integration time:
-
Permalink:
mrochk/fastlob@d26b946e6e914aeb24aeaac4234883d4964f8fd0 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/mrochk
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@d26b946e6e914aeb24aeaac4234883d4964f8fd0 -
Trigger Event:
push
-
Statement type: