Skip to main content

A high-performance order book implementation in Python

Project description

py-orderbook

A high-performance order book implementation in Python with price-time priority matching. Available as an official PyPI package.

Installation

pip install akhil4n-orderbook

Features

  • Price-time priority matching engine
  • Limit and market order support
  • Order cancellation
  • Trade log with aggressor tracking
  • 124k+ matched orders/second throughput

Usage

from orderbook import OrderBook, Order, MarketOrder, OrderSide
from decimal import Decimal

book = OrderBook()

# Add a limit order
bid = Order(side=OrderSide.BID, price=Decimal("50.00"), original_quantity=100)
book.add_limit_order(bid)

# Add a matching ask
ask = Order(side=OrderSide.ASK, price=Decimal("50.00"), original_quantity=100)
book.add_limit_order(ask)

# Add a market order
market_order = MarketOrder(side=OrderSide.BID, original_quantity=50)
book.add_market_order(market_order)

# Cancel an order
book.cancel_order(market_order.order_id) # cancels the market order we just put in

# Display the book
print(book)

# View trade log
book.print_trade_log()

Running Tests

git clone https://github.com/Akhil4n/py-orderbook.git
cd py-orderbook
python -m venv venv
venv\Scripts\activate  # Mac/Linux: source venv/bin/activate
pip install -r requirements-dev.txt
pytest test_orderbook.py -v

Performance

Simple inserts:     ~416k orders/second
Matched pairs:      ~124k orders/second
Mixed actions:      ~114k orders/second

Project Structure

py-orderbook/
├── orderbook.py        # Core implementation
├── test_orderbook.py   # Unit tests
├── stress_test.py      # Performance benchmarks
├── pyproject.toml      # Package configuration
└── requirements.txt    # Dependencies

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

akhil4n_orderbook-0.1.1.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

akhil4n_orderbook-0.1.1-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file akhil4n_orderbook-0.1.1.tar.gz.

File metadata

  • Download URL: akhil4n_orderbook-0.1.1.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for akhil4n_orderbook-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e10683246b9cb66214770cfe706acad5bd32eef2c5137c801c364a3ef56a307c
MD5 e959bdaacdde125e7e26a3a862d4ae63
BLAKE2b-256 7f51833f8b92413406be963a1cdbd21a5d19e6b31551130da288944c85fb6ff3

See more details on using hashes here.

File details

Details for the file akhil4n_orderbook-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for akhil4n_orderbook-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b9880d426a6f7ea2b306bd171446306d9602fc046c5205b73c3737e0c18a2005
MD5 c7b5e034511493dd92e362477fee9ad7
BLAKE2b-256 b7633e5355d09cc5cd0900aff9ee5f01bd30d97068ec8e8d51997b2822011a8d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page