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())
O mesmo código, que não é reportado no VSCODE, é reportado no nosso: Traceback (most recent call last): File "<string>", line 1248, in init_ctx File "<string>", line 62, in <module> 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
Qual é o motivo da solicitação? Quero obter todos os nomes de pares de moedas do contrato.
"TypeError: Object of type coroutine is not JSON serializable":这个错误表示您尝试将一个类型为 coroutine 的对象序列化为 JSON。您可能需要先使用 await 运行 coroutine,然后序列化它的结果。
"RuntimeWarning: coroutine 'main' was never awaited":这个警告表示 coroutine 函数 'main' 被调用了,但从未被 await 运行,这意味着该函数还没有被异步执行。为了解决这个问题,您应该在调用 coroutine 函数时使用 await 关键字,或使用适当的异步方法运行它。
- 1
