INNER CODE UNIT · Python
on_order_book_update_message
keanekwa/Optiver-Ready-Trader-Go · arbitrage.py:47
def on_order_book_update_message(self, instrument: int, sequence_number: int, ask_prices: List[int],
ask_volumes: List[int], bid_prices: List[int], bid_volumes: List[int]) -> None:
"""Called periodically to report the status of an order book.
The sequence number can be used to detect missed or out-of-order
messages. The five best available ask (i.e. sell) and bid (i.e. buy)
prices are reported along with the volume available at each of those
price levels.
"""
self.logger.info("received order book for instrument %d with sequence number %d", instrument,
sequence_number)
if instrument == Instrument.FUTURE:
self.last_future_bids = bid_prices
self.last_future_asks = ask_prices
if instrument == Instrument.ETF and len(self.last_future_asks) > 0 and len(self.last_future_bids) > 0:
future_price = (self.last_future_asks[0] + self.last_future_bids[0]) // 2
etf_price = (ask_prices[0] + bid_prices[0]) // 2