def insert_order_book(self, instmt): """ Insert order book row into the database client :param instmt: Instrument """ # If local timestamp indicator is on, assign the local timestamp again if self.is_local_timestamp: instmt.get_l2_depth().date_time = datetime.utcnow().strftime("%Y%m%d %H:%M:%S.%f") # Update the snapshot if self.data_mode & ExchangeGateway.DataMode.SNAPSHOT_ONLY and \ instmt.get_l2_depth() is not None: self.db_client.insert(table=self.get_snapshot_table_name(), columns=Snapshot.columns(), types=Snapshot.types(), values=Snapshot.values(instmt.get_exchange_name(), instmt.get_instmt_name(), instmt.get_l2_depth(), Trade() if instmt.get_last_trade() is None else instmt.get_last_trade(), Snapshot.UpdateType.ORDER_BOOK), primary_key_index=[0,1], is_orreplace=True, is_commit=not(self.data_mode & ExchangeGateway.DataMode.ORDER_BOOK_ONLY)) # Update its order book table if self.data_mode & ExchangeGateway.DataMode.ORDER_BOOK_ONLY: self.db_client.insert(table=instmt.get_order_book_table_name(), columns=['id'] + L2Depth.columns(), types=['int'] + L2Depth.types(), values=[instmt.get_order_book_id()] + instmt.get_l2_depth().values())
def init_order_book_table(self, instmt): if self.data_mode & ExchangeGateway.DataMode.ORDER_BOOK_ONLY: table_name = self.get_order_book_table_name(instmt.get_exchange_name(), instmt.get_instmt_name()) self.db_client.create(table_name, ['id'] + L2Depth.columns(), ['int'] + L2Depth.types(), [0])