3.10K 浏览
0

代码如下:

# -*- coding: utf-8 -*-
from datetime import date
from tqsdk import TqApi, tafunc, TqBacktest
api = TqApi(backtest=TqBacktest(start_dt=date(2020, 5, 13), end_dt=date(2020, 5, 13))) # ,_stock= True
_kline = api.get_kline_serial(‘DCE.jd2009’,900) # CZCE.SR009
while True:
    api.wait_update()
    _close = _kline.close._values
    _dt = tafunc.time_to_str(_kline.datetime._values[-1])[:19]
    _prd = _kline.duration._values[-1]
    _id = _kline.id._values[-1]
    print(_dt,_prd,_id,_close[-5:])
    # print(_kline)
输出信息如下:
2020-05-13 09:00:00 900 2220.0 [4113. 4113. 4116. 4113. 4100.]
2020-05-13 09:00:00 900 2220.0 [4113. 4113. 4116. 4113. 4117.]
2020-05-13 09:15:00 900 2221.0 [4113. 4116. 4113. 4117. 4117.]
2020-05-13 09:15:00 900 2221.0 [4113. 4116. 4113. 4117. 4125.]
2020-05-13 09:30:00 900 2222.0 [4116. 4113. 4117. 4125. 4125.]
2020-05-13 09:30:00 900 2222.0 [4116. 4113. 4117. 4125. 4113.]
2020-05-13 09:45:00 900 2223.0 [4113. 4117. 4125. 4113. 4113.]
2020-05-13 09:45:00 900 2223.0 [4113. 4117. 4125. 4113. 4119.]
2020-05-13 10:00:00 900 2224.0 [4117. 4125. 4113. 4119. 4119.]
2020-05-13 10:00:00 900 2224.0 [4117. 4125. 4113. 4119. 4107.]
2020-05-13 10:30:00 900 2225.0 [4125. 4113. 4119. 4107. 4107.]
2020-05-13 10:30:00 900 2225.0 [4125. 4113. 4119. 4107. 4065.]
2020-05-13 10:45:00 900 2226.0 [4113. 4119. 4107. 4065. 4065.]
2020-05-13 10:45:00 900 2226.0 [4113. 4119. 4107. 4065. 4043.]
2020-05-13 11:00:00 900 2227.0 [4119. 4107. 4065. 4043. 4043.]
2020-05-13 11:00:00 900 2227.0 [4119. 4107. 4065. 4043. 4061.]
2020-05-13 11:15:00 900 2228.0 [4107. 4065. 4043. 4061. 4061.]
2020-05-13 11:15:00 900 2228.0 [4107. 4065. 4043. 4061. 4052.]
2020-05-13 13:30:00 900 2229.0 [4065. 4043. 4061. 4052. 4055.]
2020-05-13 13:30:00 900 2229.0 [4065. 4043. 4061. 4052. 4041.]
2020-05-13 13:45:00 900 2230.0 [4043. 4061. 4052. 4041. 4041.]
2020-05-13 13:45:00 900 2230.0 [4043. 4061. 4052. 4041. 4037.]
2020-05-13 14:00:00 900 2231.0 [4061. 4052. 4041. 4037. 4037.]
2020-05-13 14:00:00 900 2231.0 [4061. 4052. 4041. 4037. 4039.]
2020-05-13 14:15:00 900 2232.0 [4052. 4041. 4037. 4039. 4039.]
2020-05-13 14:15:00 900 2232.0 [4052. 4041. 4037. 4039. 4036.]
2020-05-13 14:30:00 900 2233.0 [4041. 4037. 4039. 4036. 4036.]
2020-05-13 14:30:00 900 2233.0 [4041. 4037. 4039. 4036. 4028.]
2020-05-13 14:45:00 900 2234.0 [4037. 4039. 4036. 4028. 4028.]
2020-05-13 14:45:00 900 2234.0 [4037. 4039. 4036. 4028. 4032.]

ringo 已回答的问题 2020年5月15日
0

回测行情推进规则如下,会在开始和结束后各生刷新一次kline,https://doc.shinnytech.com/pysdk/latest/usage/backtest.html#backtest-rule

ringo 已回答的问题 2020年5月15日