I would like to dynamically add/remove securities after universe selection in an Alpha Class while also having a Consolidator for the Bar data. Therefore I cannot use self.warmup(…) because the warmup must happen every time when adding a security. I got it to work but only without the Consolidation layer.

With the consolidator I would have to manually update the Consolidator during warmup phase.

Is it correct to use Consolidator.Update(slice.Bars[s]) for this?

       self.symbolData = {}
    
    def OnSecuritiesChanged(self, algorithm, changes):
        
        for added in changes.AddedSecurities:
            s = added.Symbol
            
            # add data object
            if not s in self.symbolData.keys():
                self.symbolData[s] = SymbolData(algorithm, added, self.resolution,self.barperiod, self.lookback)
            
            # add consolidator OHCLV
            if self.symbolData[s].Consolidator is not None: raise Exception("Consolidator is already existing or was not remvoved")
            self.symbolData[s].Consolidator = TradeBarConsolidator(self.symbolData[s].timespan)
            self.symbolData[s].Consolidator.DataConsolidated += self.OnDataConsolidated
            algorithm.SubscriptionManager.AddConsolidator(s, self.symbolData[s].Consolidator)
            
        # history warmup
        hist = algorithm.History(self.lookback)
        for added in changes.AddedSecurities:
            s = added.Symbol
            for slice in hist:
                self.Debug(f"time={algorithm.Time},symbol={s},warmup")
                self.symbolData[s].Consolidator.Update(slice.Bars[s])
    
        for removed in changes.RemovedSecurities:
            s = removed.Symbol
            
            # remove data object
            symbolData = self.symbolData.pop(s, None)
            
            # remove consolidator
            if symbolData is not None: 
                algorithm.SubscriptionManager.RemoveConsolidator(s, symbolData.Consolidator)
                
    def OnDataConsolidated(self, sender, bar):
        # bar.Time, bar.Close, bar.Open ...
        s=bar.Symbol.Value
        self.Debug(f"time={bar.Time},symbol={s},OnDataConsolidated")
        self.symbolData[s].bar = bar
        self.symbolData[s].time = bar.Time
        self.symbolData[s].MACD.Update(bar.Time, bar.Close)
        self.symbolData[s].window_close.Add(bar.Close)