日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

火币网行情获取的websocket客户端

發布時間:2025/6/16 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 火币网行情获取的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客户端的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。