{"record":{"id":"88020d3c2d3e3217","repo":"QuantConnect/Lean","slug":"future-contracts-did-not-work-up-as-expected-add","errorCode":null,"errorMessage":"Future contracts did not work up as expected: {addedSecurity.Symbol}","messagePattern":"Future contracts did not work up as expected: (.+?)","errorType":"exception","errorClass":"RegressionTestException","httpStatus":null,"severity":"error","filePath":"Algorithm.CSharp/BasicTemplateFuturesAlgorithm.cs","lineNumber":134,"sourceCode":"            if (buyingPowerModel == null)\n            {\n                throw new RegressionTestException($\"Invalid buying power model. Found: {buyingPowerModel.GetType().Name}. Expected: {nameof(FutureMarginModel)}\");\n            }\n            var initialOvernight = futureMarginModel.InitialOvernightMarginRequirement;\n            var maintenanceOvernight = futureMarginModel.MaintenanceOvernightMarginRequirement;\n            var initialIntraday = futureMarginModel.InitialIntradayMarginRequirement;\n            var maintenanceIntraday = futureMarginModel.MaintenanceIntradayMarginRequirement;\n        }\n\n        public override void OnSecuritiesChanged(SecurityChanges changes)\n        {\n            foreach (var addedSecurity in changes.AddedSecurities)\n            {\n                if (addedSecurity.Symbol.SecurityType == SecurityType.Future\n                    && !addedSecurity.Symbol.IsCanonical()\n                    && !addedSecurity.HasData)\n                {\n                    throw new RegressionTestException($\"Future contracts did not work up as expected: {addedSecurity.Symbol}\");\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 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 List<Language> Languages { get; } = new() { Language.CSharp, Language.Python };\n\n        /// <summary>\n        /// Data Points count of all timeslices of algorithm\n        /// </summary>\n        public long DataPoints => 40308;","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.CSharp/BasicTemplateFuturesAlgorithm.cs#L116-L152","documentation":"OnSecuritiesChanged asserts that every non-canonical (real) future contract added by the universe has data (addedSecurity.HasData). If a concrete future contract is added but HasData is false, the universe selected a contract with no data feed — it would be untradeable and indicates a filter or data problem.","triggerScenarios":"OnSecuritiesChanged receives an added security that is SecurityType.Future, not canonical (!IsCanonical()), but addedSecurity.HasData is false — a real contract was selected without any data subscription backing it.","commonSituations":"The future contract filter selected an expiry with no data in the local/remote dataset; data for that contract is missing or not downloaded; the SetFilter range included illiquid/empty contracts; a data feed configuration issue left the security without bars.","solutions":["Tighten the future contract SetFilter to exclude expiries/contracts without data.","Ensure the required futures data for the selected contracts is downloaded/available.","Filter the chain on volume/liquidity or HasData before selecting a contract.","Verify the data feed/subscription configuration so added contracts receive bars."],"exampleFix":"// before\nwhere futuresContract.Expiry > Time.Date.AddDays(90)\n\n// after: also require the contract has data\nwhere futuresContract.Expiry > Time.Date.AddDays(90) && futuresContract.HasData","handlingStrategy":"validation","validationCode":"foreach (var added in changes.AddedSecurities)\n{\n    if (added.Symbol.SecurityType == SecurityType.Future\n        && !added.Symbol.IsCanonical() && !added.HasData)\n    {\n        Log($\"{added.Symbol} added without data; tightening filter.\");\n    }\n}","typeGuard":"bool IsTradeableFutureWith(Security s) => s.Symbol.SecurityType == SecurityType.Future && !s.Symbol.IsCanonical() && s.HasData;","tryCatchPattern":null,"preventionTips":["Tighten the contract SetFilter to exclude dataless expiries.","Filter the chain on HasData/liquidity before selecting.","Ensure required futures data is downloaded."],"tags":["futures","universe-selection","data","regression-test","security-configuration"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}