fastlob


Namefastlob JSON
Version 0.0.22 PyPI version JSON
download
home_pageNone
SummaryFast & minimalist limit-order-book (LOB) implementation in pure Python.
upload_time2025-07-26 02:58:45
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseNone
keywords exchange finance limit-order-book market order-book trading
VCS
bugtrack_url
requirements attrs hypothesis sortedcollections sortedcontainers termcolor
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # fastlob | Python Limit-Order-Book
<br>

**Fast & minimalist limit-order-book (LOB) implementation in Python, with almost no dependencies.**

<br>

<img src="https://github.com/mrochk/pylob/raw/main/logo.png" width=800>

*Package currently in development, bugs are expected.*

*This is the very first version of the project, the idea was to have a working, correct and clean single-threaded version before making it fast. The next step is to rewrite the core parts in a faster and concurrent fashion.*

*For now, I have decided to keep it written only in Python (no interfacing with C/C++), but that may change in the future.*

***

**Functionalities:**
- Place limit orders.
- Execute market orders.
- Orders can be good-till-cancel (GTC), fill-or-kill (FOK) or good-till-date (GTD).
- Cancel pending or partially filled orders.
- Query order status (pending, filled, partially filled, canceled...).
- Set custom tick size for price and quantities.
- Extract spread, midprice, volume, etc.
- Simulate on historical 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 ~1000 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).*

*We do not implement multi-threaded order processing yet, check out the corresponding issue for more infos.*

## Installation

