Skip to content

order_book

OrderBook

Order Book storage class.

current_price property

Current market price.

max_bid property

Maximum bid price.

min_offer property

Minimum offer price.

append(incoming_order)

Add one order to the order book.

Parameters:

Name Type Description Default
incoming_order Order

New order

required

get_imbalance(price_range=0.1)

Calculate order book imbalance.

Order book imbalance indicator is defined as $$ \rho(L)=\frac{V_L^b-V_L^a}{V_L^b+V_L^a}\in[-1,1], $$ where $$ V_L^b=\sum_i Q_i^b\cdot\mathbf{1}\left[P_i^b\geq P^M-L\right], $$ and $$ V_L^a=\sum_i Q_i^a\cdot\mathbf{1}\left[P_i^a\leq P^M+L\right], $$ are the total bid/ask volumes within \(L>0\) from the market price. It is said that the market is balanced when \(\rho\approx0\). The market is imbalanced and there exists demand (supply) pressure when \(\rho>0\) (\(\rho<0\)). As it is clear from the formula, the imbalance can be computed at any distance \(L\) from the market price. The higher the distance, the deeper looks this indicator into the order book.

Parameters:

Name Type Description Default
price_range float

Left/right from the current market price

0.1

Returns:

Type Description
float

Market imbalance indicator

get_matching_sorted_opposite_side_prices(incoming_order)

Get sorted prices of the matching orders on the opposite side.

Parameters:

Name Type Description Default
incoming_order Order
required

Returns:

Type Description
list[float]

get_opposite_side_orders(incoming_order)

Get orders on the opposite side.

If incoming order is sell, then bids are returned. If incoming order is buy, then offers are returned.

Parameters:

Name Type Description Default
incoming_order Order
required

Returns:

Type Description
OrderBookOrdersType

get_subset(expiration)

Get orders with given expiration time.

Parameters:

Name Type Description Default
expiration datetime
required

Returns:

Type Description
Orders

matching_order_exists(incoming_order)

Check that matching order exists.

Parameters:

Name Type Description Default
incoming_order Order
required

Returns:

Type Description
bool

remove(incoming_order)

Remove one order from the order book.

Parameters:

Name Type Description Default
incoming_order Order

Order to be removed

required

summary()

Summary of the order book as a pandas DataFrame.

Returns:

Type Description
DataFrame[OrderBookSummarySchema]

Summary of the order book as a pandas DataFrame