0
집중하다
1
수행원

비동기 문제:

만든 날짜: 2023-03-17 22:48:45, 업데이트 날짜: 2023-03-17 22:49:07
comments   1
hits   1126

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 모든 계약 통화 쌍 이름을 얻고 싶습니다. 감사합니다.