Fast & minimalist fixed decimal precision limit-order-book (LOB) implementation in pure Python.
Project description
fastlob | Python Limit-Order-Book
Fast & minimalist fixed decimal precision limit-order-book (LOB) implementation in pure Python.
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 the it minimalist and simple, while having 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).
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.
To be able to use this project, clone the repository and install the requirements:
git clone git@github.com:mrochk/pylob.git
cd pylob
pip install -r requirements.txt
To run tests, use make test or python3 -m unittest discover test.
Placing an order
import time
import fastlob as lob
book = lob.OrderBook('My Order-Book')
book.start()
# every order must be created this way
order_params = lob.OrderParams(
side=lob.OrderSide.BID,
price=123.32, # by default runs at 2 digits decimal precision
quantity=3.4,
otype=lob.OrderType.GTD, # good-till-date order
expiry=time.time() + 120 # expires in two minutes
)
# -> at this point an exception will be raised if invalid attributes are provided
result = book(order_params) # let the book process the order
assert result.success() # result object can be used to see various infos about the order execution
order_id = result.order_id() # unique id is used to query our order after it's been placed
status, quantity_left = book.get_order_status(order_id)
print(f'Current status of the order: {status}, quantity left: {quantity_left}.')
print(book.view()) # pretty-print the book
Lines count:
92 pylob/engine/engine.py
1 pylob/engine/__init__.py
18 pylob/utils/utils.py
1 pylob/utils/__init__.py
64 pylob/order/params.py
1 pylob/order/__init__.py
161 pylob/order/order.py
52 pylob/enums/enums.py
1 pylob/enums/__init__.py
64 pylob/orderbook/result.py
361 pylob/orderbook/orderbook.py
1 pylob/orderbook/__init__.py
19 pylob/consts/consts.py
1 pylob/consts/__init__.py
137 pylob/limit/limit.py
1 pylob/limit/__init__.py
156 pylob/side/side.py
1 pylob/side/__init__.py
4 pylob/__init__.py
1136 total
TODOs:
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. In fact, some tests have to be rewritten too.
- Benchmarking / profiling to have an idea of the performance, and see where it's slow.
- Some parts probably need to be rewritten in a cleaner way.
- Publish the package on pypi.
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.2.tar.gz.
File metadata
- Download URL: fastlob-0.0.2.tar.gz
- Upload date:
- Size: 143.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b064e366d462caaaf3662484df4d86278f37ad058fc1d698d33c44d6041e1d5d
|
|
| MD5 |
bebe52cf9b54be607e97711845a1d975
|
|
| BLAKE2b-256 |
31c18a65f164e8eb8e07bc86e4f3926e43d7c80e2461194ed5f0782e7ca83fe9
|
Provenance
The following attestation bundles were made for fastlob-0.0.2.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.2.tar.gz -
Subject digest:
b064e366d462caaaf3662484df4d86278f37ad058fc1d698d33c44d6041e1d5d - Sigstore transparency entry: 176873237
- Sigstore integration time:
-
Permalink:
mrochk/fastlob@6aa03d19c460b67bd85c156b62d8207b7df5ca58 -
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@6aa03d19c460b67bd85c156b62d8207b7df5ca58 -
Trigger Event:
push
-
Statement type:
File details
Details for the file fastlob-0.0.2-py3-none-any.whl.
File metadata
- Download URL: fastlob-0.0.2-py3-none-any.whl
- Upload date:
- Size: 16.9 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 |
351b8c7978fa9b69c2072b3fab522896ecb177d65fb42ce9a2994d6599ce653a
|
|
| MD5 |
22f877b4493699b6a19f3b4bfda4f21e
|
|
| BLAKE2b-256 |
d34414179fd7f5aa9fc21bb2e61e607f4f548e8eaa557f8608b2be290d990c25
|
Provenance
The following attestation bundles were made for fastlob-0.0.2-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.2-py3-none-any.whl -
Subject digest:
351b8c7978fa9b69c2072b3fab522896ecb177d65fb42ce9a2994d6599ce653a - Sigstore transparency entry: 176873238
- Sigstore integration time:
-
Permalink:
mrochk/fastlob@6aa03d19c460b67bd85c156b62d8207b7df5ca58 -
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@6aa03d19c460b67bd85c156b62d8207b7df5ca58 -
Trigger Event:
push
-
Statement type: