A high-performance order book implementation for cryptocurrency exchanges
Project description
Manticore OrderBook
A high-performance, feature-rich limit order book implementation for financial trading applications.
Features
✅ Complete Order Book Implementation - Full-featured limit order book with best-in-class performance
✅ Multiple Order Types - Support for limit, market, FOK, IOC, post-only, and GTD orders
✅ Price Improvement - Optional price improvement for better execution
✅ Event-Driven Architecture - Real-time events for order added, cancelled, and trades executed
✅ High Performance - Optimized for high-throughput trading (17,000+ orders/second)
✅ Comprehensive API - Clean, intuitive interface with extensive documentation
✅ Production Ready - Extensively tested and benchmarked
Installation
# From PyPI
pip3 install manticore-orderbook
# From source
git clone https://github.com/manticoretechnologies/manticore-orderbook.git
cd manticore-orderbook
pip3 install -e .
Quick Start
from manticore_orderbook import OrderBook
from manticore_orderbook.enums import Side, EventType
# Create an order book for BTC/USD
orderbook = OrderBook("BTC", "USD")
# Register event handlers
def on_trade(event):
print(f"Trade executed: {event.amount} @ {event.price}")
orderbook.event_manager.register(EventType.TRADE_EXECUTED, on_trade)
# Add orders
orderbook.add_order("bid1", Side.BUY, 10000.00, 1.0)
orderbook.add_order("ask1", Side.SELL, 10100.00, 0.5)
# Get a snapshot of the current order book state
snapshot = orderbook.get_snapshot()
print(f"Best bid: {snapshot['bids'][0]['price'] if snapshot['bids'] else 'None'}")
print(f"Best ask: {snapshot['asks'][0]['price'] if snapshot['asks'] else 'None'}")
# Add a matching order that will execute
orderbook.add_order("match1", Side.BUY, 10100.00, 0.2)
Advanced Usage
Different Order Types
from manticore_orderbook.strategies import (
MarketOrderStrategy,
FOKOrderStrategy,
IOCOrderStrategy,
PostOnlyOrderStrategy,
GTDOrderStrategy
)
import datetime
# Market order
orderbook.add_order("market1", Side.BUY, None, 0.5,
strategy=MarketOrderStrategy())
# Fill-or-Kill order
orderbook.add_order("fok1", Side.BUY, 10050.00, 2.0,
strategy=FOKOrderStrategy())
# Immediate-or-Cancel order
orderbook.add_order("ioc1", Side.SELL, 10100.00, 1.0,
strategy=IOCOrderStrategy())
# Post-Only order
orderbook.add_order("post1", Side.BUY, 9900.00, 3.0,
strategy=PostOnlyOrderStrategy())
# Good-Till-Date order
expiry = datetime.datetime.now() + datetime.timedelta(days=1)
orderbook.add_order("gtd1", Side.SELL, 10200.00, 0.75,
strategy=GTDOrderStrategy(expiry))
Price Improvement
# Create an order book with price improvement enabled
orderbook = OrderBook("ETH", "USD", enable_price_improvement=True)
# The order book will automatically match orders at the best available price,
# even if that's better than what the taker requested
Performance
Manticore OrderBook is designed for high-performance trading applications:
- Order Addition: ~15,000 orders/second
- Order Cancellation: ~14,000 cancels/second
- Order Matching: ~17,000 orders/second with multiple matches
Documentation
- User Guide - Comprehensive guide to using the library
- API Documentation - Detailed API reference
- Examples - Code examples demonstrating various features
Visualization
Manticore OrderBook includes a visualization server for real-time order book display:
python3 -m manticore_orderbook.visualizer
Development
Setup Development Environment
# Clone the repository
git clone https://github.com/manticoretechnologies/manticore-orderbook.git
cd manticore-orderbook
# Create and activate virtual environment
python3 -m venv venv
source venv/bin/activate
# Install development dependencies
pip3 install -e ".[dev]"
Running Tests
# Run all tests
python3 -m unittest discover
# Run specific test module
python3 -m unittest tests.test_orderbook
# Run benchmarks
python3 -m tests.benchmark.test_orderbook_benchmark
Contributing
Contributions are welcome! Please see our Contributing Guide for details on how to submit pull requests, report issues, and suggest features.
License
Manticore OrderBook is licensed under the MIT License. See the LICENSE file for details.
Contact
- Website: https://manticore.technology
- Email: dev@manticore.technology
- GitHub: https://github.com/manticoretechnologies
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file manticore_orderbook-1.0.1.tar.gz.
File metadata
- Download URL: manticore_orderbook-1.0.1.tar.gz
- Upload date:
- Size: 68.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
16be72049af811004a753afb788a3878c63eba0dc9887f2e4bc1b178bc5cde9e
|
|
| MD5 |
1485b5699879b2843e93c7863a0f555c
|
|
| BLAKE2b-256 |
a7c1ea9453449cf2037e020668c76e10192ebb6f3d1d21f8e1c12cd13865ad9f
|
File details
Details for the file manticore_orderbook-1.0.1-py3-none-any.whl.
File metadata
- Download URL: manticore_orderbook-1.0.1-py3-none-any.whl
- Upload date:
- Size: 75.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
330f16b31f26c265ef663b4f665c020236c7571a744d6909dd84ed1150aa0b06
|
|
| MD5 |
c7e12b948fdb6c1367c35dd4d902c00d
|
|
| BLAKE2b-256 |
185c0b889668485d75ab8b6a876a73d97dee77e17b5d9251c20451383a3fe123
|