1.08K 浏览
0

一个异步代码,没法回测成功。帮看下是什么问题?

////////////////////////////////////////

在使用天勤量化之前,默认您已经知晓并同意以下免责条款,如果不同意请立即停止使用:https://www.shinnytech.com/blog/disclaimer/
INFO – 您可以访问 http://127.0.0.1:52092 查看策略绘制出的 K 线图形。
Task was destroyed but it is pending!
task: <Task pending name=’Task-1′ coro=<TqBaseApi._windows_patch() running at d:\veighna_studio\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 d:\veighna_studio\lib\site-packages\tqsdk\api.py:3688> wait_for=<Future pending cb=[Task.task_wakeup()]> cb=[TqBaseApi._on_task_done()]>
Exception ignored in: <coroutine object TqApi._notify_watcher at 0x0000020A41F13CA0>
Traceback (most recent call last):
File “d:\veighna_studio\lib\site-packages\tqsdk\api.py”, line 3688, in _notify_watcher
File “d:\veighna_studio\lib\site-packages\tqsdk\channel.py”, line 143, in __anext__
File “d:\veighna_studio\lib\asyncio\queues.py”, line 161, in get
File “d:\veighna_studio\lib\site-packages\tqsdk\baseApi.py”, line 50, in _call_soon
File “d:\veighna_studio\lib\asyncio\base_events.py”, line 753, in call_soon
File “d:\veighna_studio\lib\asyncio\base_events.py”, line 515, in _check_closed
RuntimeError: Event loop is closed
Task was destroyed but it is pending!
task: <Task pending name=’Task-3′ coro=<TqConnect._run() running at d:\veighna_studio\lib\site-packages\tqsdk\connect.py:190> 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-4′ coro=<TqReconnect._run() running at d:\veighna_studio\lib\site-packages\tqsdk\connect.py:275> 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-5′ coro=<TqSymbols._run() running at d:\veighna_studio\lib\site-packages\tqsdk\symbols.py:29> 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-6′ coro=<TqBacktest._run() running at d:\veighna_studio\lib\site-packages\tqsdk\backtest\backtest.py:148> 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-7′ coro=<BaseSim._run() running at d:\veighna_studio\lib\site-packages\tqsdk\tradeable\sim\basesim.py:78> 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-8′ coro=<TqWebHelper._run() running at d:\veighna_studio\lib\site-packages\tqsdk\tqwebhelper.py:121> 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-9′ coro=<DataExtension._run() running at d:\veighna_studio\lib\site-packages\tqsdk\data_extension.py:85> wait_for=<Future pending cb=[Task.task_wakeup()]> cb=[TqBaseApi._on_task_done()]>
Exception ignored in: <coroutine object TqConnect._run at 0x0000020A41F13D80>
Traceback (most recent call last):
File “d:\veighna_studio\lib\site-packages\tqsdk\connect.py”, line 157, in _run
File “d:\veighna_studio\lib\site-packages\websockets\legacy\client.py”, line 637, in __aexit__
File “d:\veighna_studio\lib\site-packages\websockets\legacy\protocol.py”, line 769, in close
File “d:\veighna_studio\lib\site-packages\websockets\legacy\async_timeout.py”, line 74, in timeout
RuntimeError: no running event loop
Task was destroyed but it is pending!
task: <Task pending name=’Task-21′ coro=<TqConnect._send_handler() running at d:\veighna_studio\lib\site-packages\tqsdk\connect.py:246> wait_for=<Future cancelled>>
Exception ignored in: <coroutine object TqReconnect._run at 0x0000020A41F13AE0>
Traceback (most recent call last):
File “d:\veighna_studio\lib\site-packages\tqsdk\connect.py”, line 325, in _run
File “d:\veighna_studio\lib\site-packages\tqsdk\baseApi.py”, line 50, in _call_soon
File “d:\veighna_studio\lib\asyncio\base_events.py”, line 753, in call_soon
File “d:\veighna_studio\lib\asyncio\base_events.py”, line 515, in _check_closed
RuntimeError: Event loop is closed
Task was destroyed but it is pending!
task: <Task pending name=’Task-10′ coro=<TqReconnect._send_handler() running at d:\veighna_studio\lib\site-packages\tqsdk\connect.py:329> wait_for=<Future cancelled>>
Exception ignored in: <coroutine object TqSymbols._run at 0x0000020A41F13F40>
Traceback (most recent call last):
File “d:\veighna_studio\lib\site-packages\tqsdk\symbols.py”, line 63, in _run
File “d:\veighna_studio\lib\site-packages\tqsdk\baseApi.py”, line 50, in _call_soon
File “d:\veighna_studio\lib\asyncio\base_events.py”, line 753, in call_soon
File “d:\veighna_studio\lib\asyncio\base_events.py”, line 515, in _check_closed
RuntimeError: Event loop is closed
Task was destroyed but it is pending!
task: <Task pending name=’Task-11′ coro=<TqSymbols._sim_handler() running at d:\veighna_studio\lib\site-packages\tqsdk\symbols.py:68> wait_for=<Future cancelled>>
Exception ignored in: <coroutine object TqBacktest._run at 0x0000020A41F13DF0>
Traceback (most recent call last):
File “d:\veighna_studio\lib\site-packages\tqsdk\backtest\backtest.py”, line 196, in _run
File “d:\veighna_studio\lib\site-packages\tqsdk\baseApi.py”, line 50, in _call_soon
File “d:\veighna_studio\lib\asyncio\base_events.py”, line 753, in call_soon
File “d:\veighna_studio\lib\asyncio\base_events.py”, line 515, in _check_closed
RuntimeError: Event loop is closed
Task was destroyed but it is pending!
task: <Task pending name=’Task-12′ coro=<TqBacktest._md_handler() running at d:\veighna_studio\lib\site-packages\tqsdk\backtest\backtest.py:200> wait_for=<Future cancelled>>
INFO – 模拟交易成交记录, 账户: TQSIM
INFO – 模拟交易账户资金, 账户: TQSIM
INFO – 日期: 2024-04-15, 账户权益: 10000000.00, 可用资金: 10000000.00, 浮动盈亏: 0.00, 持仓盈亏: 0.00, 平仓盈亏: 0.00, 市值: 0.00, 保证金: 0.00, 手续费: 0.00, 风险度: 0.00%
Exception ignored in: <coroutine object BaseSim._run at 0x0000020A45AAC040>
Traceback (most recent call last):
File “d:\veighna_studio\lib\site-packages\tqsdk\tradeable\sim\basesim.py”, line 80, in _run
File “d:\veighna_studio\lib\site-packages\tqsdk\tradeable\sim\basesim.py”, line 155, in _handle_stat_report
File “d:\veighna_studio\lib\site-packages\tqsdk\tradeable\sim\tqsim.py”, line 230, in _report
File “d:\veighna_studio\lib\site-packages\tqsdk\report.py”, line 52, in __init__
File “d:\veighna_studio\lib\site-packages\tqsdk\report.py”, line 62, in _get_df
File “d:\veighna_studio\lib\site-packages\pandas\core\frame.py”, line 839, in __init__
File “d:\veighna_studio\lib\site-packages\pandas\core\indexes\base.py”, line 7642, in ensure_index
File “lib.pyx”, line 840, in pandas._libs.lib.is_all_arraylike
ImportError: sys.meta_path is None, Python is likely shutting down
Task was destroyed but it is pending!
task: <Task pending name=’Task-13′ coro=<TqModule._up_handler() running at d:\veighna_studio\lib\site-packages\tqsdk\baseModule.py:51> wait_for=<Future cancelled>>
Exception ignored in: <coroutine object TqWebHelper._run at 0x0000020A45AAC0B0>
Traceback (most recent call last):
File “d:\veighna_studio\lib\site-packages\tqsdk\tqwebhelper.py”, line 162, in _run
File “d:\veighna_studio\lib\site-packages\tqsdk\baseApi.py”, line 50, in _call_soon
File “d:\veighna_studio\lib\asyncio\base_events.py”, line 753, in call_soon
File “d:\veighna_studio\lib\asyncio\base_events.py”, line 515, in _check_closed
RuntimeError: Event loop is closed
Task was destroyed but it is pending!
task: <Task pending name=’Task-14′ coro=<TqWebHelper._data_handler() running at d:\veighna_studio\lib\site-packages\tqsdk\tqwebhelper.py:172> wait_for=<Future cancelled>>
Exception ignored in: <coroutine object DataExtension._run at 0x0000020A45AAC120>
Traceback (most recent call last):
File “d:\veighna_studio\lib\site-packages\tqsdk\data_extension.py”, line 103, in _run
File “d:\veighna_studio\lib\site-packages\tqsdk\baseApi.py”, line 50, in _call_soon
File “d:\veighna_studio\lib\asyncio\base_events.py”, line 753, in call_soon
File “d:\veighna_studio\lib\asyncio\base_events.py”, line 515, in _check_closed
RuntimeError: Event loop is closed
Task was destroyed but it is pending!
task: <Task pending name=’Task-16′ coro=<DataExtension._md_handler() running at d:\veighna_studio\lib\site-packages\tqsdk\data_extension.py:107> wait_for=<Future cancelled>>
Task was destroyed but it is pending!
task: <Task pending name=’Task-15′ coro=<TqWebHelper.link_httpserver() running at d:\veighna_studio\lib\site-packages\tqsdk\tqwebhelper.py:320> wait_for=<Future pending cb=[Task.task_wakeup()]>>
Exception ignored in: <coroutine object TqWebHelper.link_httpserver at 0x0000020A45AAD620>
Traceback (most recent call last):
File “d:\veighna_studio\lib\site-packages\tqsdk\tqwebhelper.py”, line 323, in link_httpserver
File “d:\veighna_studio\lib\site-packages\aiohttp\web_runner.py”, line 316, in cleanup
File “d:\veighna_studio\lib\site-packages\aiohttp\web_server.py”, line 64, in shutdown
File “d:\veighna_studio\lib\asyncio\tasks.py”, line 715, in gather
File “d:\veighna_studio\lib\asyncio\events.py”, line 754, in get_event_loop_policy
File “d:\veighna_studio\lib\asyncio\events.py”, line 747, in _init_event_loop_policy
ImportError: sys.meta_path is None, Python is likely shutting down
Task was destroyed but it is pending!
task: <Task pending name=’Task-18′ coro=<WebSocketCommonProtocol.transfer_data() running at d:\veighna_studio\lib\site-packages\websockets\legacy\protocol.py:963> wait_for=<Future pending cb=[Task.task_wakeup()]> cb=[Task.task_wakeup()]>
Task was destroyed but it is pending!
task: <Task pending name=’Task-19′ coro=<WebSocketCommonProtocol.keepalive_ping() running at d:\veighna_studio\lib\site-packages\websockets\legacy\protocol.py:1254> wait_for=<Future pending cb=[Task.task_wakeup()]>>
Task was destroyed but it is pending!
task: <Task pending name=’Task-20′ coro=<WebSocketCommonProtocol.close_connection() running at d:\veighna_studio\lib\site-packages\websockets\legacy\protocol.py:1301> wait_for=<Task pending name=’Task-18′ coro=<WebSocketCommonProtocol.transfer_data() running at d:\veighna_studio\lib\site-packages\websockets\legacy\protocol.py:963> wait_for=<Future pending cb=[Task.task_wakeup()]> cb=[Task.task_wakeup()]>>
Exception ignored in: <coroutine object WebSocketCommonProtocol.close_connection at 0x0000020A45AAE180>
Traceback (most recent call last):
File “d:\veighna_studio\lib\site-packages\websockets\legacy\protocol.py”, line 1337, in close_connection
File “d:\veighna_studio\lib\site-packages\websockets\legacy\protocol.py”, line 1355, in close_transport
File “d:\veighna_studio\lib\site-packages\websockets\legacy\protocol.py”, line 1379, in wait_for_connection_lost
File “d:\veighna_studio\lib\site-packages\websockets\legacy\async_timeout.py”, line 74, in timeout
RuntimeError: no running event loop
Task was destroyed but it is pending!
task: <Task pending name=’Task-22′ coro=<ATR_one() running at E:\10交易\天勤\CL\策略\3k\3k_async.py:21> cb=[TqBaseApi._on_task_done()]>
Task was destroyed but it is pending!
task: <Task pending name=’Task-23′ coro=<ATR_one() running at E:\10交易\天勤\CL\策略\3k\3k_async.py:21> cb=[TqBaseApi._on_task_done()]>
sys:1: RuntimeWarning: coroutine ‘ATR_one’ was never awaited

llex_2024 发表新评论 2024年6月16日

问题已解决,未添加:api.wait_update()