def update_bar(self, xmin, xmin_bar: BarData, bar: BarData): """ Update 1 minute bar into generator """ if not xmin_bar: xmin_bar = BarData(symbol=bar.symbol, exchange=bar.exchange, datetime=bar.datetime, gateway_name=bar.gateway_name, open_price=bar.open_price, high_price=bar.high_price, low_price=bar.low_price) else: xmin_bar.high_price = max(xmin_bar.high_price, bar.high_price) xmin_bar.low_price = min(xmin_bar.low_price, bar.low_price) xmin_bar.close_price = bar.close_price xmin_bar.volume += int(bar.volume) if not (bar.datetime.minute + 1) % xmin: xmin_bar.datetime = xmin_bar.datetime.replace(second=0, microsecond=0) xmin_bar.interval = xmin event = Event(type=EVENT_BAR, data=xmin_bar) self.rpo.put(event) xmin_bar = None
def update_bar(self, xmin, bar: BarData): """ Update 1 minute bar into generator """ xmin_bar = getattr(self, f"min_{xmin}_bar", None) if not xmin_bar: xmin_bar = BarData(symbol=bar.symbol, exchange=bar.exchange, datetime=bar.datetime, gateway_name=bar.gateway_name, open_price=bar.open_price, high_price=bar.high_price, low_price=bar.low_price) setattr(self, f"min_{xmin}_bar", xmin_bar) else: xmin_bar.high_price = max(xmin_bar.high_price, bar.high_price) xmin_bar.low_price = min(xmin_bar.low_price, bar.low_price) xmin_bar.close_price = bar.close_price xmin_bar.volume += int(bar.volume) if not (bar.datetime.minute + 1) % xmin: xmin_bar.datetime = xmin_bar.datetime.replace(second=0, microsecond=0) xmin_bar.interval = xmin event = Event(type=EVENT_BAR, data=xmin_bar) common_signals.bar_signal.send(event) setattr(self, f"min_{xmin}_bar", None)
def on_bar(self, bar: BarData) -> None: bar.datetime = str(bar) data = { "type": "bar", "data": bar._to_dict() } self.io.emit('bar', data)