问题
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