Skip to content

Market Hours Aware Consolidators #9480

@AlexCatarino

Description

@AlexCatarino

Expected Behavior

Consolidators are market-hours aware. In other words, they only account for market hours.
For example, US Equity opens at 9:30, so if we are using 7-min bars, the first bar will be at 9:37 AM. If we use extended hours, the first bar will be 4:07 AM.

Actual Behavior

As it is now, the bar size accounts for the closed market hours, and keeps a continuous period.

class BasicFutureAlgorithm(QCAlgorithm):
    _day = 0
    def initialize(self):
        self.set_start_date(2024, 12, 1)
        self.set_end_date(2024, 12, 31)
        self._future = self.add_future(
            Futures.Indices.SP_500_E_MINI,
            extended_market_hours=True
        )
        
        consolidator = TradeBarConsolidator(timedelta(minutes=7))
        consolidator.data_consolidated += self._log_bar
        self.subscription_manager.add_consolidator(self._future.symbol, consolidator)

    def _log_bar(self, sender, bar):
        if bar.end_time.day == self._day:
            return
        self._day = bar.end_time.day
        self.log(str(bar))

The market opens at 18 on Sunday, so we should see 18:07 instead of 18:03. It's 18:03 because of the 7-min bars started at 20241201 00:00:00:

Image

Potential Solution

N/A

Checklist

  • I have completely filled out this template
  • I have confirmed that this issue exists on the current master branch
  • I have confirmed that this is not a duplicate issue by searching issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions