3.21K 浏览
0

Position 是持仓对象,print(position),可以打印出一个字典,但是只打印其中的一个,或几个参数,比如:print(position.pos_long_his)就报错。请教一下大家这是为什么呀?

from tqsdk import TqApi, TqAccount

api = TqApi(TqAccount(“快期模拟”, “XXXXX”, “XXXXX”))
position = api.get_position(“SHFE.hc2010”)
print(position)
api.close()
终端显示结果:
2020-07-06 10:52:30,196 – INFO – 通知: 登录成功
2020-07-06 10:52:30,314 – INFO – 通知: 与 wss://openmd.shinnytech.com/t/md/front/mobile 的网络连接已建立
{‘SHFE.hc2010’: <tqsdk.objs.Position object at 0x000002069CACE4C0>, D({‘exchange_id’: ‘SHFE’, ‘instrument_id’: ‘hc2010’, ‘pos_long_his’: 170, ‘pos_long_today’: 0, ‘pos_short_his’: 0, ‘pos_short_today’: 0, ‘volume_long_today’: 0, ‘volume_long_his’: 170, ‘volume_long’: 170, ‘volume_long_frozen_today’: 0, ‘volume_long_frozen_his’: 0, ‘volume_long_frozen’: 0, ‘volume_short_today’: 0, ‘volume_short_his’: 0, ‘volume_short’: 0, ‘volume_short_frozen_today’: 0, ‘volume_short_frozen_his’: 0, ‘volume_short_frozen’: 0, ‘open_price_long’: 3332.0, ‘open_price_short’: 0.0, ‘open_cost_long’: 5664400.0, ‘open_cost_short’: 0.0, ‘position_price_long’: 3332.0, ‘position_price_short’: 0.0, ‘position_cost_long’: 5664400.0, ‘position_cost_short’: 0.0, ‘float_profit_long’: 448800.0, ‘float_profit_short’: 0.0, ‘float_profit’: 448800.0, ‘position_profit_long’: 448800.0, ‘position_profit_short’: 0.0, ‘position_profit’: 448800.0, ‘margin_long’: 470288.0, ‘margin_short’: 0.0, ‘margin’: 470288.0, ‘market_value_long’: 0.0, ‘market_value_short’: 0.0, ‘market_value’: 0.0, ‘user_id’: ‘chenqianli78@163.com’, ‘volume_long_yd’: 170, ‘volume_short_yd’: 0, ‘last_price’: 3596.0})}

报错情况:

from tqsdk import TqApi, TqAccount
api = TqApi(TqAccount(“快期模拟”, “XXXXX”, “XXXXXX”))
position = api.get_position(“SHFE.hc2010”)

print(position.pos_long_his)

