""" @Time : 2022/10/11 16:43 @Auth : 东 @File :WebsocketClient.py @IDE :PyCharm @Motto:ABC(Always Be Coding) @Desc: """ from threading import Thread import websocket def connect(self, apiKey, secretKey, trace=False): self.host = OKEX_USD_CONTRACT self.apiKey = apiKey self.secretKey = secretKey self.trace = trace websocket.enableTrace(trace) self.ws = websocket.WebSocketApp(self.host, on_message=self.onMessage, on_error=self.onError, on_close=self.onClose, on_open=self.onOpen) self.thread = Thread(target=self.ws.run_forever, args=(None, None, 60, 30)) self.thread.start()