QuantConnect/Lean · error · AssertionError
Algorithm should have run on extended hours for {self._es.sy
Error message
Algorithm should have run on extended hours for {self._es.symbol} future, which enabled extended market hours What it means
End-of-algorithm assertion that the ES future (extended hours enabled) produced data during an extended-hours bar at least once. _es_ran_on_extended_hours is set only when ES is in extended hours AND the slice contains ES data. Failing means extended-hours data never arrived despite the flag.
Source
Thrown at Algorithm.Python/FuturesExtendedMarketHoursRegressionAlgorithm.py:66
gc_is_in_regular_hours = self._gc.exchange.hours.is_open(self.time, False)
gc_is_in_extended_hours = not gc_is_in_regular_hours and self._gc.exchange.hours.is_open(self.time, True)
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
- Confirm add_future(..., extended_market_hours=True) is set for ES.
- Verify ES data files contain extended-hours bars in the window.
- Log slice_symbols during expected extended times to confirm subscription.
- Widen the date range to include at least one extended session.
Defensive patterns
Strategy: validation
Validate before calling
# Track extended-hours data arrival for ES
in_ext = (not self._es.exchange.hours.is_open(self.time, False)) and self._es.exchange.hours.is_open(self.time, True)
if in_ext and self._es.symbol in slice_symbols:
self._es_ran_on_extended_hours = True
else:
self.debug(f"No ES extended-hours data yet at {self.time}") Type guard
def slice_has_extended_hours_data(security, slice_symbols, t: datetime) -> bool:
in_ext = (not security.exchange.hours.is_open(t, False)) and security.exchange.hours.is_open(t, True)
return in_ext and security.symbol in slice_symbols Prevention
- Always pass extended_market_hours=True when extended data is expected.
- Verify ES data files contain extended-hours bars in the window.
- Widen the date range to include at least one extended session.
- Log slice_symbols during expected extended times.
When it happens
Trigger: extended_market_hours=True but data files lack extended-hours bars; the engine not subscribing to the extended session; slice symbol matching failing for extended-hours bars; backtest window not covering any extended-hours period.
Common situations: Data drop missing pre-market / post-market ES bars; engine change dropping the extended subscription when the flag is set; date range too narrow to include an extended session; resolution mismatch hiding extended bars.
Related errors
- Algorithm should have run on regular hours for {self._es.sym
- The Exchange hours was closed, verify 'extended_market_hours
- Never invested in ES futures and FOPs
- At {Time}, {_es.symbol} is either in regular hours but curre
- Algorithm should have run on regular hours for {self._gc.sym
AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13).
Data as JSON: /api/errors/ad7e1a115038a08d.
Report an issue: GitHub.