更新1.7.0后回测总是报错。提示“不在可交易时间段内”,然后整个程序异常退出!
有很多品种报错,如:jd2005,原 klines = api.get_kline_serial(SYMBOL, 60 * 30 )报错,
改为:klines = api.get_kline_serial(SYMBOL, 60 * 29 )jd2005能过去,不报错。
cu2005 klines = api.get_kline_serial(SYMBOL, 60 * 29 ) 报错,错误信息如下:
INFO – 模拟交易下单 ccaf2792b3d8f6bd936e9cb951d19506: 时间:2019-12-13 10:29:59.999999,合约:SHFE.cu2005,开平:OPEN,方向:BUY,手数:1,价格:49540.0
INFO – 模拟交易委托单 ccaf2792b3d8f6bd936e9cb951d19506: 下单失败, 不在可交易时间段内
Traceback (most recent call last):
File “D:\cu2009.py”, line 105, in <module>
api.wait_update()
File “D:\Python37\lib\site-packages\tqsdk\api.py”, line 878, in wait_update
self._run_until_idle()
File “D:\Python37\lib\site-packages\tqsdk\api.py”, line 1532, in _run_until_idle
self._run_once()
File “D:\Python37\lib\site-packages\tqsdk\api.py”, line 1525, in _run_once
raise self._exceptions.pop(0)
File “D:\Python37\lib\site-packages\tqsdk\lib.py”, line 187, in _target_pos_task
await gather(*[each._task for each in all_tasks])
File “D:\Python37\lib\site-packages\tqsdk\lib.py”, line 268, in _run
self._symbol, self._direction, self._offset, self._volume, limit_price, order.last_msg))
Exception: 遇到错单: SHFE.cu2005 BUY OPEN 1手 49540.000000 下单失败, 不在可交易时间段内
Task was destroyed but it is pending!
你有订阅其他合约吗
很奇怪的问题,反复调试发现报错与否可能随机出现。
下面代码限定条件, 运行后一定报错,你们看看什么原因,谢谢!
from datetime import date
from tqsdk import TqApi, TqAccount
from tqsdk import TqBacktest, TargetPosTask, TqReplay
from tqsdk.ta import KDJ
SYMBOL = “SHFE.cu2005”
api = TqApi(backtest=TqBacktest(start_dt=date(2019, 12, 13), end_dt=date(2019, 12, 14)))
quote = api.get_quote(SYMBOL)
klines = api.get_kline_serial(SYMBOL, 60 * 29) #取消此订阅就不会报错了
klines1 = api.get_kline_serial(SYMBOL, 60 * 59)
position = api.get_position(SYMBOL)
target_pos = TargetPosTask(api, SYMBOL)
while True:
api.wait_update()
if api.is_changing(klines1.iloc[-1], “datetime”): # 60min
k1 = round(list(KDJ(klines1, 18, 3, 3)[“k”])[-1],3)
if k1 == 64.705:
target_pos.set_target_volume(1)
INFO – 模拟交易下单 a54cfcd58404fdadd8f95f30042bec69: 时间:2019-12-13 10:29:59.999999,合约:SHFE.cu2005,开平:OPEN,方向:BUY,手数:1,价格:49540.0
INFO – 模拟交易委托单 a54cfcd58404fdadd8f95f30042bec69: 下单失败, 不在可交易时间段内
Traceback (most recent call last):
……
好的,这个问题我们已经知道了,会尽快修好的
这个问题预计什么版本能解决?谢谢
回测的开始时间是填的什么呢?