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), ))
def logout_handler(self, message: BaseMessage): self.logger.critical('Logout reason: {0}'.format(message.get_field(Field.Text))) self.close()
def reject_handler(self, message: BaseMessage): self.logger.warn("MESSAGE REJECTED: {0}".format(message.get_field(Field.Text)))
def test_request_handled(self, message: BaseMessage): self.send(TestResponseMessage(message.get_field(Field.TestReqID), self.session))
def heartbeat_handler(self, message: BaseMessage): self.logger.debug( "Received heartbeat, sending it back. Server time: {0}.".format(message.get_field(Field.SendingTime)) ) self.send(HeartbeatMessage(self.session))
def logon_handler(self, message: BaseMessage): self.authorized = True self.logger.info("Logged in at {0} as {1}".format(message.get_field(Field.SendingTime), self.session.sender_id))