{"record":{"id":"4bb94883c3635116","repo":"QuantConnect/Lean","slug":"unexpected-open-interest-time-openinterest-singl","errorCode":null,"errorMessage":"Unexpected open interest time: {openInterest.Single().EndTime}","messagePattern":"Unexpected open interest time: (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Algorithm.CSharp/BasicTemplateIndexDailyAlgorithm.cs","lineNumber":75,"sourceCode":"        }\n\n        public override void OnEndOfAlgorithm()\n        {\n            if (BarCounter != ExpectedBarCount)\n            {\n                throw new ArgumentException($\"Bar Count {BarCounter} is not expected count of {ExpectedBarCount}\");\n            }\n            AssertIndicators();\n\n            if (Resolution != Resolution.Daily)\n            {\n                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            }","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.CSharp/BasicTemplateIndexDailyAlgorithm.cs#L57-L93","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","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."],"exampleFix":"// before\nif (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// after — include timezone info for diagnosis\nvar expected = new DateTime(2021, 1, 15, 15, 15, 0);\nvar actual = openInterest.Single().EndTime;\nLog($\"OI EndTime: {actual} (Kind={actual.Kind}), Expected: {expected}\");\nif (actual != expected)\n{\n    throw new ArgumentException($\"Unexpected open interest time: {actual}\");\n}","handlingStrategy":"validation","validationCode":"// Validate open interest cache before asserting\nvar openInterest = Securities[SpxOption].Cache.GetAll<OpenInterest>().ToList();\nif (openInterest.Count != 1)\n{\n    Log($\"Expected 1 OI entry, found {openInterest.Count}\");\n    return;\n}\nvar expectedEnd = new DateTime(2021, 1, 15, 15, 15, 0);\nif (openInterest[0].EndTime != expectedEnd)\n{\n    Log($\"OI EndTime mismatch: {openInterest[0].EndTime} vs {expectedEnd} (kind: {openInterest[0].EndTime.Kind})\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["quantconnect","open-interest","timestamp","data-pipeline","timezone","regression-test"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}