HITBTC WebSocket API客户端
hitbtc-wss的Python项目详细描述
hitbtc_wss
用python 3编写的hitbtcwebsocketapi2.0客户端。
从Crypto-toolbox/hitbtc_wss分叉。在撰写本文时, Crypto工具箱在7个月内没有接受他的回购请求。看起来他们可能 继续做其他事情。我想我应该把球捡起来然后带着它跑。
发布历史记录
Date | Description |
---|---|
09/02/2018 | Published bug fix to PyPi so the ^{ |
客户端通过控制台可视化地提供数据,并通过其HitBTC.recv()
提供python对象。
需要注意的是,这不会直接从api接收数据-
相反,数据是从queue.Queue
对象中提取的,该对象的默认长度为
100件。因此,只有最后100条消息将被缓存-请确保处理这些消息
足够快,或者增加队列的长度(可以通过传递
实例化)。
默认情况下,数据是解压缩的-这意味着您将永远看不到原始的JSONRPC
消息
(这也可以通过在初始化时传递raw=True
来关闭)。然而,这也会
关闭对错误消息等的所有处理。
有关客户及其方法的详细说明,请参阅 readthedocs.org
安装
稳定:pip install hitbtc_wss
释放候选者:pip install --pre hitbtc_wss
示例用法
importtimeimportqueuefromhitbtc_wssimportHitBTCc=HitBTC()c.start()# start the websocket connectiontime.sleep(2)# Give the socket some time to connectc.subscribe_ticker(symbol='ETHBTC')# Subscribe to ticker data for the pair ETHBTCwhileTrue:try:data=c.recv()exceptqueue.Empty:continue# process data from websocket...c.stop()