代码如下:
async def main(api, symbols): async def fetch_kline(api, symbol): kline = await api.get_kline_serial(symbol, 86400, 30) return kline tasks = [fetch_kline(api, symbol) for symbol in symbols] klines = await asyncio.gather(*tasks) print(klines) api_sim = TqApi(TqSim(), auth=TqAuth("xxxxx", "xxxxx"), disable_print=True) symbols = api_sim.query_cont_quotes() asyncio.run(main(api_sim, symbols)) api_sim.close()
报错:
File “C:\Users\Administrator\PycharmProjects\TurtleTrading\venv\Lib\site-packages\tqsdk\api.py”, line 724, in get_kline_serial
if not self.wait_update(deadline=deadline, _task=[task, serial[“df”].__dict__[“_task”]]):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\Administrator\PycharmProjects\TurtleTrading\venv\Lib\site-packages\tqsdk\api.py”, line 1879, in wait_update
raise Exception(
Exception: TqSdk 使用了 python3 的原生协程和异步通讯库 asyncio,您所使用的 IDE 不支持 asyncio, 请使用 pycharm 或其它支持 asyncio 的 IDE
Task was destroyed but it is pending!
task: <Task pending name=’Task-1′ coro=<TqBaseApi._windows_patch() running at C:\Users\Administrator\PycharmProjects\TurtleTrading\venv\Lib\site-packages\tqsdk\baseApi.py:119> wait_for=<Future pending cb=[Task.task_wakeup()]> cb=[TqBaseApi._on_task_done()]>
Task was destroyed but it is pending!
task: <Task pending name=’Task-2′ coro=<TqApi._notify_watcher() running at C:\Users\Administrator\PycharmProjects\TurtleTrading\venv\Lib\site-packages\tqsdk\api.py:3640> wait_for=<Future pending cb=[Task.task_wakeup()]> cb=[TqBaseApi._on_task_done()]>
Exception ignored in: <coroutine object TqApi._notify_watcher at 0x000001F6C0A638B0>