Consolidator Types

Time Period Consolidators

Introduction

Time period consolidators aggregate data based on a period of time like a number of seconds, minutes, or days. If a time period consolidator aggregates data over multiple days, the multi-day aggregation cycle starts and repeats based on the time stamp of the first data point you use to update the consolidator.

Consolidate Trade Bars

TradeBar consolidators aggregate TradeBar objects into TradeBar objects of the same size or larger. Follow these steps to create and manage a TradeBar consolidator based on a period of time:

  1. Create the consolidator.
  2. To set the time period for the consolidator, you can use either a timedeltaTimeSpan or Resolution object. The consolidator time period must be greater than or equal to the resolution of the security subscription. For instance, you can aggregate minute bars into 10-minute bars, but you can't aggregate hour bars into 10-minute bars.

    • timedelta Periods
    • TimeSpan Periods
    • _consolidator = new TradeBarConsolidator(TimeSpan.FromDays(1));
      // Aliases:
      // _consolidator = CreateConsolidator(TimeSpan.FromDays(1), typeof(TradeBar));
      // _consolidator = ResolveConsolidator(_symbol, TimeSpan.FromDays(1));
      self.consolidator = TradeBarConsolidator(timedelta(days=1))
      # Aliases:
      # self.consolidator = self.CreateConsolidator(timedelta(days=1), TradeBar)
      # self.consolidator = self.ResolveConsolidator(self.symbol, timedelta(days=1))

      The time period is relative to the data time zone, not the algorithm time zone. If you consolidate Crypto data into daily bars, the event handler receives the consolidated bars at midnight 12:00 AM Coordinated Universal Time (UTC), regardless of the algorithm time zone.

    • Resolution Periods
    • The Resolution enumeration has the following members:

      _consolidator = TradeBarConsolidator.FromResolution(Resolution.Daily);
      // Alias:
      // _consolidator = ResolveConsolidator(_symbol, Resolution.Daily);
      self.consolidator = TradeBarConsolidator.FromResolution(Resolution.Daily)
      # Alias:
      # self.consolidator = self.ResolveConsolidator(self.symbol, Resolution.Daily)

    If the security subscription in your algorithm provides TradeBar and QuoteBar data, ResolveConsolidator returns a TradeBarConsolidator.

    If you consolidate on an hourly basis, the consolidator ends at the top of the hour, not every hour after the market open. For US Equities, that's 10 AM Eastern Time (ET), not 10:30 AM ET.

  3. Add an event handler to the consolidator.
  4. _consolidator.DataConsolidated += ConsolidationHandler;
    self.consolidator.DataConsolidated += self.consolidation_handler

    LEAN passes consolidated bars to the consolidator event handler in your algorithm. The most common error when creating consolidators is to put parenthesis () at the end of your method name when setting the event handler of the consolidator. If you use parenthesis, the method executes and the result is passed as the event handler instead of the method itself. Remember to pass the name of your method to the event system. Specifically, it should be ConsolidationHandlerself.consolidation_handler, not ConsolidationHandler()self.consolidation_handler().

  5. Define the consolidation handler.
  6. void ConsolidationHandler(object sender, TradeBar consolidatedBar)
    {
    
    }
    def consolidation_handler(self, sender: object, consolidated_bar: TradeBar) -> None:
        pass

    The consolidation event handler receives bars when the consolidated bar closes based on the data time zone. If you subscribe to minute resolution data for Bitcoin and create an hourly consolidator, you receive consolidated bars at the top of each hour. However, if you subscribe to minute resolution data for the regular trading hours of US Equities and create a daily consolidator, you receive consolidated bars at 9:31 AM Eastern Time (ET). The consolidated bar for US Equities doesn't close at 4:00 PM ET because the day isn't over. The consolidated bar for US Equities also doesn't close at midnight because your algorithm doesn't receive minute resolution data after 4:00 PM ET until 9:31 AM ET.

  7. Update the consolidator.
  8. You can automatically or manually update the consolidator.

    • Automatic Updates
    • To automatically update a consolidator with data from the security subscription, call the AddConsolidator method of the Subscription Manager.

      self.SubscriptionManager.AddConsolidator(self.symbol, self.consolidator)
      SubscriptionManager.AddConsolidator(_symbol, _consolidator);
    • Manual Updates
    • Manual updates let you control when the consolidator updates and what data you use to update it. If you need to warm up a consolidator with data outside of the warm-up period, you can manually update the consolidator. To manually update a consolidator, call its Update method with a TradeBar object. You can update the consolidator with data from the Slice object in the OnData method or with data from a history request.

      # Example 1: Update the consolidator with data from the Slice object
      def OnData(self, slice: Slice) -> None:
          trade_bar = slice.Bars[self.symbol]
          self.consolidator.Update(trade_bar)
      
      # Example 2: Update the consolidator with data from a history request
      history = self.History[TradeBar](self.symbol, 30, Resolution.Minute)
      for trade_bar in history:
          self.consolidator.Update(trade_bar)
      // Example 1: Update the consolidator with data from the Slice object
      public override void OnData(Slice slice)
      {
          var tradeBar = slice.Bars[_symbol];
          _consolidator.Update(tradeBar);
      }
      
      // Example 2: Update the consolidator with data from a history request
      var history = History<TradeBar>(_symbol, 30, Resolution.Minute);
      foreach (var tradeBar in history)
      {
          _consolidator.Update(tradeBar);
      }
  9. If you create consolidators for securities in a dynamic universe and register them for automatic updates, remove the consolidator when the security leaves the universe.
  10. SubscriptionManager.RemoveConsolidator(_symbol, _consolidator);
    self.SubscriptionManager.RemoveConsolidator(self.symbol, self.consolidator)

    If you have a dynamic universe and don't remove consolidators, they compound internally, causing your algorithm to slow down and eventually die once it runs out of RAM. For an example of removing consolidators from universe subscriptions, see the GasAndCrudeOilEnergyCorrelationAlphaGasAndCrudeOilEnergyCorrelationAlpha in the LEAN GitHub repository.

