在 Pusher 客户端中接收事件
Receiving events in Pusher client
我正在尝试使用 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")
当我 运行 这段代码时我看到的是 - 已完成
我怎样才能收到价格的实时更新?
在代码末尾添加一个while循环:
while True:
time.sleep(1)
我正在尝试使用 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")
当我 运行 这段代码时我看到的是 - 已完成
我怎样才能收到价格的实时更新?
在代码末尾添加一个while循环:
while True:
time.sleep(1)