我正在尝试将新的 websocket API 与 Poloniex 一起使用。Wamp 现在已被弃用,关于如何对实时公共数据(如音量等)进行简单调用的信息很少。
我发现这段代码似乎实现了这个套接字,但出现在比特流中。当我运行代码时,它会很好地调用标头并获得响应标头,并且似乎可以发送和接收数据,但随后会关闭套接字。如何订阅音量频道并解码流数据?
import websocket
import threading
import time
import json
from threading import Thread
def on_message(ws, message):
print(message)
def on_error(ws, error):
print(error)
def on_close(ws):
print("### closed ###")
def on_open(ws):
print("ON OPEN")
def run(*args):
ws.send(json.dumps({'command':'subscribe','channel':1003}))
while True:
time.sleep(1)
ws.close()
print("thread terminating...")
threading.Thread(target=run).start()
if __name__ == "__main__":
websocket.enableTrace(True)
ws = websocket.WebSocketApp("wss://api2.poloniex.com/",
on_message = on_message,
on_error = on_error,
on_close = on_close)
ws.on_open = on_open
ws.run_forever()
Am expecting a streaming connection to volume data but get this:
ON OPEN
send: b"\x81\xa9.)\x1d\xb8U\x0b~\xd7CD|\xd6J\x0b'\x98\x0cZh\xda]Jo\xd1LL?\x94\x0e\x0b~\xd0OGs\xddB\x0b'\x98\x1f\x19-\x8bS"
[1003,1]
unorderable types: float() > NoneType()
send: b'\x88\x82fWPGe\xbf'
### closed ###