已解决4.83K 浏览
0

5m close set to 0
2019-10-11 13:35:28,874 – INFO – 模拟交易委托单 455d913e85614b39b9131371329d0819: 交易日结束撤单
Traceback (most recent call last):
File “E:/cp/Futura002.py”, line 3017, in <module>
testback_5_pos()
File “E:/cp/Futura002.py”, line 2679, in testback_5_pos
api.wait_update()
File “E:\Python\Python37\lib\site-packages\tqsdk\api.py”, line 691, in wait_update
self._run_until_idle()
File “E:\Python\Python37\lib\site-packages\tqsdk\api.py”, line 1079, in _run_until_idle
self._run_once()
File “E:\Python\Python37\lib\site-packages\tqsdk\api.py”, line 1072, in _run_once
raise self.exceptions.pop(0)
File “E:\Python\Python37\lib\site-packages\tqsdk\lib.py”, line 125, in _target_pos_task
await gather(*[each.task for each in all_tasks])
File “E:\Python\Python37\lib\site-packages\tqsdk\lib.py”, line 197, in _run
raise Exception(“遇到错单: %s %s %s %d手 %f %s” % (self.symbol, self.direction, self.offset, self.volume, limit_price, order.last_msg))
Exception: 遇到错单: SHFE.ag1912 BUY CLOSETODAY 1手 3877.000000 交易日结束撤单
Task was destroyed but it is pending!
task: <Task pending coro=<TargetPosTask._target_pos_task() running at E:\Python\Python37\lib\site-packages\tqsdk\lib.py:118> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x0000020C19E26B28>()]> cb=[TqApi._on_task_done()]>
Task was destroyed but it is pending!
task: <Task pending coro=<TqApi._connect() running at E:\Python\Python37\lib\site-packages\tqsdk\api.py:1134> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x0000020C19E26168>()]> cb=[TqApi._on_task_done()]>
Task was destroyed but it is pending!
task: <Task pending coro=<TqBacktest._run() running at E:\Python\Python37\lib\site-packages\tqsdk\backtest.py:77> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x0000020C19E26078>()]> cb=[TqApi._on_task_done()]>
Task was destroyed but it is pending!
task: <Task pending coro=<TqApi._windows_patch() running at E:\Python\Python37\lib\site-packages\tqsdk\api.py:1106> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x0000020C182D4228>()]> cb=[TqApi._on_task_done()]>
Task was destroyed but it is pending!
task: <Task pending coro=<TqSim._run() running at E:\Python\Python37\lib\site-packages\tqsdk\sim.py:73> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x0000020C19E26E28>()]> cb=[TqApi._on_task_done()]>
Task was destroyed but it is pending!
task: <Task pending coro=<TqApi._notify_watcher() running at E:\Python\Python37\lib\site-packages\tqsdk\api.py:1113> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x0000020C152EC558>()]> cb=[TqApi._on_task_done()]>
Exception ignored in: <coroutine object TargetPosTask._target_pos_task at 0x0000020C1DA683C8>
Traceback (most recent call last):
File “E:\Python\Python37\lib\site-packages\tqsdk\lib.py”, line 118, in _target_pos_task
File “E:\Python\Python37\lib\site-packages\tqsdk\api.py”, line 1711, in __anext__
File “E:\Python\Python37\lib\asyncio\queues.py”, line 161, in get
File “E:\Python\Python37\lib\site-packages\tqsdk\api.py”, line 892, in _call_soon
File “E:\Python\Python37\lib\asyncio\base_events.py”, line 688, in call_soon
File “E:\Python\Python37\lib\asyncio\base_events.py”, line 480, in _check_closed
RuntimeError: Event loop is closed
Exception ignored in: <coroutine object TqApi._connect at 0x0000020C19BE8748>
Traceback (most recent call last):
File “E:\Python\Python37\lib\site-packages\tqsdk\api.py”, line 1139, in _connect
File “E:\Python\Python37\lib\site-packages\websockets\client.py”, line 527, in __aexit__
File “E:\Python\Python37\lib\site-packages\websockets\protocol.py”, line 649, in close
File “E:\Python\Python37\lib\asyncio\tasks.py”, line 400, in wait_for
File “E:\Python\Python37\lib\asyncio\base_events.py”, line 657, in call_later
File “E:\Python\Python37\lib\asyncio\base_events.py”, line 667, in call_at
File “E:\Python\Python37\lib\asyncio\base_events.py”, line 480, in _check_closed
RuntimeError: Event loop is closed
sys:1: RuntimeWarning: coroutine ‘WebSocketCommonProtocol.write_close_frame’ was never awaited
Task was destroyed but it is pending!
task: <Task pending coro=<TqApi._send_handler() running at E:\Python\Python37\lib\site-packages\tqsdk\api.py:1152> wait_for=<Future cancelled>>
Exception ignored in: <coroutine object TqBacktest._run at 0x0000020C19C1DAC8>
Traceback (most recent call last):
File “E:\Python\Python37\lib\site-packages\tqsdk\backtest.py”, line 98, in _run
File “E:\Python\Python37\lib\site-packages\tqsdk\api.py”, line 892, in _call_soon
File “E:\Python\Python37\lib\asyncio\base_events.py”, line 688, in call_soon
File “E:\Python\Python37\lib\asyncio\base_events.py”, line 480, in _check_closed
RuntimeError: Event loop is closed
Task was destroyed but it is pending!
task: <Task pending coro=<TqBacktest._md_handler() running at E:\Python\Python37\lib\site-packages\tqsdk\backtest.py:101> wait_for=<Future cancelled>>
2019-10-11 13:35:29,485 – WARNING – 模拟交易成交记录
Exception ignored in: <coroutine object TqSim._run at 0x0000020C19C1DEC8>
Traceback (most recent call last):
File “E:\Python\Python37\lib\site-packages\tqsdk\sim.py”, line 99, in _run
File “E:\Python\Python37\lib\site-packages\tqsdk\sim.py”, line 319, in _report
ImportError: sys.meta_path is None, Python is likely shutting down
Exception ignored in: <coroutine object TqApi._notify_watcher at 0x0000020C19C1DDC8>
Traceback (most recent call last):
File “E:\Python\Python37\lib\site-packages\tqsdk\api.py”, line 1113, in _notify_watcher
File “E:\Python\Python37\lib\site-packages\tqsdk\api.py”, line 1711, in __anext__
File “E:\Python\Python37\lib\asyncio\queues.py”, line 161, in get
File “E:\Python\Python37\lib\site-packages\tqsdk\api.py”, line 892, in _call_soon
File “E:\Python\Python37\lib\asyncio\base_events.py”, line 688, in call_soon
File “E:\Python\Python37\lib\asyncio\base_events.py”, line 480, in _check_closed
RuntimeError: Event loop is closed
Task was destroyed but it is pending!
task: <Task pending coro=<TqSim._md_handler() running at E:\Python\Python37\lib\site-packages\tqsdk\sim.py:103> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x0000020C19E26318>()]>>
Exception ignored in: <coroutine object TqSim._md_handler at 0x0000020C1D8A1948>
Traceback (most recent call last):
File “E:\Python\Python37\lib\site-packages\tqsdk\sim.py”, line 103, in _md_handler
File “E:\Python\Python37\lib\site-packages\tqsdk\api.py”, line 1711, in __anext__
File “E:\Python\Python37\lib\asyncio\queues.py”, line 161, in get
File “E:\Python\Python37\lib\site-packages\tqsdk\api.py”, line 892, in _call_soon
File “E:\Python\Python37\lib\asyncio\base_events.py”, line 688, in call_soon
File “E:\Python\Python37\lib\asyncio\base_events.py”, line 480, in _check_closed
RuntimeError: Event loop is closed
Task was destroyed but it is pending!
task: <Task pending coro=<WebSocketCommonProtocol.keepalive_ping() running at E:\Python\Python37\lib\site-packages\websockets\protocol.py:1084> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x0000020C19E26528>()]>>
Task was destroyed but it is pending!
task: <Task pending coro=<WebSocketCommonProtocol.transfer_data() running at E:\Python\Python37\lib\site-packages\websockets\protocol.py:795> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x0000020C19E26378>()]> cb=[<TaskWakeupMethWrapper object at 0x0000020C19E262E8>(), _wait.<locals>._on_completion() at E:\Python\Python37\lib\asyncio\tasks.py:440]>
Task was destroyed but it is pending!
task: <Task pending coro=<WebSocketCommonProtocol.close_connection() running at E:\Python\Python37\lib\site-packages\websockets\protocol.py:1129> wait_for=<Task pending coro=<WebSocketCommonProtocol.transfer_data() running at E:\Python\Python37\lib\site-packages\websockets\protocol.py:795> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x0000020C19E26378>()]> cb=[<TaskWakeupMethWrapper object at 0x0000020C19E262E8>(), _wait.<locals>._on_completion() at E:\Python\Python37\lib\asyncio\tasks.py:440]>>
Exception ignored in: <coroutine object WebSocketCommonProtocol.close_connection at 0x0000020C1D8A1F48>
Traceback (most recent call last):
File “E:\Python\Python37\lib\site-packages\websockets\protocol.py”, line 1171, in close_connection
File “E:\Python\Python37\lib\site-packages\websockets\protocol.py”, line 1195, in wait_for_connection_lost
File “E:\Python\Python37\lib\asyncio\tasks.py”, line 400, in wait_for
File “E:\Python\Python37\lib\asyncio\base_events.py”, line 657, in call_later
File “E:\Python\Python37\lib\asyncio\base_events.py”, line 667, in call_at
File “E:\Python\Python37\lib\asyncio\base_events.py”, line 480, in _check_closed
RuntimeError: Event loop is closed
Process finished with exit code

