天择量化公共接口文档
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
1.1 KiB

  1. import asyncio
  2. import websockets
  3. import json
  4. # WebSocket URI
  5. # URI: ws://192.168.34.9:8765
  6. # 请求参数
  7. # 平台 (platform): 指定交易平台的名称,gate_spot/gate_swap_u/binance_spot/binance_swap_u/bybit_spot/bybit_swap_u/okx_spot/okx_swap_u
  8. # 基础货币 (base): 交易对中的基础货币,如 btc。
  9. # 结算货币 (settle): 交易对中的结算货币,如 usdt。
  10. # 开始时间 (start_data): 数据请求的开始时间(格式应为 YYYY-MM-DD-HH,但注意您代码中写的是 start_data 可能是 start_date 的笔误)。
  11. # 结束时间 (end_data): 数据请求的结束时间(同上,格式应为 YYYY-MM-DD-HH,且可能应为 end_date)。
  12. async def connect_to_server():
  13. uri = "ws://192.168.34.9:8765"
  14. async with websockets.connect(uri) as websocket:
  15. msg = {'platform': 'gate_spot', 'base': 'btc', "settle": "usdt", "start_data": "2024-08-13-18",
  16. "end_data": "2024-08-13-18"}
  17. await websocket.send(f"{json.dumps(msg)}")
  18. while True:
  19. response = await websocket.recv()
  20. print(json.loads(response))
  21. if __name__ == "__main__":
  22. asyncio.run(connect_to_server())