下面用python编写的代码使用websocket实时获取比特戳交换的加密币(以太币以美元计)的价格。它在屏幕上打印下载的信息。在
import pusherclient
import logging
def connect_handler(data):
trades_channel_ethusd = pusher.subscribe("live_trades_ethusd")
trades_channel_ethusd.bind('trade', trade_callback_ethusd)
def trade_callback_ethusd(data):
print(data)
pusher = pusherclient.Pusher("de504dc5763aeef9ff52")
pusher.connection.logger.setLevel(logging.WARNING)
pusher.connection.bind('pusher:connection_established', connect_handler)
pusher.connect()
如果我想对orderbook执行同样的操作,我们应该将“live_trades_ethusd”更改为“diff_order_book_ethusd”。(^ a1)
但是,当我替换字符串时,它什么也不返回。是websocket失败吗?在
编辑:
正确的代码是:
^{pr2}$
简短回答
将
bind
行改为以下内容完整答案
订阅WebSocket时,请确保绑定到正确的事件名称。“previous”调用(即
live_trades_ethusd
)绑定到“trade”事件,其中diff_order_book_ethusd
调用绑定到“data”事件相关问题 更多 >
编程相关推荐