QuantConnect/Lean · error · AssertionError

Algorithm should have run on regular hours for {self._gc.sym

Error message

Algorithm should have run on regular hours for {self._gc.symbol} future, which did not enable extended market hours

What it means

End-of-algorithm assertion that the GC gold future (extended hours NOT enabled) still produced regular-hours data. _gc_ran_on_regular_hours requires GC in regular hours AND slice contains GC data. Failing means the algorithm never saw a regular-hours GC bar.

Source

Thrown at Algorithm.Python/FuturesExtendedMarketHoursRegressionAlgorithm.py:69

        slice_has_g_c_data = self._gc.symbol in slice_symbols
        self._gc_ran_on_regular_hours |= gc_is_in_regular_hours and slice_has_g_c_data
        self._gc_ran_on_extended_hours |= gc_is_in_extended_hours and slice_has_g_c_data

        time_of_day = self.time.time()
        current_time_is_regular_hours = (time_of_day >= time(9, 30, 0) and time_of_day < time(16, 15, 0)) or (time_of_day >= time(16, 30, 0) and time_of_day < time(17, 0, 0))
        current_time_is_extended_hours = not current_time_is_regular_hours and (time_of_day < time(9, 30, 0) or time_of_day >= time(18, 0, 0))
        if es_is_in_regular_hours != current_time_is_regular_hours or es_is_in_extended_hours != current_time_is_extended_hours:
            raise AssertionError("At {Time}, {_es.symbol} is either in regular hours but current time is in extended hours, or viceversa")

    def on_end_of_algorithm(self):
        if not self._es_ran_on_regular_hours:
            raise AssertionError(f"Algorithm should have run on regular hours for {self._es.symbol} future, which enabled extended market hours")

        if not self._es_ran_on_extended_hours:
            raise AssertionError(f"Algorithm should have run on extended hours for {self._es.symbol} future, which enabled extended market hours")

        if not self._gc_ran_on_regular_hours:
            raise AssertionError(f"Algorithm should have run on regular hours for {self._gc.symbol} future, which did not enable extended market hours")

        if self._gc_ran_on_extended_hours:
            raise AssertionError(f"Algorithm should have not run on extended hours for {self._gc.symbol} future, which did not enable extended market hours")

View on GitHub (pinned to d2c3659f87)

Solutions

  1. Log self.time and slice_symbols to confirm GC arrives in regular hours.
  2. Verify GC data files cover the regular session for the window.
  3. Confirm slice_symbols includes both mapped and canonical GC symbol.
  4. Check the MarketHoursDatabase regular-session window for GC gold.
Defensive patterns

Strategy: validation

Validate before calling

# Track regular-hours data arrival for GC
if self._gc.exchange.hours.is_open(self.time, False) and self._gc.symbol in slice_symbols:
    self._gc_ran_on_regular_hours = True
else:
    self.debug(f"No GC regular-hours data yet at {self.time}")

Type guard

def slice_has_regular_hours_data(security, slice_symbols, t: datetime) -> bool:
    return security.exchange.hours.is_open(t, False) and security.symbol in slice_symbols

Prevention

When it happens

Trigger: GC data missing for every regular-hours bar; is_open returning False for all GC regular times due to a MarketHoursDatabase bug; slice symbol matching failing so slice_has_g_c_data is always False.

Common situations: Data drop covering only non-regular GC bars; canonical-vs-mapped symbol mismatch; resolution/fill-forward suppressing regular bars; MarketHoursDatabase entry for GC gold narrowing the regular session.

Related errors


AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13). Data as JSON: /api/errors/be3bd5def28d5016. Report an issue: GitHub.