2016-12-18 98 views
3

我试图用Python连接到BitStamp Websocket API在Pusher客户端中接收事件

但是,我无法找到一个体面的教程或任何地方的过程的解释。

我需要的是接收现场报价。

我尝试使用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") 

我看到,当我运行这段代码是 - 成品

我怎么能接受的价格实时更新?

+0

你找到获取数据,然后通过StreamHandler中的更好的办法? –

回答

2

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

while True: 
    time.sleep(1)