我想订阅Bitfinex.com websocket API公共频道BTCUSD
.
以下是代码:
from websocket import create_connection
ws = create_connection("wss://api2.bitfinex.com:3000/ws")
ws.connect("wss://api2.bitfinex.com:3000/ws")
ws.send("LTCBTC")
while True:
result = ws.recv()
print ("Received '%s'" % result)
ws.close()
我相信ws.send("BTCUSD")
是公共频道的订户吗?我收到一条消息,我想这是在确认订阅({"event":"info","version":1}
,但之后我没有收到数据流.我错过了什么?
更新:以下是最终有效的代码.
import json
from websocket import create_connection
ws = create_connection("wss://api2.bitfinex.com:3000/ws")
#ws.connect("wss://api2.bitfinex.com:3000/ws")
ws.send(json.dumps({
"event": "subscribe",
"channel": "book",
"pair": "BTCUSD",
"prec": "P0"
}))
while True:
result = ws.recv()
result = json.loads(result)
print ("Received '%s'" % result)
ws.close()