import asyncio import aiohttp import websockets import json import pandas as pd from datetime import datetime
async def get_usdt_symbols(): url = “https://fapi.binance.com/fapi/v1/exchangeInfo” async with aiohttp.ClientSession() as session: async with session.get(url) as resp: response = await resp.json() symbols = [symbol_info[“symbol”] for symbol_info in response[“symbols”] if symbol_info[“quoteAsset”] == “USDT” and symbol_info[“contractType”] == “PERPETUAL”] return symbols
async def main(): symbol_list = await get_usdt_symbols() print(f”Total USDT perpetual symbols: {len(symbol_list)}“)
# 在此处添加WebSocket连接和数据处理代码
if name == “main”: loop = asyncio.get_event_loop() loop.run_until_complete(main())
同样的代码,在VSCODE中就不报错,在咱们这就报错:Traceback (most recent call last): File “”, line 1248, in init_ctx File “”, line 62, in TypeError: Object of type coroutine is not JSON serializable sys:1: RuntimeWarning: coroutine ‘main’ was never awaited RuntimeWarning: Enable tracemalloc to get the object allocation traceback 请问是什么原因呢?想取得所有合约货币对名称 谢谢