{"record":{"id":"ecf63602edd0b6ad","repo":"QuantConnect/Lean","slug":"empty-history-at-time","errorCode":null,"errorMessage":"Empty history at {Time}","messagePattern":"Empty history at (.+?)","errorType":"exception","errorClass":"RegressionTestException","httpStatus":null,"severity":"error","filePath":"Algorithm.CSharp/BasicTemplateFuturesHistoryAlgorithm.cs","lineNumber":72,"sourceCode":"            SetCash(1000000);\n\n            foreach (var root in roots)\n            {\n                // set our expiry filter for this futures chain\n                AddFuture(root, Resolution.Minute, extendedMarketHours: ExtendedMarketHours).SetFilter(TimeSpan.Zero, TimeSpan.FromDays(182));\n            }\n\n            SetBenchmark(d => 1000000);\n\n            Schedule.On(DateRules.EveryDay(), TimeRules.Every(TimeSpan.FromHours(1)), MakeHistoryCall);\n        }\n\n        private void MakeHistoryCall()\n        {\n            var history = History(10, Resolution.Minute);\n            if (history.Count() < 10)\n            {\n                throw new RegressionTestException($\"Empty history at {Time}\");\n            }\n            _successCount++;\n        }\n\n        public override void OnEndOfAlgorithm()\n        {\n            if (_successCount < ExpectedHistoryCallCount)\n            {\n                throw new RegressionTestException($\"Scheduled Event did not assert history call as many times as expected: {_successCount}/49\");\n            }\n        }\n\n        /// <summary>\n        /// Event - v3.0 DATA EVENT HANDLER: (Pattern) Basic template for user to override for receiving all subscription data in a single event\n        /// </summary>\n        /// <param name=\"slice\">The current slice of data keyed by symbol string</param>\n        public override void OnData(Slice slice)\n        {","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.CSharp/BasicTemplateFuturesHistoryAlgorithm.cs#L54-L90","documentation":"A scheduled history probe calls History(10, Resolution.Minute) and asserts at least 10 minute bars return. Fewer than 10 means the history request yielded insufficient data for the period — the futures universe lacked 10 minutes of lookback at that call time, so the data window was empty or short.","triggerScenarios":"MakeHistoryCall() (scheduled every hour) runs History(10, Resolution.Minute) and the returned enumerable has Count() < 10 — not enough minute-bar history exists for the subscribed futures at that wall-clock point (e.g. near warm-up, market open, or a data gap).","commonSituations":"Called during warm-up before 10 bars accumulated; near the algorithm start date where lookback underflows; a data gap/hole in the minute feed; the futures subscription hadn't received enough bars yet; resolution mismatch (subscribed daily but requesting minute).","solutions":["Ensure the algorithm is warmed up (SetWarmup) so 10 minute bars exist before the scheduled call fires.","Confirm the futures subscription resolution is Minute (or finer) so minute history is available.","Start the scheduled history probe only after enough bars have accumulated (guard on algorithm time / bar count).","Verify no data gaps in the backtest window; if gaps exist, lower the requested bar count or tolerate short windows."],"exampleFix":"// before\nvar history = History(10, Resolution.Minute);\nif (history.Count() < 10) { throw ...; }\n\n// after: skip the check while warming up\nif (IsWarmingUp) return;\nvar history = History(10, Resolution.Minute);\nif (history.Count() < 10) { Log($\"Short history at {Time}: {history.Count()}\"); return; }","handlingStrategy":"validation","validationCode":"private void MakeHistoryCall()\n{\n    if (IsWarmingUp) return;\n    var history = History(10, Resolution.Minute);\n    if (history.Count() < 10)\n    {\n        Log($\"Short history at {Time}: {history.Count()} bars.\");\n        return;\n    }\n    _successCount++;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Warm up the algorithm so 10 minute bars exist before scheduled history calls.","Confirm the futures subscription resolution is Minute or finer.","Start history probes only after enough bars accumulated."],"tags":["futures","history","scheduled-event","data","regression-test","warmup"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}