pyorderbook


Namepyorderbook JSON
Version 0.4.9 PyPI version JSON
download
home_pageNone
SummaryOrder Book and Matching Engine
upload_time2025-02-25 02:02:36
maintainerNone
docs_urlNone
authorNone
requires_python>=3.11
licenseMIT License Copyright (c) 2021-present PyO3 Project and Contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords limit order book matching engine order book orderbook pyorderbook
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # PyOrderBook
[![Project CI](https://github.com/zkhorozianbc/pyorderbook/actions/workflows/project-ci.yml/badge.svg?refresh=1)](https://github.com/zkhorozianbc/pyorderbook/actions/workflows/project-ci.yml)
[![PyPI version](https://img.shields.io/pypi/v/pyorderbook.svg)](https://pypi.org/project/pyorderbook/)
[![Python Versions](https://img.shields.io/pypi/pyversions/pyorderbook.svg)](https://pypi.org/project/pyorderbook/)
[![License](https://img.shields.io/github/license/zkhorozianbc/pyorderbook.svg)](https://github.com/zkhorozianbc/pyorderbook/blob/main/LICENSE)

PyOrderBook is a pure Python implementation of a limit order book and matching engine.

## Features

- **Order Matching Engine**
- **Order Cancellation**
- **Detailed Trade Blotter**

## Usage

```python
from pyorderbook import Book, bid, ask

# Create a new order book
book = Book()

# Process some orders
book.match(bid("IBM", 3.5, 20))
book.match(ask("IBM", 3.6, 10))
trade_blotter = book.match(ask("IBM", 3.5, 10))

# Print trade blotter
print(trade_blotter)
```

## Installation

To install the package, use:

```sh
# pip
pip install pyorderbook
# uv
uv pip install pyorderbook
# or 
uv add pyorderbook
```

## System Requirements
- Python 3.11+


## Design

- **Price Levels**: Stored in a heap of dataclasses, each with a price attribute and orders attribute. Orders are stored in a dictionary within each price level. New price levels are created when an unseen price is received for a symbol/side, and standing price levels are deleted when there are no more orders in the queue at that price level.
- **Order Queueing**: Unfilled orders are enqueued to the tail of the corresponding symbol/side/price queue, maintaining insertion order.
- **Matching Logic**: Iterates through the price level heap (descending order for bids, ascending for asks) and dequeues from the head of each matching price level until the level or incoming order quantity is exhausted.
- **Order Cancellation**: Uses a reference map from order ID to its encompassing price level. The order is popped from the price level and the reference map.
- **Precision**: Uses `decimal.Decimal` objects to store prices to avoid floating point arithmetic problems.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pyorderbook",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": null,
    "keywords": "limit order book, matching engine, order book, orderbook, pyorderbook",
    "author": null,
    "author_email": "Zach Khorozian <zkhorozianbc@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/5c/96/0dc8b8d790a3bec36bc6e70fd82c936113182ee8990ebe0181e521a3bafb/pyorderbook-0.4.9.tar.gz",
    "platform": null,
    "description": "# PyOrderBook\n[![Project CI](https://github.com/zkhorozianbc/pyorderbook/actions/workflows/project-ci.yml/badge.svg?refresh=1)](https://github.com/zkhorozianbc/pyorderbook/actions/workflows/project-ci.yml)\n[![PyPI version](https://img.shields.io/pypi/v/pyorderbook.svg)](https://pypi.org/project/pyorderbook/)\n[![Python Versions](https://img.shields.io/pypi/pyversions/pyorderbook.svg)](https://pypi.org/project/pyorderbook/)\n[![License](https://img.shields.io/github/license/zkhorozianbc/pyorderbook.svg)](https://github.com/zkhorozianbc/pyorderbook/blob/main/LICENSE)\n\nPyOrderBook is a pure Python implementation of a limit order book and matching engine.\n\n## Features\n\n- **Order Matching Engine**\n- **Order Cancellation**\n- **Detailed Trade Blotter**\n\n## Usage\n\n```python\nfrom pyorderbook import Book, bid, ask\n\n# Create a new order book\nbook = Book()\n\n# Process some orders\nbook.match(bid(\"IBM\", 3.5, 20))\nbook.match(ask(\"IBM\", 3.6, 10))\ntrade_blotter = book.match(ask(\"IBM\", 3.5, 10))\n\n# Print trade blotter\nprint(trade_blotter)\n```\n\n## Installation\n\nTo install the package, use:\n\n```sh\n# pip\npip install pyorderbook\n# uv\nuv pip install pyorderbook\n# or \nuv add pyorderbook\n```\n\n## System Requirements\n- Python 3.11+\n\n\n## Design\n\n- **Price Levels**: Stored in a heap of dataclasses, each with a price attribute and orders attribute. Orders are stored in a dictionary within each price level. New price levels are created when an unseen price is received for a symbol/side, and standing price levels are deleted when there are no more orders in the queue at that price level.\n- **Order Queueing**: Unfilled orders are enqueued to the tail of the corresponding symbol/side/price queue, maintaining insertion order.\n- **Matching Logic**: Iterates through the price level heap (descending order for bids, ascending for asks) and dequeues from the head of each matching price level until the level or incoming order quantity is exhausted.\n- **Order Cancellation**: Uses a reference map from order ID to its encompassing price level. The order is popped from the price level and the reference map.\n- **Precision**: Uses `decimal.Decimal` objects to store prices to avoid floating point arithmetic problems.\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2021-present PyO3 Project and Contributors  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "Order Book and Matching Engine",
    "version": "0.4.9",
    "project_urls": {
        "Repository": "https://github.com/zkhorozianbc/pyorderbook"
    },
    "split_keywords": [
        "limit order book",
        " matching engine",
        " order book",
        " orderbook",
        " pyorderbook"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "ce5c42a25c3e19ce2eb6c917c24352360e8401e1cd543b60741f3adc9440311f",
                "md5": "525141b5cbd8fb5e35a7c58120e667e2",
                "sha256": "d470c5b8e17fc653a01665bf8b6011a0a1cdabadb72895ed10631d6174f97f32"
            },
            "downloads": -1,
            "filename": "pyorderbook-0.4.9-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "525141b5cbd8fb5e35a7c58120e667e2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 8002,
            "upload_time": "2025-02-25T02:02:35",
            "upload_time_iso_8601": "2025-02-25T02:02:35.198161Z",
            "url": "https://files.pythonhosted.org/packages/ce/5c/42a25c3e19ce2eb6c917c24352360e8401e1cd543b60741f3adc9440311f/pyorderbook-0.4.9-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "5c960dc8b8d790a3bec36bc6e70fd82c936113182ee8990ebe0181e521a3bafb",
                "md5": "ad321560c01460563e4af4e7c1736d6e",
                "sha256": "63b0ac502f63178001619c2cbc62d5463b2d64c2cf1576b117aa14db1a78538e"
            },
            "downloads": -1,
            "filename": "pyorderbook-0.4.9.tar.gz",
            "has_sig": false,
            "md5_digest": "ad321560c01460563e4af4e7c1736d6e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 18186,
            "upload_time": "2025-02-25T02:02:36",
            "upload_time_iso_8601": "2025-02-25T02:02:36.142085Z",
            "url": "https://files.pythonhosted.org/packages/5c/96/0dc8b8d790a3bec36bc6e70fd82c936113182ee8990ebe0181e521a3bafb/pyorderbook-0.4.9.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-25 02:02:36",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "zkhorozianbc",
    "github_project": "pyorderbook",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pyorderbook"
}
        
Elapsed time: 1.37282s