我正在尝试使用Python连接BitStamp Websocket API。
然而,我无法在任何地方找到一个合适的教程或解释这个过程。
我需要接收实时价格行情。
我尝试使用this库,但是我没有接收到任何实时价格。我认为我可能错过了什么,因为我是WebSockets的新手。
这是我的代码:
import pusherclient
import sys
# Add a logging handler so we can see the raw communication data
import logging
root = logging.getLogger()
root.setLevel(logging.INFO)
ch = logging.StreamHandler(sys.stdout)
root.addHandler(ch)
global pusher
# We can't subscribe until we've connected, so we use a callback handler
# to subscribe when able
def connect_handler(data):
channel = pusher.subscribe('live_trades')
channel.bind('trade', callback)
appkey = "de504dc5763aeef9ff52"
pusher = pusherclient.Pusher(appkey)
pusher.connection.bind('pusher:connection_established', connect_handler)
pusher.connect()
print("finished")
当我运行这段代码时,我只看到“已完成”字样。
如何实时获取价格更新?