619 浏览
0

D:\Programs\Python\Python311\python.exe D:\Learning\program_py\TqSdk_2023_12\demo_CZCE_AP.py
在使用天勤量化之前,默认您已经知晓并同意以下免责条款,如果不同意请立即停止使用:https://www.shinnytech.com/blog/disclaimer/
[‘401’, ‘405 ‘, ‘410’]
3
2023-12-16 07:35:39 – INFO – 通知 : 与 wss://api.shinnytech.com/t/nfmd/front/mobile 的网络连接已建立
2023-12-16 07:35:39 – INFO – 通知 snowfeng2019: 与 wss://otg-sim.shinnytech.com/trade 的网络连接已建立
2023-12-16 07:35:39 – INFO – 通知 snowfeng2019: 登录成功
2023
12
———————
CZCE.FG401
{‘contract_id’: ‘CZCE.FG401’, ‘open_interest’: 111418, ‘volume’: 39654}
+++++++++++++++++
CZCE.FG405
Traceback (most recent call last):
File “D:\Learning\program_py\TqSdk_2023_12\demo_CZCE_AP.py”, line 83, in <module>
get_open_interest(“CZCE”,”FG”,List_candiate_month)
File “D:\Learning\program_py\TqSdk_2023_12\demo_CZCE_AP.py”, line 42, in get_open_interest
AP_05_info = api.get_quote(contract_id)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\api.py”, line 431, in get_quote
return self.get_quote_list([symbol])[0]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\api.py”, line 483, in get_quote_list
if not self.wait_update(deadline=deadline, _task=quote_list._task):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\api.py”, line 1898, in wait_update
self._run_until_task_done(task=update_task, deadline=deadline)
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\baseApi.py”, line 88, in _run_until_task_done
self._run_once()
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\baseApi.py”, line 57, in _run_once
raise self._exceptions.pop(0)
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\symbols.py”, line 41, in _run
raise Exception(f”查询合约服务报错 {query_result[‘error’]}”)
Exception: 查询合约服务报错 failed to execute graphql operation, errors: [variable instrument_id: [CZCE.FG405 ] contains non-existent instrument: CZCE.FG405 ]
Task was destroyed but it is pending!
task: <Task pending name=’Task-2′ coro=<TqApi._notify_watcher() running at D:\Programs\Python\Python311\Lib\site-packages\tqsdk\api.py:3625> 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-1′ coro=<TqBaseApi._windows_patch() running at D:\Programs\Python\Python311\Lib\site-packages\tqsdk\baseApi.py:119> wait_for=<Future pending cb=[Task.task_wakeup()]> cb=[TqBaseApi._on_task_done()]>
Exception ignored in: <coroutine object TqApi._notify_watcher at 0x000002E2527BFA00>
Traceback (most recent call last):
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\api.py”, line 3625, in _notify_watcher
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\channel.py”, line 143, in __anext__
File “D:\Programs\Python\Python311\Lib\asyncio\queues.py”, line 160, in get
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\baseApi.py”, line 50, in _call_soon
File “D:\Programs\Python\Python311\Lib\asyncio\base_events.py”, line 761, in call_soon
File “D:\Programs\Python\Python311\Lib\asyncio\base_events.py”, line 519, 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:\Programs\Python\Python311\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:\Programs\Python\Python311\Lib\site-packages\tqsdk\connect.py:274> 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=<TqTradingStatus._run() running at D:\Programs\Python\Python311\Lib\site-packages\tqsdk\trading_status.py:26> 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=<TqConnect._run() running at D:\Programs\Python\Python311\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-8′ coro=<TqReconnect._run() running at D:\Programs\Python\Python311\Lib\site-packages\tqsdk\connect.py:274> 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=<BaseOtg._run() running at D:\Programs\Python\Python311\Lib\site-packages\tqsdk\tradeable\otg\base_otg.py:109> 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-10′ coro=<TqWebHelper._run() running at D:\Programs\Python\Python311\Lib\site-packages\tqsdk\tqwebhelper.py:80> 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-11′ coro=<DataExtension._run() running at D:\Programs\Python\Python311\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 0x000002E252786C20>
Traceback (most recent call last):
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\connect.py”, line 157, in _run
File “D:\Programs\Python\Python311\Lib\site-packages\websockets\legacy\client.py”, line 637, in __aexit__
File “D:\Programs\Python\Python311\Lib\site-packages\websockets\legacy\protocol.py”, line 769, in close
File “D:\Programs\Python\Python311\Lib\asyncio\timeouts.py”, line 141, in timeout
RuntimeError: no running event loop
Task was destroyed but it is pending!
task: <Task cancelling name=’Task-25′ coro=<TqConnect._send_handler() running at D:\Programs\Python\Python311\Lib\site-packages\tqsdk\connect.py:245> wait_for=<Future cancelled>>
Exception ignored in: <coroutine object TqReconnect._run at 0x000002E2527BB400>
Traceback (most recent call last):
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\connect.py”, line 324, in _run
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\baseApi.py”, line 50, in _call_soon
File “D:\Programs\Python\Python311\Lib\asyncio\base_events.py”, line 761, in call_soon
File “D:\Programs\Python\Python311\Lib\asyncio\base_events.py”, line 519, in _check_closed
RuntimeError: Event loop is closed
Task was destroyed but it is pending!
task: <Task cancelling name=’Task-12′ coro=<TqReconnect._send_handler() running at D:\Programs\Python\Python311\Lib\site-packages\tqsdk\connect.py:328> wait_for=<Future cancelled>>
Exception ignored in: <coroutine object TqTradingStatus._run at 0x000002E21F328890>
Traceback (most recent call last):
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\trading_status.py”, line 26, in _run
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\baseModule.py”, line 47, in _run
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\baseModule.py”, line 47, in <listcomp>
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\baseApi.py”, line 50, in _call_soon
File “D:\Programs\Python\Python311\Lib\asyncio\base_events.py”, line 761, in call_soon
File “D:\Programs\Python\Python311\Lib\asyncio\base_events.py”, line 519, in _check_closed
RuntimeError: Event loop is closed
Task was destroyed but it is pending!
task: <Task cancelling name=’Task-14′ coro=<TqModule._up_handler() running at D:\Programs\Python\Python311\Lib\site-packages\tqsdk\baseModule.py:51> wait_for=<Future cancelled>>
Exception ignored in: <coroutine object TqConnect._run at 0x000002E252787100>
Traceback (most recent call last):
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\connect.py”, line 157, in _run
File “D:\Programs\Python\Python311\Lib\site-packages\websockets\legacy\client.py”, line 637, in __aexit__
File “D:\Programs\Python\Python311\Lib\site-packages\websockets\legacy\protocol.py”, line 769, in close
File “D:\Programs\Python\Python311\Lib\asyncio\timeouts.py”, line 141, in timeout
RuntimeError: no running event loop
Task was destroyed but it is pending!
task: <Task cancelling name=’Task-30′ coro=<TqConnect._send_handler() running at D:\Programs\Python\Python311\Lib\site-packages\tqsdk\connect.py:245> wait_for=<Future cancelled>>
Exception ignored in: <coroutine object TqReconnect._run at 0x000002E2527BB570>
Traceback (most recent call last):
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\connect.py”, line 324, in _run
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\baseApi.py”, line 50, in _call_soon
File “D:\Programs\Python\Python311\Lib\asyncio\base_events.py”, line 761, in call_soon
File “D:\Programs\Python\Python311\Lib\asyncio\base_events.py”, line 519, in _check_closed
RuntimeError: Event loop is closed
Task was destroyed but it is pending!
task: <Task cancelling name=’Task-16′ coro=<TqReconnect._send_handler() running at D:\Programs\Python\Python311\Lib\site-packages\tqsdk\connect.py:328> wait_for=<Future cancelled>>
Exception ignored in: <coroutine object BaseOtg._run at 0x000002E2529689C0>
Traceback (most recent call last):
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\tradeable\otg\base_otg.py”, line 109, in _run
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\baseModule.py”, line 47, in _run
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\baseModule.py”, line 47, in <listcomp>
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\baseApi.py”, line 50, in _call_soon
File “D:\Programs\Python\Python311\Lib\asyncio\base_events.py”, line 761, in call_soon
File “D:\Programs\Python\Python311\Lib\asyncio\base_events.py”, line 519, in _check_closed
RuntimeError: Event loop is closed
Task was destroyed but it is pending!
task: <Task cancelling name=’Task-17′ coro=<TqModule._up_handler() running at D:\Programs\Python\Python311\Lib\site-packages\tqsdk\baseModule.py:51> wait_for=<Future cancelled>>
Exception ignored in: <coroutine object TqWebHelper._run at 0x000002E2526ED170>
Traceback (most recent call last):
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\tqwebhelper.py”, line 85, in _run
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\baseApi.py”, line 50, in _call_soon
File “D:\Programs\Python\Python311\Lib\asyncio\base_events.py”, line 761, in call_soon
File “D:\Programs\Python\Python311\Lib\asyncio\base_events.py”, line 519, in _check_closed
RuntimeError: Event loop is closed
Task was destroyed but it is pending!
task: <Task cancelling name=’Task-19′ coro=<TqWebHelper._data_handler_without_web() running at D:\Programs\Python\Python311\Lib\site-packages\tqsdk\tqwebhelper.py:168> wait_for=<Future cancelled>>
Exception ignored in: <coroutine object DataExtension._run at 0x000002E252A517A0>
Traceback (most recent call last):
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\data_extension.py”, line 103, in _run
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\baseApi.py”, line 50, in _call_soon
File “D:\Programs\Python\Python311\Lib\asyncio\base_events.py”, line 761, in call_soon
File “D:\Programs\Python\Python311\Lib\asyncio\base_events.py”, line 519, in _check_closed
RuntimeError: Event loop is closed
Task was destroyed but it is pending!
task: <Task cancelling name=’Task-20′ coro=<DataExtension._md_handler() running at D:\Programs\Python\Python311\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=<TqModule._up_handler() running at D:\Programs\Python\Python311\Lib\site-packages\tqsdk\baseModule.py:51> wait_for=<Future pending cb=[Task.task_wakeup()]>>
Task was destroyed but it is pending!
task: <Task pending name=’Task-18′ coro=<TqModule._up_handler() running at D:\Programs\Python\Python311\Lib\site-packages\tqsdk\baseModule.py:51> wait_for=<Future pending cb=[Task.task_wakeup()]>>
Exception ignored in: <coroutine object TqModule._up_handler at 0x000002E2558D2890>
Traceback (most recent call last):
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\baseModule.py”, line 51, in _up_handler
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\channel.py”, line 143, in __anext__
File “D:\Programs\Python\Python311\Lib\asyncio\queues.py”, line 160, in get
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\baseApi.py”, line 50, in _call_soon
File “D:\Programs\Python\Python311\Lib\asyncio\base_events.py”, line 761, in call_soon
File “D:\Programs\Python\Python311\Lib\asyncio\base_events.py”, line 519, in _check_closed
RuntimeError: Event loop is closed
Exception ignored in: <coroutine object TqModule._up_handler at 0x000002E2558D3010>
Traceback (most recent call last):
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\baseModule.py”, line 51, in _up_handler
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\channel.py”, line 143, in __anext__
File “D:\Programs\Python\Python311\Lib\asyncio\queues.py”, line 160, in get
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\baseApi.py”, line 50, in _call_soon
File “D:\Programs\Python\Python311\Lib\asyncio\base_events.py”, line 761, in call_soon
File “D:\Programs\Python\Python311\Lib\asyncio\base_events.py”, line 519, in _check_closed
RuntimeError: Event loop is closed
Task was destroyed but it is pending!
task: <Task pending name=’Task-22′ coro=<WebSocketCommonProtocol.transfer_data() running at D:\Programs\Python\Python311\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-23′ coro=<WebSocketCommonProtocol.keepalive_ping() running at D:\Programs\Python\Python311\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-24′ coro=<WebSocketCommonProtocol.close_connection() running at D:\Programs\Python\Python311\Lib\site-packages\websockets\legacy\protocol.py:1301> wait_for=<Task pending name=’Task-22′ coro=<WebSocketCommonProtocol.transfer_data() running at D:\Programs\Python\Python311\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 0x000002E2528FA330>
Traceback (most recent call last):
File “D:\Programs\Python\Python311\Lib\site-packages\websockets\legacy\protocol.py”, line 1337, in close_connection
File “D:\Programs\Python\Python311\Lib\site-packages\websockets\legacy\protocol.py”, line 1355, in close_transport
File “D:\Programs\Python\Python311\Lib\site-packages\websockets\legacy\protocol.py”, line 1379, in wait_for_connection_lost
File “D:\Programs\Python\Python311\Lib\asyncio\timeouts.py”, line 141, in timeout
RuntimeError: no running event loop
Task was destroyed but it is pending!
task: <Task pending name=’Task-27′ coro=<WebSocketCommonProtocol.transfer_data() running at D:\Programs\Python\Python311\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-28′ coro=<WebSocketCommonProtocol.keepalive_ping() running at D:\Programs\Python\Python311\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-29′ coro=<WebSocketCommonProtocol.close_connection() running at D:\Programs\Python\Python311\Lib\site-packages\websockets\legacy\protocol.py:1301> wait_for=<Task pending name=’Task-27′ coro=<WebSocketCommonProtocol.transfer_data() running at D:\Programs\Python\Python311\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-39′ coro=<QuoteList._ensure_quotes() running at D:\Programs\Python\Python311\Lib\site-packages\tqsdk\objs_not_entity.py:69> 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-40′ coro=<ensure_quote_with_underlying() running at D:\Programs\Python\Python311\Lib\site-packages\tqsdk\objs_not_entity.py:37> wait_for=<Future pending cb=[Task.task_wakeup()]> cb=[TqBaseApi._on_task_done()]>
Task was destroyed but it is pending!
task: <Task cancelling name=’Task-41′ coro=<TqApi._fetch_msg() running at D:\Programs\Python\Python311\Lib\site-packages\tqsdk\api.py:3639> wait_for=<Future cancelled> cb=[TqBaseApi._on_task_done()]>
Exception ignored in: <coroutine object WebSocketCommonProtocol.close_connection at 0x000002E2529EDB10>
Traceback (most recent call last):
File “D:\Programs\Python\Python311\Lib\site-packages\websockets\legacy\protocol.py”, line 1337, in close_connection
File “D:\Programs\Python\Python311\Lib\site-packages\websockets\legacy\protocol.py”, line 1355, in close_transport
File “D:\Programs\Python\Python311\Lib\site-packages\websockets\legacy\protocol.py”, line 1379, in wait_for_connection_lost
File “D:\Programs\Python\Python311\Lib\asyncio\timeouts.py”, line 141, in timeout
RuntimeError: no running event loop
Exception ignored in: <coroutine object QuoteList._ensure_quotes at 0x000002E252A53010>
Traceback (most recent call last):
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\objs_not_entity.py”, line 69, in _ensure_quotes
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\objs_not_entity.py”, line 64, in _ensure_symbols
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\channel.py”, line 143, in __anext__
File “D:\Programs\Python\Python311\Lib\asyncio\queues.py”, line 160, in get
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\baseApi.py”, line 50, in _call_soon
File “D:\Programs\Python\Python311\Lib\asyncio\base_events.py”, line 761, in call_soon
File “D:\Programs\Python\Python311\Lib\asyncio\base_events.py”, line 519, in _check_closed
RuntimeError: Event loop is closed
Exception ignored in: <coroutine object ensure_quote_with_underlying at 0x000002E255A15700>
Traceback (most recent call last):
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\objs_not_entity.py”, line 37, in ensure_quote_with_underlying
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\objs_not_entity.py”, line 31, in ensure_quote
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\channel.py”, line 143, in __anext__
File “D:\Programs\Python\Python311\Lib\asyncio\queues.py”, line 160, in get
File “D:\Programs\Python\Python311\Lib\site-packages\tqsdk\baseApi.py”, line 50, in _call_soon
File “D:\Programs\Python\Python311\Lib\asyncio\base_events.py”, line 761, in call_soon
File “D:\Programs\Python\Python311\Lib\asyncio\base_events.py”, line 519, in _check_closed
RuntimeError: Event loop is closed

进程已结束,退出代码为 1

若是不用for, 以AP为举例, 直接 获取 AP 1,5,9 就没有问题。 使用for 循环就有问题(见上图中 获取 FG 1,5,9 合约, FG401 没问题, FG405就有问题 ),请问题如何解决

AP_05_info = api.get_quote("CZCE.AP401")
print(AP_05_info)

AP_05_info = api.get_quote("CZCE.AP405")
print(AP_05_info)

AP_05_info = api.get_quote("CZCE.AP410")
print(AP_05_info)
snowfeng2019 发表新评论 2023年12月16日

可能是参数问题

此问题已经解决