class bourse.core.OrderBook

Rust orderbook interface

Python interface to a Rust implementation of an orderbook. Allow orders to be placed and modified. The orderbook also stores data on all orders created on the market, allowing the state of orders to be queried from Python.

Examples

import bourse

book = bourse.core.OrderBook(0, True)

# Place a new order
order_id = book.place_order(
    True, 100, 0, price=50
)

# Get touch prices
bid, ask = book.bid_ask()

# Get the status of the order
status = book.order_status(order_id)

OrderBook Methods

OrderBook(**kwargs)

Create and return a new object. See help(type) for accurate signature.

ask_vol() int

Get the current total ask side volume

best_ask_vol() int

Get the current ask side touch volume

best_ask_vol_and_orders()

Get the current ask side touch volume and order count

best_bid_vol() int

Get the current bid side touch volume

best_bid_vol_and_orders()

Get the current bid side touch volume and order count

bid_ask() tuple[int, int]

Get the current bid-ask prices

bid_vol() int

Get the current total bid side volume

cancel_order(order_id: int)

Cancel order

disable_trading()

Disable trading

enable_trading()

Enable trading

get_orders() list[tuple]

Get order data

get_trades() list[tuple]

Get trade data

modify_order(order_id: int, new_price: int = None, ...)

Modify an order

order_status(order_id: int) int

Get the status of an order

place_order(bid: bool, vol: int, trader_id: int, ...) int

Place a new order on the market

save_json_snapshot(path: str, pretty: bool = False)

Save a snapshot of the order book state to JSON

set_time(t: int)

Set the orderbook time