Пример #1
0
    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),
        ))
Пример #2
0
 def logout_handler(self, message: BaseMessage):
     self.logger.critical('Logout reason: {0}'.format(message.get_field(Field.Text)))
     self.close()
Пример #3
0
 def reject_handler(self, message: BaseMessage):
     self.logger.warn("MESSAGE REJECTED: {0}".format(message.get_field(Field.Text)))
Пример #4
0
 def test_request_handled(self, message: BaseMessage):
     self.send(TestResponseMessage(message.get_field(Field.TestReqID), self.session))
Пример #5
0
 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))
Пример #6
0
 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))