Skip to main content

PyOrderBook

Project CI PyPI version Python Versions 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

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:

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

Metadata

Release files for pyorderbook 0.4.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyorderbook 0.4.9
File Size Uploaded
pyorderbook-0.4.9.tar.gz 18.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyorderbook 0.4.9
File Interpreter ABI Platform
pyorderbook-0.4.9-py3-none-any.whl Python 3 none any Details

Total release size: 26.2 kB

Release files / pyorderbook-0.4.9.tar.gz

Download URL pyorderbook-0.4.9.tar.gz
Size 18.2 kB
Tags Source
SHA-256 checksum
How to use checksums
63b0ac502f63178001619c2cbc62d5463b2d64c2cf1576b117aa14db1a78538e
BLAKE2b-256 checksum
How to use checksums
5c960dc8b8d790a3bec36bc6e70fd82c936113182ee8990ebe0181e521a3bafb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.26

Release files / pyorderbook-0.4.9-py3-none-any.whl

Download URL pyorderbook-0.4.9-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d470c5b8e17fc653a01665bf8b6011a0a1cdabadb72895ed10631d6174f97f32
BLAKE2b-256 checksum
How to use checksums
ce5c42a25c3e19ce2eb6c917c24352360e8401e1cd543b60741f3adc9440311f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.26

Release history Release notifications | RSS feed

This release

0.4.9 This release

2 release files

0.4.8

2 release files

0.4.6

2 release files

0.4.5

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page