适用于收盘时间为15:00的国内品种,只负责合成单日K线。
更改了BarGenerator的代码。主要更改了3部分:
1、在init新增日K线的名称daily_bar
self.daily_bar: BarData = None
2、在update__bar函数增加DAILY的选项
3、新增update_bar_daily_window函数
代码参考update_bar_minute_window函数,把其中的window_bar改成 daily_bar即可。
结束时间的判定为14:59分
def update_bar_daily_window(self, bar: BarData) -> None:
""""""
# If not inited, create window bar object
if not self.daily_bar:
dt = bar.datetime.replace(minute=0, second=0, microsecond=0)
self.daily_bar = BarData(
symbol=bar.symbol,
exchange=bar.exchange,
datetime=dt,
gateway_name=bar.gateway_name,
open_price=bar.open_price,
high_price=bar.high_price,
low_price=bar.low_price
)
# Otherwise, update high/low price into window bar
else:
self.daily_bar.high_price = max(
self.daily_bar.high_price,
bar.high_price
)
self.daily_bar.low_price = min(
self.daily_bar.low_price,
bar.low_price
)
# Update close price/volume/turnover into window bar
self.daily_bar.close_price = bar.close_price
self.daily_bar.volume += bar.volume
self.daily_bar.turnover += bar.turnover
self.daily_bar.open_interest = bar.open_interest
# Check if daily bar completed
if self.last_bar and str(bar.datetime)[-14:-6] == '14:59:00':
self.on_daily_bar(self.daily_bar)
self.daily_bar = None
新手小白一枚,不知道这样的更改是否存在问题?请各位大佬指点~