Lucas C 选择最佳答案 2019年10月11日

我使用的是挂价下单
target_pos = TargetPosTask(api=api, symbol=cod, price=’PASSIVE’)

0

请问你是使用的回测还是盘中模拟交易?可以稳定重现吗?

Lucas C 发表新评论 2019年10月11日

用的回测:
try:
tdata = api.get_tick_serial(symbol=cod,data_length=1)

kline_5m = api.get_kline_serial(symbol=cod, duration_seconds=300, data_length=DATA_LEN) # 获取5分钟的k数据

account = api.get_account()
position = api.get_position(cod)
target_pos = TargetPosTask(api=api, symbol=cod)

while True:
api.wait_update()
。。。
target_pos.set_target_volume(volumes)
。。。。

可以稳定复现。

这个应该就是正常的挂单未成交,等回测到当日收盘后,就自动撤单,以报错作为提示。你是希望它能按照正常的状况做出提示还是 如果未成交就保留到第二个交易日来继续平仓呢?

我希望是测试多日的,比如从8月1日到9月1日,但是测试到8月2日,就报错退出了。
我目的是想快结束时做对价挂单,平仓收盘。

这个是一个开仓单。我不知道是不是平仓单也有这样的问题。开仓单直接撤销不做就可以了。
平仓单,也可以撤销什么都不做,只要不报错,可继续回测即可。

您正在查看1个答案中的1个,单击此处查看所有答案。