在Pusher客户端接收活动



我正在尝试使用Python连接到Bitstamp Websocket API。

但是,我在任何地方都找不到一个体面的教程或解释。

我需要的是接收现场价格股票。

我尝试使用此库,但没有收到任何现场价格。我想我可能缺少一些东西,因为我是新的Websocket。

这是我的代码:

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")

我在运行此代码时看到的所有 - 完成

我如何收到价格实时更新?

在代码末尾添加一个way循环:

while True:
    time.sleep(1)

最新更新