@@ -149,8 +149,9 @@ async def _send_snapshot(self):
149
149
"pre_open_interest" : None ,
150
150
"pre_settlement" : None ,
151
151
"pre_close" : None ,
152
- "margin" : quote .get ("margin" ),
153
- "commission" : quote .get ("commission" ),
152
+ "ins_class" : quote .get ("ins_class" , "" ),
153
+ "margin" : quote .get ("margin" ), # 用于内部实现模拟交易, 不作为api对外可用数据(即 Quote 类中无此字段)
154
+ "commission" : quote .get ("commission" ), # 用于内部实现模拟交易, 不作为api对外可用数据(即 Quote 类中无此字段)
154
155
"price_tick" : quote ["price_tick" ],
155
156
"price_decs" : quote ["price_decs" ],
156
157
"volume_multiple" : quote ["volume_multiple" ],
@@ -160,10 +161,11 @@ async def _send_snapshot(self):
160
161
"min_market_order_volume" : quote ["min_market_order_volume" ],
161
162
"underlying_symbol" : quote ["underlying_symbol" ],
162
163
"strike_price" : quote ["strike_price" ],
163
- "change" : None ,
164
- # todo: 回测添加合约文件字段,trading_time等
165
- "change_percent" : None ,
166
164
"expired" : None ,
165
+ "trading_time" : quote .get ("trading_time" ),
166
+ "expire_datetime" : quote .get ("expire_datetime" ),
167
+ "delivery_month" : quote .get ("delivery_month" ),
168
+ "delivery_year" : quote .get ("delivery_year" ),
167
169
}
168
170
self .diffs .append ({
169
171
"quotes" : quotes ,
@@ -192,7 +194,7 @@ async def _send_diff(self):
192
194
if quotes_diff and (quote_info ["min_duration" ] != 0 or min_serial [1 ] == 0 ):
193
195
quotes [min_serial [0 ]] = quotes_diff
194
196
await self ._fetch_serial (min_serial )
195
- if not self .serials :
197
+ if not self .serials : # 当无可发送数据时则抛出BacktestFinished例外,包括未订阅任何行情 或 所有已订阅行情的最后一笔行情获取完成
196
198
self .logger .warning ("回测结束" )
197
199
raise BacktestFinished () from None
198
200
for ins , diff in quotes .items ():
@@ -243,7 +245,7 @@ async def _gen_serial(self, ins, dur):
243
245
"chart_id" : TqApi ._generate_chart_id ("backtest" ),
244
246
"ins_list" : ins ,
245
247
"duration" : dur ,
246
- "view_width" : 8964 ,
248
+ "view_width" : 8964 , # 设为8964原因:可满足用户所有的订阅长度,并在backtest中将所有的 相同合约及周期 的K线用同一个serial存储
247
249
"focus_datetime" : int (self .current_dt ),
248
250
"focus_position" : 8964 ,
249
251
}
0 commit comments