Order Matching Engine and Market Data - Liquibook
Project description
This project is a python wrapper for Liquibook. Liquibook is a low latency open source order matching engine written in modern C++ - Liquibook Source Code
This project allows to submit orders and receive the following notifications:
-
Order State
- Order accepted
- Order rejected
- Order filled (full or partial)
- Order replaced
- Replace request rejected
- Order canceled
- Cancel request rejected.
-
Order Book State
- Depth book changed
- Best Bid or Best Offer (BBO) changed
Example:
-
Submitting Buy - Price : 100 Size: 10
- Receive and print
- Order accept details
- Price depth
- BBO Change
- Receive and print
-
Submitting Buy - Price : 110 Size: 10
- Receive and print
- Order accept details
- Price depth
- BBO Change
- Receive and print
-
Submitting Sell - Price : 120 Size: 30
- Receive and print
- Order accept details
- Price depth
- BBO Change
- Receive and print
-
Cancelling Sell - Price : 120 Size: 30
- Receive and print
- Order cancel details
- Price depth
- BBO Change
- Receive and print
-
Submitting Sell - Price : 100 Size: 25
- Receive and print
- Order accept details
- Trades @110
- Trades @100
- Price depth
- BBO Change
- Receive and print
import liquibook
from liquibook import pretty_print
import time
class DepthListener(liquibook.DepthListener):
def __init__(self):
print("DepthListener")
liquibook.DepthListener.__init__(self)
def on_depth_change(self, book, depth):
print('Depth change:[' + book.symbol() + ']')
print(liquibook.pretty_print.depth_header)
print(liquibook.pretty_print.depth_header_separator)
pretty_depth = liquibook.pretty_print.depth(depth)
print(pretty_depth)
print('\n')
class OrderListener(liquibook.OrderListener):
def __init__(self):
print("OrderListener")
liquibook.OrderListener.__init__(self)
def on_accept(self, order):
print('Order accepted: [' + str(order.order_id_) + ']')
order_string = liquibook.pretty_print.order(order)
print(liquibook.pretty_print.order_header)
print(liquibook.pretty_print.order_header_separator)
print(order_string)
print('\n')
def on_cancel(self, order):
print('Order cancelled: [' + str(order.order_id_) + ']')
order_string = liquibook.pretty_print.order(order)
print(liquibook.pretty_print.order_header)
print(liquibook.pretty_print.order_header_separator)
print(order_string)
print('\n')
def on_fill(self, passive_order, aggressive_order, fill_qty, fill_cost):
passive_order.fill(fill_qty, fill_cost,0)
aggressive_order.fill(fill_qty, fill_cost,0)
print('Orders Filled: @' + str(fill_cost) + '')
print(liquibook.pretty_print.order_header)
print(liquibook.pretty_print.order_header_separator)
aggressive_order_string = liquibook.pretty_print.order(passive_order)
passive_order_order_string = liquibook.pretty_print.order(aggressive_order)
print(aggressive_order_string)
print(passive_order_order_string+'\n')
class BBOListener(liquibook.DepthOrderBookBboListener):
def __init__(self):
print("BBO Listener")
liquibook.DepthOrderBookBboListener.__init__(self)
def on_bbo_change(self, book, depth):
print('Best bid/offer change: [' + book.symbol() + ']')
print(liquibook.pretty_print.depth_header)
print(liquibook.pretty_print.depth_header_separator)
bid_price_size_tuple = liquibook.pretty_print.depth_level(depth.bids())
ask_price_size_tuple = liquibook.pretty_print.depth_level(depth.asks())
top_level_out = liquibook.pretty_print.depth_header_format.\
format(bid=bid_price_size_tuple, ask=ask_price_size_tuple)
print(top_level_out+'\n')
if __name__ == '__main__':
order_book_listener = DepthListener()
bbo_listener = BBOListener()
order_listener = OrderListener()
basic_order_book = liquibook.DepthOrderBook()
basic_order_book.set_bbo_listener(bbo_listener)
basic_order_book.set_depth_listener(order_book_listener)
basic_order_book.set_order_listener(order_listener)
basic_order_book.set_symbol('AAPL')
transaction_seprator="="*len(liquibook.pretty_print.order_header)
print(transaction_seprator)
buy_order_1 = liquibook.SimpleOrder(True, 100, 10)
print('Submitting Buy - Price : {:<7} Size: {:<7}'.format(buy_order_1.price(), buy_order_1.order_qty()))
time.sleep(1)
basic_order_book.add(buy_order_1)
print(transaction_seprator)
buy_order_2 = liquibook.SimpleOrder(True, 110, 10)
print('\n\nSubmitting Buy - Price : {:<7} Size: {:<7}'.format(buy_order_2.price(), buy_order_2.order_qty()))
time.sleep(1)
basic_order_book.add(buy_order_2)
print(transaction_seprator)
sell_order_1 = liquibook.SimpleOrder(False, 120, 30)
print('\n\nSubmitting Sell - Price : {:<7} Size: {:<7}'.format(sell_order_1.price(), sell_order_1.order_qty()))
time.sleep(2)
basic_order_book.add(sell_order_1)
print(transaction_seprator)
print('\n\nCancelling Sell - Price : {:<7} Size: {:<7}'.format(sell_order_1.price(), sell_order_1.order_qty()))
time.sleep(2)
basic_order_book.cancel(sell_order_1)
print(transaction_seprator)
sell_order_2 = liquibook.SimpleOrder(False, 100, 25)
print('\n\nSubmitting Sell - Price : {:<7} Size: {:<7}'.format(sell_order_2.price(), sell_order_2.order_qty()))
time.sleep(2)
basic_order_book.add(sell_order_2)
print(transaction_seprator)
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
liquibook-1.0.0.win-amd64.zip
(188.2 kB
view details)
Built Distributions
File details
Details for the file liquibook-1.0.0.win-amd64.zip
.
File metadata
- Download URL: liquibook-1.0.0.win-amd64.zip
- Upload date:
- Size: 188.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c83f8ab3e215fe0ec46c2bf07759ca9819491c3321b734d8cf530880da9eda8b |
|
MD5 | e71cfaba2495a03917a526bb8c5ba45f |
|
BLAKE2b-256 | f95c53edc9dec7f957597a2b2fb5f2aa7cdc6cec4e8512e8f0ac18f6d0bc6943 |
File details
Details for the file liquibook-1.0.0-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: liquibook-1.0.0-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 170.6 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | be9089503f200aa348361aa09420a66dba76aed5b99a1c3660faa6d642be6833 |
|
MD5 | c7718d1e913413df4335576082db8315 |
|
BLAKE2b-256 | fd62589bcec850dc2a41b10f810e732208eba93e881286dd42094e487c0cf1d2 |
File details
Details for the file liquibook-1.0.0-cp39-cp39-macosx_10_9_universal2.whl
.
File metadata
- Download URL: liquibook-1.0.0-cp39-cp39-macosx_10_9_universal2.whl
- Upload date:
- Size: 401.5 kB
- Tags: CPython 3.9, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7ff2c9f669d5c9b81cd2d87335c617431253f9f54a7eb74cdd2b74575ad8fd1 |
|
MD5 | f3cfd22fc18f9cc18f46e5a8660d19ec |
|
BLAKE2b-256 | bc33507c5b5b74a2110ed5b316a85900395cb9ee962b87d2c9acb159deb4c4dc |
File details
Details for the file liquibook-1.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: liquibook-1.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.6 MB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84f0f8aebbb726cedea70903e5a2d6b3c0ec88b1fd7b5f5b7b8b9389c39cca9e |
|
MD5 | b8f08295cf0c0f39eae9b9b40d28470e |
|
BLAKE2b-256 | ee36ff0e86b58cb36c1a867b7604b88f6bc3076c30ce92cfd7de204d43cebb5b |