在 Pusher 客户端接收事件 [英] Receiving events in Pusher client

查看:77
本文介绍了在 Pusher 客户端接收事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Python 连接到 BitStamp Websocket API.

I'm trying to connect to the BitStamp Websocket API with Python.

但是,我在任何地方都找不到像样的教程或过程的解释.

However, I cannot find a decent tutorial or explanation of the process anywhere.

我需要的是接收实时价格代码.

我尝试使用 this 库,但我没有收到任何实时价格.我想我可能遗漏了一些东西,因为我是 WebSockets 的新手.

I tried using this library but I'm not receiving any live price. I think I'm probably missing something because I'm new with 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")

当我运行此代码时,我看到的只是 - 已完成

All I see when I run this code is - Finished

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

推荐答案

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

Add a while loop at the end of the code:

while True:
    time.sleep(1)

这篇关于在 Pusher 客户端接收事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