Can we inherit this OrderBook?
Broever101 opened this issue · 2 comments
Broever101 commented
I want to inherit this OrderBook to add some custom functionality. Is that possible? How can it be done and which interfaces I need to implement?
bmoscon commented
It can be done, but you'd have to look at the Python C API specification and implement all the requisite functions and structures.
lijiachang commented
i have done like this:
from order_book import OrderBook as C_OrderBook
class FastOrderBook(C_OrderBook):
def __init__(self, instrument_name, bids: dict, asks: dict, change_id, timestamp,
greeks=None, mark_price=None, mark_iv=None, bid_iv=None, ask_iv=None, connection_id=None,
max_depth: int = None):
if max_depth:
super().__init__(max_depth=max_depth)
else:
super().__init__()
self.instrument_name = instrument_name
...
def __setattr__(self, key, value):
if key in ('bids', 'asks'):
super().__setattr__(key, value)
else:
self.__dict__[key] = value
def to_json(self, level=0):
# asks = [(price, self.asks[price]) for price in self.asks]
# bids = [(price, self.bids[price]) for price in self.bids]
d = self.to_dict()
asks = list(d['ask'].items())
bids = list(d['bid'].items())
...