All Projects → bmoscon → orderbook

bmoscon / orderbook

Licence: GPL-3.0 license
A fast L2/L3 orderbook data structure, in C, for Python

Programming Languages

python
139335 projects - #7 most used programming language
c
50402 projects - #5 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to orderbook

tellerbot
Telegram Bot for over-the-counter trading
Stars: ✭ 17 (-83.17%)
Mutual labels:  finance, trading, orderbook
hurtrade
An Open Source Forex Trading Platform
Stars: ✭ 22 (-78.22%)
Mutual labels:  finance, trading
wolf
🐺 Binance trading bot for node.js
Stars: ✭ 76 (-24.75%)
Mutual labels:  finance, trading
HTML-Crypto-Currency-Chart-Snippets
💹 Simple HTML Snippets to create Tickers / Charts of Cryptocurrencies with the TradingView API 💹
Stars: ✭ 89 (-11.88%)
Mutual labels:  finance, trading
Alpaca Backtrader Api
Alpaca Trading API integrated with backtrader
Stars: ✭ 246 (+143.56%)
Mutual labels:  finance, trading
cira
Cira algorithmic trading made easy. A Façade library for simpler interaction with alpaca-trade-API from Alpaca Markets.
Stars: ✭ 21 (-79.21%)
Mutual labels:  finance, trading
portfoliolab
PortfolioLab is a python library that enables traders to take advantage of the latest portfolio optimisation algorithms used by professionals in the industry.
Stars: ✭ 104 (+2.97%)
Mutual labels:  finance, trading
Philadelphia
Low-latency Financial Information Exchange (FIX) engine for the JVM
Stars: ✭ 219 (+116.83%)
Mutual labels:  finance, trading
tradestation-python-api
A Python Client library for the TradeStation API.
Stars: ✭ 69 (-31.68%)
Mutual labels:  finance, trading
futu algo
Futu Algorithmic Trading Solution (Python) 基於富途OpenAPI所開發量化交易程序
Stars: ✭ 143 (+41.58%)
Mutual labels:  finance, trading
Ostia
Ostia is a cryptocurrency trading platform that allows you to run algorithmic trading strategies across all major exchanges.
Stars: ✭ 61 (-39.6%)
Mutual labels:  finance, trading
Ta Rs
Technical analysis library for Rust language
Stars: ✭ 248 (+145.54%)
Mutual labels:  finance, trading
Trading Backtest
A stock backtesting engine written in modern Java. And a pairs trading (cointegration) strategy implementation using a bayesian kalman filter model
Stars: ✭ 247 (+144.55%)
Mutual labels:  finance, trading
Mida
The open-source and cross-platform trading framework
Stars: ✭ 263 (+160.4%)
Mutual labels:  finance, trading
Vnpy
基于Python的开源量化交易平台开发框架
Stars: ✭ 17,054 (+16785.15%)
Mutual labels:  finance, trading
algotrading-example
algorithmic trading backtest and optimization examples using order book imbalances. (bitcoin, cryptocurrency, bitmex, binance futures, market making)
Stars: ✭ 169 (+67.33%)
Mutual labels:  trading, orderbook
Awesome Quant
中国的Quant相关资源索引
Stars: ✭ 2,529 (+2403.96%)
Mutual labels:  finance, trading
Jiji2
Forex algorithmic trading framework using OANDA REST API.
Stars: ✭ 211 (+108.91%)
Mutual labels:  finance, trading
web trader
📊 Python Flask game that consolidates data from Nasdaq, allowing the user to practice buying and selling stocks.
Stars: ✭ 21 (-79.21%)
Mutual labels:  finance, trading
Sequence-to-Sequence-Learning-of-Financial-Time-Series-in-Algorithmic-Trading
My bachelor's thesis—analyzing the application of LSTM-based RNNs on financial markets. 🤓
Stars: ✭ 64 (-36.63%)
Mutual labels:  finance, trading

Orderbook

License Python PyPi coverage-lines coverage-functions

A fast L2/L3 orderbook data structure, in C, for Python

Basic Usage

from decimal import Decimal

import requests
from order_book import OrderBook

ob = OrderBook()

# get some orderbook data
data = requests.get("https://api.pro.coinbase.com/products/BTC-USD/book?level=2").json()

ob.bids = {Decimal(price): size for price, size, _ in data['bids']}
ob.asks = {Decimal(price): size for price, size, _ in data['asks']}

# OR

for side in data:
    # there is additional data we need to ignore
    if side in {'bids', 'asks'}:
        ob[side] = {Decimal(price): size for price, size, _ in data[side]}


# Data is accessible by .index(), which returns a tuple of (price, size) at that level in the book
price, size = ob.bids.index(0)
print(f"Best bid price: {price} size: {size}")

price, size = ob.asks.index(0)
print(f"Best ask price: {price} size: {size}")

print(f"The spread is {ob.asks.index(0)[0] - ob.bids.index(0)[0]}\n\n")

# Data is accessible via iteration
# Note: bids/asks are iterators

print("Bids")
for price in ob.bids:
    print(f"Price: {price} Size: {ob.bids[price]}")


print("\n\nAsks")
for price in ob.asks:
    print(f"Price: {price} Size: {ob.asks[price]}")


# Data can be exported to a sorted dictionary
# In Python3.7+ dictionaries remain in insertion ordering. The
# dict returned by .to_dict() has had its keys inserted in sorted order
print("\n\nRaw asks dictionary")
print(ob.asks.to_dict())

Main Features

  • Sides maintained in correct order
  • Can perform orderbook checksums
  • Supports max depth and depth truncation

Installation

The preferable way to install is via pip - pip install order-book. Installing from source will require a compiler and can be done with setuptools: python setup.py install.

Running code coverage

The script coverage.sh will compile the source using the -coverage CFLAG, run the unit tests, and build a coverage report in HTML. The script uses tools that may need to be installed (coverage, lcov, genhtml).

Running the performance tests

You can run the performance tests like so: python perf/performance_test.py. The program will profile the time to run for random data samples of various sizes as well as the construction of a sorted orderbook using live L2 orderbook data from Coinbase.

The performance of constructing a sorted orderbook (using live data from Coinbase) using this C library, versus a pure Python sorted dictionary library:

Library Time, in seconds
C Library 0.00021767616271
Python Library 0.00043988227844

The performance of constructing sorted dictionaries using the same libraries, as well as the cost of building unsorted, python dictionaies for dictionaries of random floating point data:

Library Number of Keys Time, in seconds
C Library 100 0.00021600723266
Python Library 100 0.00044703483581
Python Dict 100 0.00022006034851
C Library 500 0.00103306770324
Python Library 500 0.00222206115722
Python Dict 500 0.00097918510437
C Library 1000 0.00202703475952
Python Library 1000 0.00423812866210
Python Dict 1000 0.00176715850830

This represents a roughly 2x speedup compared to a pure python implementation, and in many cases is close to the performance of an unsorted python dictionary.

For other performance metrics, run performance_test.py as well as the other performance tests in perf/

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].