pip install websocket-client
import websocket
import json
if __name__ == ‘__main__‘:
ws = websocket.create_connection(‘wss://ws.bitforex.com/mkapi/coinGroup1/ws‘, timeout=10)
ws.send(
‘[{"type": "subHq", "event": "trade", "param": {"businessType": "coin-usdt-btc", "dType": 0, "size": 100}}]‘) # 订阅交易数据
while True:
content = ws.recv()
for data in json.loads(content).get("data"):
print(data)
ws.close()
原文:https://www.cnblogs.com/iFanLiwei/p/12846677.html