Пример #1
0
	def handle_data(self, data_decode):
		#000a 0001 000003f91e07e221
		data_decode_io = general.stringio(data_decode)
		while True:
			data = io_unpack_short_raw(data_decode_io)
			if not data:
				break
			data_io = general.stringio(data)
			data_type = data_io.read(2).encode("hex")
			if data_type not in DATA_TYPE_NOT_PRINT:
				general.log("[ map ]",
					data[:2].encode("hex"), data[2:].encode("hex"))
			handler = self.name_map.get(data_type)
			if not handler:
				general.log_error("[ map ] unknow packet type",
					data[:2].encode("hex"), data[2:].encode("hex"))
				return
			try:
				handler(self, data_io)
			except:
				general.log_error("[ map ] handle_data error:", data.encode("hex"))
				general.log_error(traceback.format_exc())
				if data_type in DATA_TYPE_CANCEL_TRADE_WHEN_EXCEPT:
					try:
						self.pc.cancel_trade()
					except:
						general.log_error("[ map ] cancel trade when except error:")
						general.log_error(traceback.format_exc())
Пример #2
0
 def handle_data(self, data_decode):
     #000a 0001 000003f91e07e221
     data_decode_io = general.stringio(data_decode)
     while True:
         data = io_unpack_short_raw(data_decode_io)
         if not data:
             break
         data_io = general.stringio(data)
         data_type = data_io.read(2).encode("hex")
         if data_type not in DATA_TYPE_NOT_PRINT:
             general.log("[ map ]", data[:2].encode("hex"),
                         data[2:].encode("hex"))
         handler = self.name_map.get(data_type)
         if not handler:
             general.log_error("[ map ] unknow packet type",
                               data[:2].encode("hex"),
                               data[2:].encode("hex"))
             return
         try:
             handler(self, data_io)
         except:
             general.log_error("[ map ] handle_data error:",
                               data.encode("hex"))
             general.log_error(traceback.format_exc())
             if data_type in DATA_TYPE_CANCEL_TRADE_WHEN_EXCEPT:
                 try:
                     self.pc.cancel_trade()
                 except:
                     general.log_error(
                         "[ map ] cancel trade when except error:")
                     general.log_error(traceback.format_exc())