You can also use the Consolidate helper method to create period consolidators and register them for automatic updates. With just one line of code, you can create data in any time period based on a timedeltaTimeSpan or Resolution object:

  • TimeSpan Periods
  • timedelta Periods
  • _consolidator = Consolidate(_symbol, TimeSpan.FromDays(1), ConsolidationHandler);
    self.consolidator = self.Consolidate(self.symbol, timedelta(days=1), self.consolidation_handler)
  • Resolution Periods
  • _consolidator = Consolidate(_symbol, Resolution.Daily, ConsolidationHandler);
    self.consolidator = self.Consolidate(self.symbol, Resolution.Daily, self.consolidation_handler)

If you use the Consolidate helper method, the consolidation handler doesn't receive an object argument.

void ConsolidationHandler(TradeBar consolidatedBar)
{

}
def consolidation_handler(self, consolidated_bar: TradeBar) -> None:
    pass

Consolidate Quote Bars

QuoteBar consolidators aggregate QuoteBar objects into QuoteBar objects of the same size or larger. Follow these steps to create and manage a QuoteBar consolidator based on a period of time:

  1. Create the consolidator.
  2. To set the time period for the consolidator, you can use either a timedeltaTimeSpan or Resolution object. The consolidator time period must be greater than or equal to the resolution of the security subscription. For instance, you can aggregate minute bars into 10-minute bars, but you can't aggregate hour bars into 10-minute bars.

    • timedelta Periods
    • TimeSpan Periods
    • _consolidator = new QuoteBarConsolidator(TimeSpan.FromDays(1));
      // Aliases:
      // _consolidator = CreateConsolidator(TimeSpan.FromDays(1), typeof(QuoteBar));
      // _consolidator = ResolveConsolidator(_symbol, TimeSpan.FromDays(1));
      self.consolidator = QuoteBarConsolidator(timedelta(days=1))
      # Aliases:
      # self.consolidator = self.CreateConsolidator(timedelta(days=1), QuoteBar)
      # self.consolidator = self.ResolveConsolidator(self.symbol, timedelta(days=1))

      The time period is relative to the data time zone, not the algorithm time zone. If you consolidate Crypto data into daily bars, the event handler receives the consolidated bars at midnight 12:00 AM Coordinated Universal Time (UTC), regardless of the algorithm time zone.

    • Resolution Periods
    • The Resolution enumeration has the following members:

      _consolidator = ResolveConsolidator(_symbol, Resolution.Daily);
      self.consolidator = self.ResolveConsolidator(self.symbol, Resolution.Daily)

    If the security subscription in your algorithm provides TradeBar and QuoteBar data, ResolveConsolidator returns a TradeBarConsolidator.

    If you consolidate on an hourly basis, the consolidator ends at the top of the hour, not every hour after the market open. For US Equities, that's 10 AM Eastern Time (ET), not 10:30 AM ET.

  3. Add an event handler to the consolidator.
  4. _consolidator.DataConsolidated += ConsolidationHandler;
    self.consolidator.DataConsolidated += self.consolidation_handler

    LEAN passes consolidated bars to the consolidator event handler in your algorithm. The most common error when creating consolidators is to put parenthesis () at the end of your method name when setting the event handler of the consolidator. If you use parenthesis, the method executes and the result is passed as the event handler instead of the method itself. Remember to pass the name of your method to the event system. Specifically, it should be ConsolidationHandlerself.consolidation_handler, not ConsolidationHandler()self.consolidation_handler().

  5. Define the consolidation handler.
  6. void ConsolidationHandler(object sender, QuoteBar consolidatedBar)
    {
    
    }
    def consolidation_handler(self, sender: object, consolidated_bar: QuoteBar) -> None:
        pass

    The consolidation event handler receives bars when the consolidated bar closes based on the data time zone. If you subscribe to minute resolution data for Bitcoin and create an hourly consolidator, you receive consolidated bars at the top of each hour. However, if you subscribe to minute resolution data for the regular trading hours of US Equities and create a daily consolidator, you receive consolidated bars at 9:31 AM Eastern Time (ET). The consolidated bar for US Equities doesn't close at 4:00 PM ET because the day isn't over. The consolidated bar for US Equities also doesn't close at midnight because your algorithm doesn't receive minute resolution data after 4:00 PM ET until 9:31 AM ET.

  7. Update the consolidator.
  8. You can automatically or manually update the consolidator.

    • Automatic Updates
    • To automatically update a consolidator with data from the security subscription, call the AddConsolidator method of the Subscription Manager.

      self.SubscriptionManager.AddConsolidator(self.symbol, self.consolidator)
      SubscriptionManager.AddConsolidator(_symbol, _consolidator);
    • Manual Updates
    • Manual updates let you control when the consolidator updates and what data you use to update it. If you need to warm up a consolidator with data outside of the warm-up period, you can manually update the consolidator. To manually update a consolidator, call its Update method with a QuoteBar object. You can update the consolidator with data from the Slice object in the OnData method or with data from a history request.

      # Example 1: Update the consolidator with data from the Slice object
      def OnData(self, slice: Slice) -> None:
          quote_bar = slice.QuoteBars[self.symbol]
          self.consolidator.Update(quote_bar)
      
      # Example 2: Update the consolidator with data from a history request
      history = self.History[QuoteBar](self.symbol, 30, Resolution.Minute)
      for quote_bar in history:
          self.consolidator.Update(quote_bar)
      // Example 1: Update the consolidator with data from the Slice object
      public override void OnData(Slice slice)
      {
          var quoteBar = slice.QuoteBars[_symbol];
          _consolidator.Update(quoteBar);
      }
      
      // Example 2: Update the consolidator with data from a history request
      var history = History<QuoteBar>(_symbol, 30, Resolution.Minute);
      foreach (var quoteBar in history)
      {
          _consolidator.Update(quoteBar);
      }
  9. If you create consolidators for securities in a dynamic universe and register them for automatic updates, remove the consolidator when the security leaves the universe.
  10. SubscriptionManager.RemoveConsolidator(_symbol, _consolidator);
    self.SubscriptionManager.RemoveConsolidator(self.symbol, self.consolidator)

    If you have a dynamic universe and don't remove consolidators, they compound internally, causing your algorithm to slow down and eventually die once it runs out of RAM. For an example of removing consolidators from universe subscriptions, see the GasAndCrudeOilEnergyCorrelationAlphaGasAndCrudeOilEnergyCorrelationAlpha in the LEAN GitHub repository.

