火币网行情获取的websocket客户端
生活随笔
收集整理的這篇文章主要介紹了
火币网行情获取的websocket客户端
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
從驗證結果看應該是網絡關閉了,不過程序寫的不錯,可以作為其它websocket客戶端的測試程序
?
# !/usr/bin/env python # -*- coding: utf-8 -*- # author: luhx # https://pypi.org/project/websocket-client/ # pip install websocket-client # 火幣數據調試, 感覺這個websocket客戶端很好用from websocket import create_connection import gzip import timeif __name__ == '__main__':while(1):try:ws = create_connection("wss://api.huobipro.com/ws")breakexcept:print('connect ws error,retry...')time.sleep(5)# 訂閱 KLine 數據tradeStr="""{"sub": "market.ethusdt.kline.1min","id": "id10"}"""ws.send(tradeStr)while(1):compressData=ws.recv()result=gzip.decompress(compressData).decode('utf-8')if result[:7] == '{"ping"':ts=result[8:21]pong='{"pong":'+ts+'}'ws.send(pong)ws.send(tradeStr)else:print(result)總結
以上是生活随笔為你收集整理的火币网行情获取的websocket客户端的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 趋势解读:John D′Ambrosia
- 下一篇: NetCore入门篇:(二)Net Co