我试图将这个程序作为我程序中的无限线程 https://github.com/qLethon/bitmex_simple_websocket
from bitmex_simple_websocket import BitMEXWebSocket
import json
class MyBitMEXWebsocket(BitMEXWebSocket):
def on_message(self, ws, message):
data = json.loads(message)
if 'table' in data and data['table'] == 'tradeBin1m':
print(data['data'][0])
bitmex = MyBitMEXWebsocket(endpoint='wss://www.bitmex.com/realtime?subscribe=tradeBin1m:XBTUSD')
如何在
中启动它if __name__ == '__main__':
正确的线程
在我目前的代码中,只有第一个主题 myBitMEXWebsocket 功能启动,但 tradeview 和交易者不会
if __name__ == '__main__':
Thread(target = MyBitMEXWebsocket(endpoint='wss://www.bitmex.com/realtime?subscribe=quote:XBTUSD')).start()
Thread(target = tradingview).start()
for count_var_short, count_var_long in tradingview():
trader(count_var_short,count_var_long)
答案 0 :(得分:-2)
解决了,我问github作者,他给出了这个答案
class MyBitMEXWebsocket(BitMEXWebSocket):
def on_message(self, ws, message):
data = json.loads(message)
if 'table' in data and data['table'] == 'quote':
print(data['data'][0])
WS_BestBid = (data['data'][0]["bidPrice"])
WS_BestAsk = (data['data'][0]["askPrice"])
#print('bid:',WS_BestBid)
#print('ask:',WS_BestAsk)
#print('bid:',data['data'][0]["bidPrice"])
#print('ask:',data['data'][0]["askPrice"])
def f():
MyBitMEXWebsocket(endpoint='wss://www.bitmex.com/realtime?subscribe=quote:XBTUSD,order:XBTUSD')
th1 = threading.Thread(target=f)
th1.start()
if __name__ == '__main__':
Thread(target = f).start()
Thread(target = tradingview).start()
for count_var_short, count_var_long in tradingview():
trader(count_var_short,count_var_long)