lob package¶
Submodules¶
lob.orderbook module¶
Main module containing the Orderbook class.
- class fastlob.lob.orderbook.Orderbook(name='LOB-1', start=False)¶
Bases:
object
The Orderbook is a collection of bid and ask limits. It is reponsible for: - Calling engine when order is market. - Placing order in correct side when order is limit. - All the safety checking before and after order has been processed. - Logging informations.
- asks_volume()¶
Total volume on the ask side.
- Return type:
Decimal
- best_ask()¶
Get the best ask limit=(price, volume, #orders) in the lob.
- Return type:
Optional
[tuple
[Decimal
,Decimal
,int
]]
- best_asks(n)¶
Return best n asks (price, volume, #orders) triplets. If n > #asks, returns #asks elements.
- Return type:
list
[tuple
[Decimal
,Decimal
,int
]]
- best_bid()¶
Get the best bid limit=(price, volume, #orders) in the lob.
- Return type:
Optional
[tuple
[Decimal
,Decimal
,int
]]
- best_bids(n)¶
Return best n bids (price, volume, #orders) triplets. If n > #bids, returns #bids elements.
- Return type:
list
[tuple
[Decimal
,Decimal
,int
]]
- bids_volume()¶
Total volume on the bid side.
- Return type:
Decimal
- cancel(orderid)¶
Cancel an order sitting in the lob given it’s identifier.
- Return type:
- Args:
orderid (str): Identifier of the order to cancel.
- Returns:
ExecutionResult: The result of the cancellation.
- static from_snapshot(snapshot, name='LOB', start=False)¶
Instantiate a new LOB from a given snapshot. A “snapshot” is a dictionary of the following form {“bids”: <list_of_(price, volume)_pairs>, “asks”: <list_of_(price, volume)_pairs>}.
It does so by placing a “fake” order. These orders are also not added to the history. They are simply added to each price level.
- Returns:
Orderbook: A new LOB initialized with snapshot.
- get_status(orderid)¶
Get the status and the quantity left for a given order or None if order was not accepted by the lob.
- Return type:
Optional
[tuple
[OrderStatus
,Decimal
]]
- imbalance(n=None)¶
Get the lob imbalance for the n best limits on each side. If n is not provided, takes all limits on each side.
- Return type:
Decimal
- load_updates(updates)¶
Load updates so that every time step is called, the lob gets updated (using fake orders).
- midprice()¶
Get the lob midprice.
- Return type:
Optional
[Decimal
]
- n_asks()¶
Get the number of ask limits.
- Return type:
int
- n_bids()¶
Get the number of bid limits.
- Return type:
int
- n_prices()¶
Get the total number of limits (price levels).
- Return type:
int
- process_many(ordersparams)¶
Process many order parameters.
- Return type:
list
[ExecutionResult
]
- Args:
ordersparams (Iterable[OrderParams]): Iterable of OrderParams to process.
- Returns:
list[ExecutionResult]: The result of the execution of each order.
- process_one(orderparams)¶
Process one order params instance.
- Return type:
- Args:
orderparams (OrderParams): OrderParams to process.
- Returns:
ExecutionResult: The result of the execution of the order.
- render(n=10)¶
Pretty-print the best n limits on each side of the lob.
- Return type:
None
- reset()¶
Reset the lob. Equivalent to re-instantiating it.
- Return type:
None
- running_time()¶
Number of seconds since the lob has been started.
- Return type:
int
- Returns:
int: Time in seconds since the lob has been started.
- spread()¶
Get the lob spread.
- Return type:
Decimal
- start()¶
Start the lob. Required before orders can be placed.
- Return type:
None
- step()¶
Apply the updates in next(updates) to the lob.
- stop()¶
Stop the lob and its background processes.
- Return type:
None
- total_volume()¶
Total volume on ask and bid side.
- Return type:
Decimal
- view(n=10)¶
Get a pretty-printed view of the lob state.
- Return type:
str
- weighted_midprice()¶
Get the lob weighted midprice.
- Return type:
Optional
[Decimal
]
lob.utils module¶
Utility functions for lob.
- fastlob.lob.utils.check_limit_order(order)¶
Check if limit order can be processed.
- Return type:
Optional
[str
]
- fastlob.lob.utils.not_running_error(logger)¶
Build the not running error.
- Return type:
Module contents¶
Main module containing the Orderbook class.