在 Pusher 客户端接收事件

编程入门 行业动态 更新时间:2024-10-26 12:35:07
本文介绍了在 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 客户端接收事件

本文发布于:2023-10-26 19:18:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1531104.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:客户端   事件   Pusher

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!