{"record":{"id":"a67be608058fb989","repo":"QuantConnect/Lean","slug":"unexpected-history-data-start-time","errorCode":null,"errorMessage":"Unexpected history data start time","messagePattern":"Unexpected history data start time","errorType":"exception","errorClass":"RegressionTestException","httpStatus":null,"severity":"error","filePath":"Algorithm.CSharp/BasicTemplateIndexDailyAlgorithm.cs","lineNumber":87,"sourceCode":"                return;\n            }\n\n            var openInterest = Securities[SpxOption].Cache.GetAll<OpenInterest>();\n            if (openInterest.Single().EndTime != new DateTime(2021, 1, 15, 15, 15, 0))\n            {\n                throw new ArgumentException($\"Unexpected open interest time: {openInterest.Single().EndTime}\");\n            }\n\n            foreach (var symbol in new[] { SpxOption, Spx })\n            {\n                var history = History(symbol, 10).ToList();\n                if (history.Count != 10)\n                {\n                    throw new RegressionTestException($\"Unexpected history count: {history.Count}\");\n                }\n                if (history.Any(x => x.Time.TimeOfDay != new TimeSpan(8, 30, 0)))\n                {\n                    throw new RegressionTestException($\"Unexpected history data start time\");\n                }\n                if (history.Any(x => x.EndTime.TimeOfDay != new TimeSpan(15, 15, 0)))\n                {\n                    throw new RegressionTestException($\"Unexpected history data end time\");\n                }\n            }\n        }\n\n        /// <summary>\n        /// This is used by the regression test system to indicate if the open source Lean repository has the required data to run this algorithm.\n        /// </summary>\n        public override bool CanRunLocally { get; } = true;\n\n        /// <summary>\n        /// This is used by the regression test system to indicate which languages this algorithm is written in.\n        /// </summary>\n        public override List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };\n","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.CSharp/BasicTemplateIndexDailyAlgorithm.cs#L69-L105","documentation":"Thrown when any of the 10 history bars returned for SpxOption or Spx has a Time.TimeOfDay that is not 08:30:00. For daily-resolution SPX bars, the bar start time should be 8:30 AM US Eastern (market open). A mismatch indicates a timezone, market-hours, or bar-construction problem in the data pipeline.","triggerScenarios":"The algorithm's SetTimeZone is configured differently than the data's native timezone, MarketHoursDatabase changed the SPX market-open time, the daily bar Time field was set to midnight instead of market open, or a data normalization change altered the bar start timestamp.","commonSituations":"Engine-wide timezone refactoring, changes to MarketHoursEntry for SecurityType.Index, switching from exchange-local to UTC timestamps, or data re-ingestion that stamped bars at midnight.","solutions":["Verify the algorithm's time zone matches the data's exchange timezone (SetTimeZone should reflect SPX exchange hours).","Check MarketHoursDatabase for the SPX/USA index entry to confirm market open is 8:30.","Inspect the raw data file timestamps and compare against what the history provider returns.","Log each history bar's Time and EndTime with .Kind to identify UTC/local confusion."],"exampleFix":"// before\nif (history.Any(x => x.Time.TimeOfDay != new TimeSpan(8, 30, 0)))\n{\n    throw new RegressionTestException($\"Unexpected history data start time\");\n}\n\n// after — show which bar is wrong\nvar bad = history.FirstOrDefault(x => x.Time.TimeOfDay != new TimeSpan(8, 30, 0));\nif (bad != null)\n{\n    throw new RegressionTestException($\"Unexpected history start time: {bad.Time} (Kind={bad.Time.Kind})\");\n}","handlingStrategy":"validation","validationCode":"// Validate history bar start times with diagnostics\nvar history = History(symbol, 10).ToList();\nvar expectedStart = new TimeSpan(8, 30, 0);\nvar badBar = history.FirstOrDefault(x => x.Time.TimeOfDay != expectedStart);\nif (badBar != null)\n{\n    Log($\"Bad start time: {badBar.Time} (kind={badBar.Time.Kind}) for {symbol}\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify MarketHoursDatabase market-open time for the security type and market.","Log Time.Kind alongside time-of-day checks to catch timezone issues.","Confirm the algorithm SetTimeZone matches the exchange timezone.","Check that data files store exchange-local timestamps."],"tags":["quantconnect","history","timestamp","market-hours","timezone","regression-test"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}