The package is available on [PyPI](https://pypi.org/project/fastlob/), you can simply install it using
```
pip install fastlob
```

Otherwise, one can install it from source
```bash
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.

```python
# examples/basics.py

import time, logging

from fastlob import Orderbook, OrderParams, OrderSide, OrderType

logging.basicConfig(level=logging.INFO) # maximum logging

lob = Orderbook(name='MYLOB', start=True) # init and start lob

# 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
```

**For more examples please check out `https://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`
            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "fastlob",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "Maxime Rochkoulets <mrochkoulets@gmail.com>",
    "keywords": "exchange, finance, limit-order-book, market, order-book, trading",
    "author": null,
    "author_email": "Maxime Rochkoulets <mrochkoulets@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/08/be/11126ec40f0de751ce7be60952dfbfde10aac231052aef19f532d39121f4/fastlob-0.0.22.tar.gz",
    "platform": null,
    "description": "# fastlob | Python Limit-Order-Book\n<br>\n\n**Fast & minimalist limit-order-book (LOB) implementation in Python, with almost no dependencies.**\n\n<br>\n\n<img src=\"https://github.com/mrochk/pylob/raw/main/logo.png\" width=800>\n\n*Package currently in development, bugs are expected.*\n\n*This is the very first version of the project, the idea was to have a working, correct and clean single-threaded version before making it fast. The next step is to rewrite the core parts in a faster and concurrent fashion.*\n\n*For now, I have decided to keep it written only in Python (no interfacing with C/C++), but that may change in the future.*\n\n***\n\n**Functionalities:**\n- Place limit orders.\n- Execute market orders.\n- Orders can be good-till-cancel (GTC), fill-or-kill (FOK) or good-till-date (GTD).\n- Cancel pending or partially filled orders.\n- Query order status (pending, filled, partially filled, canceled...).\n- Set custom tick size for price and quantities.\n- Extract spread, midprice, volume, etc.\n- Simulate on historical data.\n\nThe goal is to build an efficient and easy to use package, with a clean and comprehensible API. \n\nWe 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.\n\nWe 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.\n\n*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).*\n\n*We do not implement multi-threaded order processing yet, check out the corresponding issue for more infos.*\n\n## Installation\n\nThe package is available on [PyPI](https://pypi.org/project/fastlob/), you can simply install it using\n```\npip install fastlob\n```\n\nOtherwise, one can install it from source\n```bash\ngit clone git@github.com:mrochk/fastlob.git\ncd fastlob\npip install -r requirements.txt\npip install .\n```\n\n## Testing\n\nTo run the tests and check that everything is okay, run `make test` or `python3 -m unittest discover test`.\n\n## Usage\n\nThis 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.\n\n```python\n# examples/basics.py\n\nimport time, logging\n\nfrom fastlob import Orderbook, OrderParams, OrderSide, OrderType\n\nlogging.basicConfig(level=logging.INFO) # maximum logging\n\nlob = Orderbook(name='MYLOB', start=True) # init and start lob\n\n# every order must be created this way \nparams = OrderParams(\n    side=OrderSide.BID, # is it a buy or sell order\n    price=123.32, quantity=3.42, # by default runs at 2 digits decimal precision\n    otype=OrderType.GTD, # good-till-date order\n    expiry=time.time() + 120 # order will expire in two minutes\n    # since order is GTD, expiry must be set to some future timestamp\n)\n\n# -> at this point an exception will be raised if invalid attributes are provided\n\nresult = lob(params) # let the book process the order\nassert result.success() # result object can be used to see various infos about the order execution\n\n# order uuid is used to query our order after it's been placed\nstatus, quantity_left = lob.get_order_status(result.orderid())\nprint(f'Current order status: {status.name}, quantity left: {quantity_left}.\\n')\n\nlob.render() # pretty-print the book\n\nlob.stop() # stop the background processes\n```\n\n**For more examples please check out `https://fastlob.com`.**\n\n## Contributing\n\nAs mentioned earlier, this package is still in early development, and contributions are more than welcome.\n\nPlease 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.\n\nMy e-mail: `mrochkoulets@gmail.com`",
    "bugtrack_url": null,
    "license": null,
    "summary": "Fast & minimalist limit-order-book (LOB) implementation in pure Python.",
    "version": "0.0.22",
    "project_urls": {
        "Homepage": "https://fastlob.com",
        "Repository": "https://github.com/mrochk/fastlob"
    },
    "split_keywords": [
        "exchange",
        " finance",
        " limit-order-book",
        " market",
        " order-book",
        " trading"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "f171c9288a8c97719ccd12eb8ea94dbf56fa17591f066eb70918c1e4092ba37c",
                "md5": "643b162c61f9da5eb3d82d2ec5889fd9",
                "sha256": "be21050018def8d6442b8b2b0c6c17ea3157d85f9d9c9d536d659460184ef6b6"
            },
            "downloads": -1,
            "filename": "fastlob-0.0.22-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "643b162c61f9da5eb3d82d2ec5889fd9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 24373,
            "upload_time": "2025-07-26T02:58:44",
            "upload_time_iso_8601": "2025-07-26T02:58:44.047439Z",
            "url": "https://files.pythonhosted.org/packages/f1/71/c9288a8c97719ccd12eb8ea94dbf56fa17591f066eb70918c1e4092ba37c/fastlob-0.0.22-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "08be11126ec40f0de751ce7be60952dfbfde10aac231052aef19f532d39121f4",
                "md5": "656bc0651c9558b78571472ef2d79b95",
                "sha256": "2626a26ec0e109bc09c6589bdfdcf53f1dd48f49bb6c456bb86f0a9042eea07d"
            },
            "downloads": -1,
            "filename": "fastlob-0.0.22.tar.gz",
            "has_sig": false,
            "md5_digest": "656bc0651c9558b78571472ef2d79b95",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 376443,
            "upload_time": "2025-07-26T02:58:45",
            "upload_time_iso_8601": "2025-07-26T02:58:45.477920Z",
            "url": "https://files.pythonhosted.org/packages/08/be/11126ec40f0de751ce7be60952dfbfde10aac231052aef19f532d39121f4/fastlob-0.0.22.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-26 02:58:45",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mrochk",
    "github_project": "fastlob",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "attrs",
            "specs": [
                [
                    "==",
                    "25.1.0"
                ]
            ]
        },
        {
            "name": "hypothesis",
            "specs": [
                [
                    "==",
                    "6.127.2"
                ]
            ]
        },
        {
            "name": "sortedcollections",
            "specs": [
                [
                    "==",
                    "2.1.0"
                ]
            ]
        },
        {
            "name": "sortedcontainers",
            "specs": [
                [
                    "==",
                    "2.4.0"
                ]
            ]
        },
        {
            "name": "termcolor",
            "specs": [
                [
                    "==",
                    "2.5.0"
                ]
            ]
        }
    ],
    "lcname": "fastlob"
}
        
Elapsed time: 0.97528s