xiaohe wrote:
下面self.bar.low_price = min(self.bar.low_price, tick.low_price)会更新的
第1个tick:时间=2025-09-01 09:30:00.5, last_price=4518.8, low_price=4516.8
第2个tick:时间=2025-09-01 09:30:01, last_price=4519.0, low_price=4516.8
第3个tick:时间=2025-09-01 09:30:01.5, last_price=4518.4, low_price=4516.8
...
第120个tick: 时间=2025-09-01 09:30:59.5, last_price=4519.0, low_price=4516.8
当收到第1个tick后,self.bar.low_price=4518.8,
当收到第3个tick后,self.bar.low_price=4518.4,
因为只有 if self.last_tick and tick.low_price < self.last_tick.low_price:
才能 self.bar.low_price = min(self.bar.low_price, tick.low_price),
但这个条件是没法实现的,因为后续的 tick.low_price = self.last_tick.low_price,没能出现比前一个更低价的tick.low_price,所以第一个tick的 low_price没法采集到了。我在想是否可以改成这样:
if new_minute:
self.bar = BarData(
symbol=tick.symbol,
exchange=tick.exchange,
interval=Interval.MINUTE,
datetime=tick.datetime,
gateway_name=tick.gateway_name,
open_price=tick.last_price,
high_price=tick.last_price,
low_price=tick.last_price,
close_price=tick.last_price,
open_interest=tick.open_interest
)
if (self.last_tick and tick.high_price > self.last_tick.high_price) or (self.last_tickNone) :
self.bar.high_price = max(self.bar.high_price, tick.high_price)
if (self.last_tick and tick.low_price < self.last_tick.low_price) or (self.last_tickNone) :
self.bar.low_price = min(self.bar.low_price, tick.low_price)
elif self.bar: