Receiving events in Pusher client

依然范特西╮ 提交于 2021-01-27 15:51:43

问题


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.

What I need is to receive the live price ticker.

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.

Here is my code:

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

How can I receive live updates on the price?


回答1:


Add a while loop at the end of the code:

while True:
    time.sleep(1)


来源:https://stackoverflow.com/questions/41208003/receiving-events-in-pusher-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!