RODY/app/utils/WebsocketClient.py

29 lines
775 B
Python
Raw Permalink Normal View History

2022-11-04 17:37:08 +08:00
"""
@Time 2022/10/11 16:43
@Auth
@File WebsocketClient.py
@IDE PyCharm
@MottoABC(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()