RODY/app/utils/WebsocketClient.py
552068321@qq.com 6f7de660aa first commit
2022-11-04 17:37:08 +08:00

29 lines
775 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
@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()