def market_data_refresh_handler(self, message: BaseMessage): results = message.get_group(Field.Groups.MDEntry_Refresh) actions = {'0': 'New', '2': 'Delete'} types = {'0': 'BID', '1': 'ASK'} message = "Price Update:" for r in results: if actions[r[Field.MDUpdateAction]] == 'New': if Field.MDEntryPx in r: name = self.session.symbol_table[int(r[Field.Symbol])]['name'] message += "\n\t\t\tSymbol: {0: <7}, Type: {1}, ID: {2}, Price: {3: <10}, Size: {4}, Action: {5}".format( name, types[r[Field.MDEntryType]], r[Field.MDEntryID], r[Field.MDEntryPx], r[Field.MDEntrySize], actions[r[Field.MDUpdateAction]] ) else: message += "\n\t\t\tSymbol: {0: <7}, ID: {1}, Action: {2}".format( 'none', r[Field.MDEntryID], actions[r[Field.MDUpdateAction]] ) self.logger.info(message)
def market_data_snapshot_handler(self, message: BaseMessage): prices = message.get_group(Field.Groups.MDEntry_Snapshot) if len(prices) < 2 or Field.MDEntryPx not in prices[0] or Field.MDEntryPx not in prices[1]: self.logger.warn("No ask or bid in price update.") return ask_idx = 1 if prices[0][Field.MDEntryType] == '0' else 0 bid_idx = (ask_idx + 1) % 2 spread = calculate_spread( prices[bid_idx][Field.MDEntryPx], prices[ask_idx][Field.MDEntryPx], self.session.symbol_table[int(message.get_field(Field.Symbol))]['pip_position'] ) name = self.session.symbol_table[int(message.get_field(Field.Symbol))]['name'] self.logger.info("Symbol: {0: <7}\tBID: {1: <10}\tASK: {2: <10}\tSPREAD: {3}\t\tBID_VOL: {4}\tASK_VOL: {5}".format( name, prices[bid_idx][Field.MDEntryPx], prices[ask_idx][Field.MDEntryPx], spread, int(self.session.symbol_table[int(message.get_field(Field.Symbol))]['bid_volume'] / 1000000), int(self.session.symbol_table[int(message.get_field(Field.Symbol))]['ask_volume'] / 1000000), ))