api.close()
终端显示报错:
在使用天勤量化之前,默认您已经知晓并同意以下免责条款,如果不同意请立即停止使用:https://www.shinnytech.com/blog/disclaimer/
2020-07-06 12:21:08,768 – INFO – 通知: 与 wss://otg-sim.shinnytech.com/trade 的网络连接已建立
2020-07-06 12:21:08,770 – INFO – 通知: 登录成功
2020-07-06 12:21:08,891 – INFO – 通知: 与 wss://openmd.shinnytech.com/t/md/front/mobile 的网络连接已建立
Traceback (most recent call last):
File “c:\Users\Administrator\Desktop\get_account() – 获取账户资金情况.py”, line 12, in <module>
print(position.pos_long_his)
AttributeError: ‘Entity’ object has no attribute ‘pos_long_his’
Task was destroyed but it is pending!
task: <Task pending name=’Task-1′ coro=<TqApi._windows_patch() running at C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\tqsdk\api.py:1559> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x0000018ECE703580>()]> cb=[TqApi._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\AppData\Local\Programs\Python\Python38\lib\site-packages\tqsdk\api.py:1567> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x0000018ED694B6D0>()]> cb=[TqApi._on_task_done()]>
Exception ignored in: <coroutine object TqApi._notify_watcher at 0x0000018ECEA64E40>
Traceback (most recent call last):
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\tqsdk\api.py”, line 1567, in _notify_watcher
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\tqsdk\api.py”, line 2326, in __anext__
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\asyncio\queues.py”, line 165, in get
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\tqsdk\api.py”, line 1157, in _call_soon
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py”, line 715, in call_soon
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py”, line 508, in _check_closed
RuntimeError: Event loop is closed
Task was destroyed but it is pending!
task: <Task pending name=’Task-3′ coro=<TqApi._connect() running at C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\tqsdk\api.py:1629> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x0000018ED694B5B0>()]> cb=[TqApi._on_task_done()]>
Task was destroyed but it is pending!
task: <Task pending name=’Task-4′ coro=<TqApi._connect() running at C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\tqsdk\api.py:1629> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x0000018ED6924CA0>()]> cb=[TqApi._on_task_done()]>
Task was destroyed but it is pending!
task: <Task pending name=’Task-5′ coro=<TqAccount._run() running at C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\tqsdk\api.py:2205> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x0000018ECE705040>()]> cb=[TqApi._on_task_done()]>
Task was destroyed but it is pending!
task: <Task pending name=’Task-6′ coro=<TqWebHelper._run() running at C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\tqsdk\tqwebhelper.py:60> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x0000018ED694BA90>()]> cb=[TqApi._on_task_done()]>
Exception ignored in: <coroutine object TqApi._connect at 0x0000018ECEA64840>
Traceback (most recent call last):
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\tqsdk\api.py”, line 1729, in _connect
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\websockets\client.py”, line 525, in __aexit__
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\websockets\protocol.py”, line 676, in close
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\asyncio\tasks.py”, line 448, in wait_for
RuntimeError: no running event loop
sys:1: RuntimeWarning: coroutine ‘WebSocketCommonProtocol.write_close_frame’ was never awaited
Task was destroyed but it is pending!
task: <Task pending name=’Task-24′ coro=<TqApi._send_handler() running at C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\tqsdk\api.py:1766> wait_for=<Future cancelled>>
Exception ignored in: <coroutine object TqApi._connect at 0x0000018EC9D4B440>
Traceback (most recent call last):
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\tqsdk\api.py”, line 1729, in _connect
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\websockets\client.py”, line 525, in __aexit__
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\websockets\protocol.py”, line 676, in close
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\asyncio\tasks.py”, line 448, in wait_for
RuntimeError: no running event loop
Task was destroyed but it is pending!
task: <Task pending name=’Task-15′ coro=<TqApi._send_handler() running at C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\tqsdk\api.py:1766> wait_for=<Future cancelled>>
Exception ignored in: <coroutine object TqAccount._run at 0x0000018EC9D4B540>
Traceback (most recent call last):
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\tqsdk\api.py”, line 2211, in _run
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\tqsdk\api.py”, line 1157, in _call_soon
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py”, line 715, in call_soon
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py”, line 508, in _check_closed
RuntimeError: Event loop is closed
Task was destroyed but it is pending!
task: <Task pending name=’Task-7′ coro=<TqAccount._md_handler() running at C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\tqsdk\api.py:2215> wait_for=<Future cancelled>>
Exception ignored in: <coroutine object TqWebHelper._run at 0x0000018ECEAA9440>
Traceback (most recent call last):
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\tqsdk\tqwebhelper.py”, line 65, in _run
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\tqsdk\api.py”, line 1157, in _call_soon
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py”, line 715, in call_soon
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py”, line 508, in _check_closed
RuntimeError: Event loop is closed
Task was destroyed but it is pending!
task: <Task pending name=’Task-9′ coro=<TqWebHelper._data_handler_without_web() running at C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\tqsdk\tqwebhelper.py:134> wait_for=<Future cancelled>>
Task was destroyed but it is pending!
task: <Task pending name=’Task-8′ coro=<TqAccount._td_handler() running at C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\tqsdk\api.py:2222> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x0000018ED694B640>()]>>
Exception ignored in: <coroutine object TqAccount._td_handler at 0x0000018ED42D7140>
Traceback (most recent call last):
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\tqsdk\api.py”, line 2222, in _td_handler
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\tqsdk\api.py”, line 2326, in __anext__
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\asyncio\queues.py”, line 165, in get
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\tqsdk\api.py”, line 1157, in _call_soon
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py”, line 715, in call_soon
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\asyncio\base_events.py”, line 508, in _check_closed
RuntimeError: Event loop is closed
Task was destroyed but it is pending!
task: <Task pending name=’Task-12′ coro=<WebSocketCommonProtocol.transfer_data() running at C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\websockets\protocol.py:827> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x0000018ECE716520>()]> cb=[<TaskWakeupMethWrapper object at 0x0000018ED69247F0>()]>
Task was destroyed but it is pending!
task: <Task pending name=’Task-13′ coro=<WebSocketCommonProtocol.keepalive_ping() running at C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\websockets\protocol.py:1119> wait_for=<Future pending cb=[<TaskWakeupMethWrapper
object at 0x0000018ED69247C0>()]>>
Task was destroyed but it is pending!
task: <Task pending name=’Task-14′ coro=<WebSocketCommonProtocol.close_connection() running at C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\websockets\protocol.py:1169> wait_for=<Task pending name=’Task-12′ coro=<WebSocketCommonProtocol.transfer_data() running at C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\websockets\protocol.py:827> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x0000018ECE716520>()]> cb=[<TaskWakeupMethWrapper object at 0x0000018ED69247F0>()]>>
Exception ignored in: <coroutine object WebSocketCommonProtocol.close_connection at 0x0000018ED42D7CC0>
Traceback (most recent call last):
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\websockets\protocol.py”, line 1206, in
close_connection
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\websockets\protocol.py”, line 1226, in
wait_for_connection_lost
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\asyncio\tasks.py”, line 448, in wait_for
RuntimeError: no running event loop
Task was destroyed but it is pending!
task: <Task pending name=’Task-21′ coro=<WebSocketCommonProtocol.transfer_data() running at C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\websockets\protocol.py:827> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x0000018ED694B820>()]> cb=[<TaskWakeupMethWrapper object at 0x0000018ED694B8E0>()]>
Task was destroyed but it is pending!
task: <Task pending name=’Task-22′ coro=<WebSocketCommonProtocol.keepalive_ping() running at C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\websockets\protocol.py:1119> wait_for=<Future pending cb=[<TaskWakeupMethWrapper
object at 0x0000018ED694B8B0>()]>>
Task was destroyed but it is pending!
task: <Task pending name=’Task-23′ coro=<WebSocketCommonProtocol.close_connection() running at C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\websockets\protocol.py:1169> wait_for=<Task pending name=’Task-21′ coro=<WebSocketCommonProtocol.transfer_data() running at C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\websockets\protocol.py:827> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x0000018ED694B820>()]> cb=[<TaskWakeupMethWrapper object at 0x0000018ED694B8E0>()]>>
Exception ignored in: <coroutine object WebSocketCommonProtocol.close_connection at 0x0000018ED693C640>
Traceback (most recent call last):
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\websockets\protocol.py”, line 1206, in
close_connection
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\websockets\protocol.py”, line 1226, in
wait_for_connection_lost
File “C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\asyncio\tasks.py”, line 448, in wait_for
RuntimeError: no running event loop

ringo 已回答的问题 2020年7月6日
0

天勤终端已经暂停维护,建议转到tqsdk使用上来

pos_long_his 是0.9.9以后版本才有的字段https://doc.shinnytech.com/pysdk/latest/version.html

ringo 已回答的问题 2020年7月6日
您正在查看1个答案中的1个,单击此处查看所有答案。