823 浏览
0

伪代码:

tqacc = TqAccount(“Z中信建投”, account, password)
api = TqApi(account=tqacc, auth=TqAuth(user_name, password))
account = tqacc.get_account()
print(account.float_profit)

以上代码运行后无法正确获取结果,报错如下:

在使用天勤量化之前,默认您已经知晓并同意以下免责条款,如果不同意请立即停止使用:https://www.shinnytech.com/blog/disclaimer/
天勤量化发布了量化智能机器人助手,尝试回答用户任何关于天勤的问题,提供策略示例,函数讲解等功能,访问官网使用:https://www.shinnytech.com/tianqin/
Traceback (most recent call last):
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\websockets\legacy\client.py”, line 647, in __await_impl_timeout__
return await self.__await_impl__()
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\websockets\legacy\client.py”, line 651, in __await_impl__
_transport, _protocol = await self._create_connection()
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\asyncio\base_events.py”, line 986, in create_connection
infos = await self._ensure_resolved(
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\asyncio\base_events.py”, line 1365, in _ensure_resolved
return await loop.getaddrinfo(host, port, family=family, type=type,
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\asyncio\base_events.py”, line 825, in getaddrinfo
return await self.run_in_executor(
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\tqsdk\api.py”, line 298, in __init__
if not self.wait_update(deadline=deadline): # 等待连接成功并收取截面数据
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\tqsdk\api.py”, line 1883, in wait_update
self._run_until_idle(async_run=False)
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\tqsdk\baseApi.py”, line 67, in _run_until_idle
self._run_once()
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\tqsdk\baseApi.py”, line 57, in _run_once
raise self._exceptions.pop(0)
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\tqsdk\connect.py”, line 157, in _run
async with websockets.connect(url, **self._keywords) as client:
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\websockets\legacy\client.py”, line 629, in __aenter__
return await self
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\websockets\legacy\client.py”, line 647, in __await_impl_timeout__
return await self.__await_impl__()
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\websockets\legacy\async_timeout.py”, line 169, in __aexit__
self._do_exit(exc_type)
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\websockets\legacy\async_timeout.py”, line 252, in _do_exit
raise asyncio.TimeoutError
asyncio.exceptions.TimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “E:\code\py\qihuo\tq_test.py”, line 10, in <module>
api = TqApi(account=tqacc, auth=TqAuth(username, password))
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\tqsdk\api.py”, line 302, in __init__
self.close()
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\tqsdk\api.py”, line 358, in close
super(TqApi, self)._close()
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\tqsdk\baseApi.py”, line 126, in _close
self._run_once()
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\tqsdk\baseApi.py”, line 57, in _run_once
raise self._exceptions.pop(0)
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\tqsdk\connect.py”, line 157, in _run
async with websockets.connect(url, **self._keywords) as client:
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\websockets\legacy\client.py”, line 629, in __aenter__
return await self
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\websockets\legacy\client.py”, line 647, in __await_impl_timeout__
return await self.__await_impl__()
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\websockets\legacy\async_timeout.py”, line 169, in __aexit__
self._do_exit(exc_type)
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\websockets\legacy\async_timeout.py”, line 252, in _do_exit
raise asyncio.TimeoutError
asyncio.exceptions.TimeoutError
Task was destroyed but it is pending!
task: <Task pending name=’Task-18′ coro=<TqModule._up_handler() running at C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\tqsdk\baseModule.py:51> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x00000207DE434190>()]>>
Task was destroyed but it is pending!
task: <Task pending name=’Task-16′ coro=<TqReconnect._send_handler() running at C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\tqsdk\connect.py:328> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x00000207DE4340D0>()]>>
Task was destroyed but it is pending!
task: <Task pending name=’Task-6′ coro=<TqTradingStatus._run() running at C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\tqsdk\trading_status.py:26> wait_for=<Future cancelled> cb=[TqBaseApi._on_task_done()]>
Task was destroyed but it is pending!
task: <Task pending name=’Task-4′ coro=<TqReconnect._run() running at C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\tqsdk\connect.py:274> wait_for=<Future cancelled> cb=[TqBaseApi._on_task_done()]>
Task was destroyed but it is pending!
task: <Task pending name=’Task-1′ coro=<TqBaseApi._windows_patch() running at C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\tqsdk\baseApi.py:119> wait_for=<Future cancelled> cb=[TqBaseApi._on_task_done()]>
Task was destroyed but it is pending!
task: <Task pending name=’Task-10′ coro=<TqWebHelper._run() running at C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\tqsdk\tqwebhelper.py:80> wait_for=<Future cancelled> cb=[TqBaseApi._on_task_done()]>
Task was destroyed but it is pending!
task: <Task pending name=’Task-11′ coro=<DataExtension._run() running at C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\tqsdk\data_extension.py:85> wait_for=<Future cancelled> cb=[TqBaseApi._on_task_done()]>
Task was destroyed but it is pending!
task: <Task pending name=’Task-5′ coro=<TqSymbols._run() running at C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\tqsdk\symbols.py:29> wait_for=<Future cancelled> cb=[TqBaseApi._on_task_done()]>
Task was destroyed but it is pending!
task: <Task pending name=’Task-8′ coro=<TqReconnect._run() running at C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\tqsdk\connect.py:274> wait_for=<Future cancelled> cb=[TqBaseApi._on_task_done()]>
Task was destroyed but it is pending!
task: <Task pending name=’Task-9′ coro=<BaseOtg._run() running at C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\tqsdk\tradeable\otg\base_otg.py:109> wait_for=<Future cancelled> 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\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\tqsdk\api.py:3682> wait_for=<Future cancelled> cb=[TqBaseApi._on_task_done()]>
Exception ignored in: <coroutine object TqModule._up_handler at 0x00000207DE423DC0>
Traceback (most recent call last):
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\tqsdk\baseModule.py”, line 51, in _up_handler
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\tqsdk\channel.py”, line 143, in __anext__
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\asyncio\queues.py”, line 165, in get
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\tqsdk\baseApi.py”, line 50, in _call_soon
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\asyncio\base_events.py”, line 719, in call_soon
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\asyncio\base_events.py”, line 508, in _check_closed
RuntimeError: Event loop is closed
Exception ignored in: <coroutine object TqReconnect._send_handler at 0x00000207DE4238C0>
Traceback (most recent call last):
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\tqsdk\connect.py”, line 328, in _send_handler
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\tqsdk\channel.py”, line 143, in __anext__
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\asyncio\queues.py”, line 165, in get
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\tqsdk\baseApi.py”, line 50, in _call_soon
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\asyncio\base_events.py”, line 719, in call_soon
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\asyncio\base_events.py”, line 508, in _check_closed
RuntimeError: Event loop is closed
Exception ignored in: <coroutine object TqTradingStatus._run at 0x00000207ABBE0CC0>
Traceback (most recent call last):
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\tqsdk\trading_status.py”, line 26, in _run
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\tqsdk\baseModule.py”, line 47, in _run
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\tqsdk\baseModule.py”, line 47, in <listcomp>
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\site-packages\tqsdk\baseApi.py”, line 50, in _call_soon
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\asyncio\base_events.py”, line 719, in call_soon
File “C:\Users\kevin\AppData\Local\anaconda3\envs\PY38\lib\asyncio\base_events.py”, line 508, in _check_closed

# 获取当前浮动盈亏 from tqsdk import TqApi, TqAuth, TqAccount user_name = “” symbol = “SHFE.au2404” my_email = ‘1xxx@qq.com’ account = ‘xxx’ password = ‘xx’ tqacc = TqAccount(“Z中信建投”, account, password) api = TqApi(account=tqacc, auth=TqAuth(user_name, password)) account = tqacc.get_account() print(account.float_profit)


Task was destroyed but it is pending!

李思恒 已回答的问题 2024年9月20日
0

结束了代码后记得调用api.close()

李思恒 已回答的问题 2024年9月20日