币安websocket订阅永续合约行情信息

Author: GCC, Date: 2021-11-02 22:36:28
Tags:


import json
def main():
    LogStatus("正在连接...")
    # client = Dial("wss://stream.binance.com:9443/stream?streams=btcusdt@aggTrade/ethusdt@aggTrade|reconnect=true")    #多个交易对
    # client = Dial("wss://stream.binance.com:9443/ws/btcusdt@aggTrade|reconnect=true")    #单个交易对
    # client = Dial("wss://dstream.binance.com/ws/btcusd_perp@aggTrade|reconnect=true")    #币本位,ticker
    client = Dial("wss://fstream.binance.com/ws/btcusdt@aggTrade|reconnect=true")
    if not client:    
        Log("连接失败, 程序退出")
        return
    while True:
        buf = client.read(-2)
        Log('tt',buf)
        if buf:
            obj = json.loads(buf)
            # Log(obj)
            # Log('交易对',obj['data']['s'], ' 价格', obj['data']['p'])    #多个交易对 
            Log(obj['p'])    #测试
        Sleep(5000)
    client.close()

More

oklong 老哥,代写?怎么联系

GCC 本人水平有限,暂不接代写,抱歉