You can also use the Consolidate helper method to create period consolidators and register them for automatic updates. With just one line of code, you can create data in any time period based on a timedeltaTimeSpan or Resolution object:

  • TimeSpan Periods
  • timedelta Periods
  • _consolidator = Consolidate<QuoteBar>(_symbol, TimeSpan.FromDays(1), TickType.Quote, ConsolidationHandler);
    self.consolidator = self.Consolidate(self.symbol, timedelta(days=1), TickType.Quote, self.consolidation_handler)
  • Resolution Periods
  • _consolidator = Consolidate<QuoteBar>(_symbol, Resolution.Daily, TickType.Quote, ConsolidationHandler);
    self.consolidator = self.Consolidate(self.symbol, Resolution.Daily, TickType.Quote, self.consolidation_handler)

If you use the Consolidate helper method, the consolidation handler doesn't receive an object argument.

void ConsolidationHandler(QuoteBar consolidatedBar)
{

}
def consolidation_handler(self, consolidated_bar: QuoteBar) -> None:
    pass

Consolidate Trade Ticks

Tick consolidators aggregate Tick objects into TradeBar objects. Follow these steps to create and manage a Tick consolidator based on a period of time:

  1. Create the consolidator.
  2. To set the time period for the consolidator, you can use either a timedeltaTimeSpan or Resolution object. The consolidator time period must be greater than or equal to the resolution of the security subscription. For instance, you can aggregate minute bars into 10-minute bars, but you can't aggregate hour bars into 10-minute bars.

    • timedelta Periods
    • TimeSpan Periods
    • _consolidator = new TickConsolidator(TimeSpan.FromMilliseconds(100));
      // Aliases:
      // _consolidator = CreateConsolidator(TimeSpan.FromMilliseconds(100), typeof(Tick));
      // _consolidator = ResolveConsolidator(_symbol, TimeSpan.FromMilliseconds(100));
      self.consolidator = TickConsolidator(timedelta(milliseconds=100))
      # Aliases:
      # self.consolidator = self.CreateConsolidator(timedelta(milliseconds=100), Tick)
      # self.consolidator = self.ResolveConsolidator(self.symbol, timedelta(milliseconds=100))

      The time period is relative to the data time zone, not the algorithm time zone. If you consolidate Crypto data into daily bars, the event handler receives the consolidated bars at midnight 12:00 AM Coordinated Universal Time (UTC), regardless of the algorithm time zone.

    • Resolution Periods
    • The Resolution enumeration has the following members:

      _consolidator = ResolveConsolidator(_symbol, Resolution.Second);
      self.consolidator = self.ResolveConsolidator(self.symbol, Resolution.Second)

    If you consolidate on an hourly basis, the consolidator ends at the top of the hour, not every hour after the market open. For US Equities, that's 10 AM Eastern Time (ET), not 10:30 AM ET.

  3. Add an event handler to the consolidator.
  4. _consolidator.DataConsolidated += ConsolidationHandler;
    self.consolidator.DataConsolidated += self.consolidation_handler

    LEAN passes consolidated bars to the consolidator event handler in your algorithm. The most common error when creating consolidators is to put parenthesis () at the end of your method name when setting the event handler of the consolidator. If you use parenthesis, the method executes and the result is passed as the event handler instead of the method itself. Remember to pass the name of your method to the event system. Specifically, it should be ConsolidationHandlerself.consolidation_handler, not ConsolidationHandler()self.consolidation_handler().

  5. Define the consolidation handler.
  6. void ConsolidationHandler(object sender, TradeBar consolidatedBar)
    {
    
    }
    def consolidation_handler(self, sender: object, consolidated_bar: TradeBar) -> None:
        pass

    The consolidation event handler receives bars when the consolidated bar closes based on the data time zone. If you subscribe to tick resolution data for Bitcoin and create an hourly consolidator, you receive consolidated bars at the top of each hour. However, if you subscribe to tick resolution data for the regular trading hours of US Equities and create a daily consolidator, you receive consolidated bars milliseconds after 9:30 AM Eastern Time (ET). The consolidated bar for US Equities doesn't close at 4:00 PM ET because the day isn't over. The consolidated bar for US Equities also doesn't close at midnight because your algorithm doesn't receive minute resolution data after 4:00 PM ET until milliseconds after 9:30 AM ET.

  7. Update the consolidator.
  8. You can automatically or manually update the consolidator.

    • Automatic Updates
    • To automatically update a consolidator with data from the security subscription, call the AddConsolidator method of the Subscription Manager.

      self.SubscriptionManager.AddConsolidator(self.symbol, self.consolidator)
      SubscriptionManager.AddConsolidator(_symbol, _consolidator);
    • Manual Updates
    • Manual updates let you control when the consolidator updates and what data you use to update it. If you need to warm up a consolidator with data outside of the warm-up period, you can manually update the consolidator. To manually update a consolidator, call its Update method with a Tick object. You can update the consolidator with data from the Slice object in the OnData method or with data from a history request.

      # Example 1: Update the consolidator with data from the Slice object
      def OnData(self, slice: Slice) -> None:
          ticks = slice.Ticks[self.symbol]
          for tick in ticks:
          	self.consolidator.Update(tick)
      
      # Example 2: Update the consolidator with data from a history request
      ticks = self.History[Tick](self.symbol, timedelta(minutes=3), Resolution.Tick)
      for tick in ticks:
          self.consolidator.Update(tick)
      // Example 1: Update the consolidator with data from the Slice object
      public override void OnData(Slice slice)
      {
          var ticks = slice.Ticks[_symbol];
          foreach (var tick in ticks)
          {
          	_consolidator.Update(tick);
          }
      }
      
      // Example 2: Update the consolidator with data from a history request
      var ticks = History<Tick>(_symbol, TimeSpan.FromMinutes(3), Resolution.Tick);
      foreach (var tick in ticks)
      {
          _consolidator.Update(tick);
      }
  9. If you create consolidators for securities in a dynamic universe and register them for automatic updates, remove the consolidator when the security leaves the universe.
  10. SubscriptionManager.RemoveConsolidator(_symbol, _consolidator);
    self.SubscriptionManager.RemoveConsolidator(self.symbol, self.consolidator)

    If you have a dynamic universe and don't remove consolidators, they compound internally, causing your algorithm to slow down and eventually die once it runs out of RAM. For an example of removing consolidators from universe subscriptions, see the GasAndCrudeOilEnergyCorrelationAlphaGasAndCrudeOilEnergyCorrelationAlpha in the LEAN GitHub repository.

