我使用HuobiWebSocket,您可以看到我下面的代码。它在开始时工作得很好,但过了一段时间,它在循环中阻塞,并在无限循环中打印相同的内容。你能帮我解决这个问题吗
from websocket import create_connection
import gzip
import json
ws = create_connection("wss://api-aws.huobi.pro/ws")
time.sleep(5)
tradeStr_tradeDetail="""
{"sub": "market.ethusdt.trade.detail"}
"""
ws.send(tradeStr_tradeDetail)
count = 0
while True:
try:
result = gzip.decompress(ws.recv()).decode('utf-8', 'backslashreplace')
except:
pass
try:
if result[:7] == '{"ping"':
count = count+1
elif result[:7] == '{"ping"' and count%3==0:
ts=result[8:21]
pong='{"pong":'+ts+'}'
ws.send(pong)
else:
pass
except:
pass
try:
print(result)
except:
pass
time.sleep(1)
目前没有回答
相关问题 更多 >
编程相关推荐