fastlob | Python Limit-Order-Book
Limit-order-book (LOB) implementation in Python, with almost no dependencies.
Package currently in development.
For now, I have decided to keep this project in pure Python (no interfacing with C/C++), but that may change in the future.
A limit-order book is a useful tool for anyone working with high-frequency market data, and sometimes you just want to be able to quickly start one, feed your data and extract features.
fastlob is not well named, the goal is not to be fast, but rather to provide a simple and useful implementation. Otherwise this would not be written in Python.
But if you want to quickly prototype a trading strategy, or analyze some historical data, this is the right package for you.
This project was mainly born from the lack of good order-book packages in Python.
Functionalities:
- Place limit orders.
- Execute market orders.
- Orders can be good-till-cancel (GTC), fill-or-kill (FOK) or good-till-date (GTD).
- Cancel / update pending or partially filled orders.
- Query order status (pending, filled, partially filled, canceled...).
- Set custom tick size for price and quantities.
- Extract lob features: spread, midprice, volume, imbalance...
- Simulate historical market data.
The goal is to build an efficient and 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 2000 lines of code.
We implement three types of orders: FOK, GTC and GTD. Every order is initially defined as limit, 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, in this case it will be rounded to 4, nearest integer).
Installation
The package is 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 .
Testing
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 decimal precision (also called tick size) can be set via the FASTLOB_DECIMAL_PRECISION_PRICE and FASTLOB_DECIMAL_PRECISION_QTY environment variables, if not set it defaults to 2.
# examples/quickstart.py
import time, logging
from fastlob import (
Orderbook,
OrderParams,
OrderSide,
OrderType,
)
logging.basicConfig(level=logging.INFO) # maximum logging
with Orderbook(name='example') as lob: # init and start lob in cm
# 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_status(result.orderid())
print(f'Current order status: {status.name}, quantity left: {quantity_left}.\n')
lob.render() # pretty-print the book state
# if lob not started using context manager, must call lob.stop() before terminating
For more examples please check out fastlob.com.
Contributing
As mentioned earlier, this package is still in early development, and contributions are more than welcome.
Please do not hesitate to contact me or directly submit a pull request if you'd like to contribute, there are also various issues open on Github.
My e-mail: mrochkoulets@gmail.com
Metadata
Release files for fastlob 0.0.24
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| fastlob-0.0.24.tar.gz | 381.3 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fastlob-0.0.24-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 406.5 kB
Release files / fastlob-0.0.24.tar.gz
| Download URL | fastlob-0.0.24.tar.gz |
|---|---|
| Size | 381.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9a1c39971125c572be76002f46eecb09b14b64cec4916f6e297a0c281bfe45f1
|
|
BLAKE2b-256 checksum How to use checksums |
46a83ded8c531e970f05546ab61298279d30a595c75f93415c243ab256841e15
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 1, 2026.
Transparency logRelease files / fastlob-0.0.24-py3-none-any.whl
| Download URL | fastlob-0.0.24-py3-none-any.whl |
|---|---|
| Size | 25.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a612aa46eb52ea749094f6c473f796535397d70e0a5bd0d1bfb97a756df276d1
|
|
BLAKE2b-256 checksum How to use checksums |
699cbd9f59e81abc63cf1789def111e8266b73d93ab378287d5733e4eac21f80
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 1, 2026.
Transparency logSecurity for fastlob 0.0.24
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for fastlob-0.0.24.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 1, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.