QuantConnect/Lean · error · ArgumentException
Unexpected open interest time: {openInterest.Single().EndTim
Error message
Unexpected open interest time: {openInterest.Single().EndTime} What it means
Thrown when the EndTime of the single cached OpenInterest data point for SpxOption does not equal 2021-01-15 15:15:00. This verifies that the daily-resolution data pipeline stamps open-interest records with the correct exchange-close timestamp (15:15 US Eastern for SPX). A mismatch indicates a timezone offset, data ingestion error, or bar-construction change.
Source
Thrown at Algorithm.CSharp/BasicTemplateIndexDailyAlgorithm.cs:75
}
public override void OnEndOfAlgorithm()
{
if (BarCounter != ExpectedBarCount)
{
throw new ArgumentException($"Bar Count {BarCounter} is not expected count of {ExpectedBarCount}");
}
AssertIndicators();
if (Resolution != Resolution.Daily)
{
return;
}
var openInterest = Securities[SpxOption].Cache.GetAll<OpenInterest>();
if (openInterest.Single().EndTime != new DateTime(2021, 1, 15, 15, 15, 0))
{
throw new ArgumentException($"Unexpected open interest time: {openInterest.Single().EndTime}");
}
foreach (var symbol in new[] { SpxOption, Spx })
{
var history = History(symbol, 10).ToList();
if (history.Count != 10)
{
throw new RegressionTestException($"Unexpected history count: {history.Count}");
}
if (history.Any(x => x.Time.TimeOfDay != new TimeSpan(8, 30, 0)))
{
throw new RegressionTestException($"Unexpected history data start time");
}
if (history.Any(x => x.EndTime.TimeOfDay != new TimeSpan(15, 15, 0)))
{
throw new RegressionTestException($"Unexpected history data end time");
}
}View on GitHub (pinned to d2c3659f87)
Solutions
- Inspect the raw open interest data file for SpxOption to verify the stored timestamp is 2021-01-15 15:15.
- Check SetTimeZone and Settings.DailyPreciseEndTime configuration in Initialize.
- Verify the Lean engine's BaseData EndTime logic for daily-resolution bars has not changed.
- Debug-log openInterest.Single().EndTime and its Kind (UTC vs local) to identify timezone mismatch.
- If openInterest has more than one entry, investigate why the cache retained stale data.
Example fix
// before
if (openInterest.Single().EndTime != new DateTime(2021, 1, 15, 15, 15, 0))
{
throw new ArgumentException($"Unexpected open interest time: {openInterest.Single().EndTime}");
}
// after — include timezone info for diagnosis
var expected = new DateTime(2021, 1, 15, 15, 15, 0);
var actual = openInterest.Single().EndTime;
Log($"OI EndTime: {actual} (Kind={actual.Kind}), Expected: {expected}");
if (actual != expected)
{
throw new ArgumentException($"Unexpected open interest time: {actual}");
} Defensive patterns
Strategy: validation
Validate before calling
// Validate open interest cache before asserting
var openInterest = Securities[SpxOption].Cache.GetAll<OpenInterest>().ToList();
if (openInterest.Count != 1)
{
Log($"Expected 1 OI entry, found {openInterest.Count}");
return;
}
var expectedEnd = new DateTime(2021, 1, 15, 15, 15, 0);
if (openInterest[0].EndTime != expectedEnd)
{
Log($"OI EndTime mismatch: {openInterest[0].EndTime} vs {expectedEnd} (kind: {openInterest[0].EndTime.Kind})");
} Prevention
- Always log DateTime.Kind alongside timestamps to catch UTC/local confusion.
- Verify data file timestamps match expected exchange-close times.
- Check that DailyPreciseEndTime is enabled when testing daily bar timestamps.
- Document the expected timezone for each assertion timestamp.
When it happens
Trigger: The open interest data file has an incorrect timestamp, the algorithm's time zone is set differently than expected, the daily bar EndTime calculation changed in Lean's data pipeline, or openInterest.Single() returns a different entry than expected because the cache contains multiple or zero entries.
Common situations: Timezone configuration changes in the Lean engine, data re-ingestion producing shifted timestamps, switching between DailyPreciseEndTime settings, or modifications to how Lean computes EndTime for daily bars (close time vs. midnight).
Related errors
- Unexpected history data start time
- Bar Count {BarCounter} is not expected count of {ExpectedBar
- Unexpected history count: {history.Count}
- Unexpected history data end time
- Expiry event was not at the correct time, {orderEvent.UtcTim
AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13).
Data as JSON: /api/errors/4bb94883c3635116.
Report an issue: GitHub.