我正在尝试订阅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()