You can also use the Consolidate helper method to create period consolidators and register them for automatic updates. With just one line of code, you can create data in any time period based on a timedeltaTimeSpan or Resolution object:

  • TimeSpan Periods
  • timedelta Periods
  • _consolidator = Consolidate(_symbol, TimeSpan.FromMilliseconds(100), ConsolidationHandler);
    self.consolidator = self.Consolidate(self.symbol, timedelta(milliseconds=100), self.consolidation_handler)
  • Resolution Periods
  • _consolidator = Consolidate(_symbol, Resolution.Second, ConsolidationHandler);
    self.consolidator = self.Consolidate(self.symbol, Resolution.Second, self.consolidation_handler)

If you use the Consolidate helper method, the consolidation handler doesn't receive an object argument.

void ConsolidationHandler(TradeBar consolidatedBar)
{

}
def consolidation_handler(self, consolidated_bar: TradeBar) -> None:
    pass

Consolidate Quote Ticks

Tick quote bar consolidators aggregate Tick objects that represent quotes into QuoteBar objects. Follow these steps to create and manage a Tick quote bar consolidator based on a period of time:

  1. Create the consolidator.
  2. To set the time period for the consolidator, you can use either a timedeltaTimeSpan or Resolution object. The consolidator time period must be greater than or equal to the resolution of the security subscription. For instance, you can aggregate minute bars into 10-minute bars, but you can't aggregate hour bars into 10-minute bars.

    • timedelta Periods
    • TimeSpan Periods
    • _consolidator = new TickQuoteBarConsolidator(TimeSpan.FromMilliseconds(100));
      // Aliases:
      // _consolidator = CreateConsolidator(TimeSpan.FromMilliseconds(100), typeof(Tick), TickType.Quote);
      // _consolidator = ResolveConsolidator(_symbol, TimeSpan.FromMilliseconds(100), typeof(QuoteBar));
      self.consolidator = TickQuoteBarConsolidator(timedelta(milliseconds=100))
      # Aliases:
      # self.consolidator = self.CreateConsolidator(timedelta(milliseconds=100), Tick, TickType.Quote)
      # self.consolidator = self.ResolveConsolidator(self.symbol, timedelta(milliseconds=100))

      The time period is relative to the data time zone, not the algorithm time zone. If you consolidate Crypto data into daily bars, the event handler receives the consolidated bars at midnight 12:00 AM Coordinated Universal Time (UTC), regardless of the algorithm time zone.

    • Resolution Periods
    • The Resolution enumeration has the following members:

      _consolidator = ResolveConsolidator(_symbol, Resolution.Second);
      self.consolidator = self.ResolveConsolidator(self.symbol, Resolution.Second)

    If you consolidate on an hourly basis, the consolidator ends at the top of the hour, not every hour after the market open. For US Equities, that's 10 AM Eastern Time (ET), not 10:30 AM ET.

  3. Add an event handler to the consolidator.
  4. _consolidator.DataConsolidated += ConsolidationHandler;
    self.consolidator.DataConsolidated += self.consolidation_handler

    LEAN passes consolidated bars to the consolidator event handler in your algorithm. The most common error when creating consolidators is to put parenthesis () at the end of your method name when setting the event handler of the consolidator. If you use parenthesis, the method executes and the result is passed as the event handler instead of the method itself. Remember to pass the name of your method to the event system. Specifically, it should be ConsolidationHandlerself.consolidation_handler, not ConsolidationHandler()self.consolidation_handler().

  5. Define the consolidation handler.
  6. void ConsolidationHandler(object sender, QuoteBar consolidatedBar)
    {
    
    }
    def consolidation_handler(self, sender: object, consolidated_bar: QuoteBar) -> None:
        pass

    The consolidation event handler receives bars when the consolidated bar closes based on the data time zone. If you subscribe to tick resolution data for Bitcoin and create an hourly consolidator, you receive consolidated bars at the top of each hour. However, if you subscribe to tick resolution data for the regular trading hours of US Equities and create a daily consolidator, you receive consolidated bars milliseconds after 9:30 AM Eastern Time (ET). The consolidated bar for US Equities doesn't close at 4:00 PM ET because the day isn't over. The consolidated bar for US Equities also doesn't close at midnight because your algorithm doesn't receive minute resolution data after 4:00 PM ET until milliseconds after 9:30 AM ET.

  7. Update the consolidator.
  8. You can automatically or manually update the consolidator.

    • Automatic Updates
    • To automatically update a consolidator with data from the security subscription, call the AddConsolidator method of the Subscription Manager.

      self.SubscriptionManager.AddConsolidator(self.symbol, self.consolidator)
      SubscriptionManager.AddConsolidator(_symbol, _consolidator);
    • Manual Updates
    • Manual updates let you control when the consolidator updates and what data you use to update it. If you need to warm up a consolidator with data outside of the warm-up period, you can manually update the consolidator. To manually update a consolidator, call its Update method with a Tick object. You can update the consolidator with data from the Slice object in the OnData method or with data from a history request.

      # Example 1: Update the consolidator with data from the Slice object
      def OnData(self, slice: Slice) -> None:
          ticks = slice.Ticks[self.symbol]
          for tick in ticks:
          	self.consolidator.Update(tick)
      
      # Example 2: Update the consolidator with data from a history request
      ticks = self.History[Tick](self.symbol, timedelta(minutes=3), Resolution.Tick)
      for tick in ticks:
          self.consolidator.Update(tick)
      // Example 1: Update the consolidator with data from the Slice object
      public override void OnData(Slice slice)
      {
          var ticks = slice.Ticks[_symbol];
          foreach (var tick in ticks)
          {
          	_consolidator.Update(tick);
          }
      }
      
      // Example 2: Update the consolidator with data from a history request
      var ticks = History<Tick>(_symbol, TimeSpan.FromMinutes(3), Resolution.Tick);
      foreach (var tick in ticks)
      {
          _consolidator.Update(tick);
      }
  9. If you create consolidators for securities in a dynamic universe and register them for automatic updates, remove the consolidator when the security leaves the universe.
  10. SubscriptionManager.RemoveConsolidator(_symbol, _consolidator);
    self.SubscriptionManager.RemoveConsolidator(self.symbol, self.consolidator)

    If you have a dynamic universe and don't remove consolidators, they compound internally, causing your algorithm to slow down and eventually die once it runs out of RAM. For an example of removing consolidators from universe subscriptions, see the GasAndCrudeOilEnergyCorrelationAlphaGasAndCrudeOilEnergyCorrelationAlpha in the LEAN GitHub repository.

You can also use the Consolidate helper method to create period consolidators and register them for automatic updates. With just one line of code, you can create data in any time period based on a timedeltaTimeSpan or Resolution object:

  • TimeSpan Periods
  • timedelta Periods
  • _consolidator = Consolidate<QuoteBar>(_symbol, TimeSpan.FromMilliseconds(100), TickType.Quote, ConsolidationHandler);
    self.consolidator = self.Consolidate(self.symbol, timedelta(milliseconds=100), TickType.Quote, self.consolidation_handler)
  • Resolution Periods
  • _consolidator = Consolidate<QuoteBar>(_symbol, Resolution.Second, TickType.Quote, ConsolidationHandler);
    self.consolidator = self.Consolidate(self.symbol, Resolution.Second, TickType.Quote, self.consolidation_handler)

If you use the Consolidate helper method, the consolidation handler doesn't receive an object argument.

void ConsolidationHandler(QuoteBar consolidatedBar)
{

}
def consolidation_handler(self, consolidated_bar: QuoteBar) -> None:
    pass

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: