def sendString(self, string_msg): if not self.isConnected() and self.reopen: self.connect() self.trade_in_socket.send_unicode("REQ," + self.connection_id + ',' + string_msg) response_message = self.trade_in_socket.recv() raw_resp_message_header = response_message[:3] raw_resp_message = response_message[4:].strip() rep_msg = None if raw_resp_message: try: rep_msg = JsonMessage(raw_resp_message) except Exception: pass if raw_resp_message_header == 'CLS' and rep_msg and not rep_msg.isErrorMessage( ): self.close() if self.reopen: self.connect() return rep_msg if raw_resp_message_header != 'REP': self.close() if self.reopen: self.connect() if rep_msg and rep_msg.isErrorMessage(): raise TradeClientException(rep_msg.get('Description'), rep_msg.get('Detail')) raise TradeClientException('Invalid request: ' + raw_resp_message) if rep_msg and rep_msg.isUserResponse(): if rep_msg.get("UserStatus") == 1: self.user_id = rep_msg.get("UserID") self.is_logged = True if self.trade_pub_socket: self.trade_pub_socket.setsockopt( zmq.SUBSCRIBE, '^' + str(self.user_id) + '$') return rep_msg
def sendString(self, string_msg): if not self.isConnected() and self.reopen: self.connect() self.trade_in_socket.send_unicode( "REQ," + self.connection_id + ',' + string_msg) response_message = self.trade_in_socket.recv() raw_resp_message_header = response_message[:3] raw_resp_message = response_message[4:].strip() rep_msg = None if raw_resp_message: try: rep_msg = JsonMessage(raw_resp_message) except Exception: pass if raw_resp_message_header == 'CLS' and rep_msg and not rep_msg.isErrorMessage(): self.close() if self.reopen: self.connect() return rep_msg if raw_resp_message_header != 'REP': self.close() if self.reopen: self.connect() if rep_msg and rep_msg.isErrorMessage(): raise TradeClientException(rep_msg.get('Description'), rep_msg.get('Detail')) raise TradeClientException('Invalid request: ' + raw_resp_message ) if rep_msg and rep_msg.isUserResponse(): if rep_msg.get("UserStatus") == 1: self.user_id = rep_msg.get("UserID") self.is_logged = True if self.trade_pub_socket: self.trade_pub_socket.setsockopt(zmq.SUBSCRIBE, str(self.user_id)) return rep_msg