{"record":{"id":"3522b243f7f8f972","repo":"QuantConnect/Lean","slug":"future-contracts-did-not-work-up-as-expected-add-3522b2","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/BasicTemplateFuturesWithExtendedMarketAlgorithm.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 => 117079;","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.CSharp/BasicTemplateFuturesWithExtendedMarketAlgorithm.cs#L116-L152","documentation":"Same invariant as BasicTemplateFuturesAlgorithm: OnSecuritiesChanged asserts every non-canonical future contract added by the universe has data (HasData). A concrete contract added without data is untradeable and signals a filter or data-feed problem in the extended-market configuration.","triggerScenarios":"OnSecuritiesChanged receives an added security that is SecurityType.Future, non-canonical, but HasData == false in the extended-market algorithm — a real contract was selected without a backing data subscription.","commonSituations":"The contract filter selected an expiry with no data; extended-hours data for the contract is missing; the SetFilter range included empty/illiquid contracts; the data feed was not configured for the selected contract.","solutions":["Tighten the future contract SetFilter to contracts with data.","Ensure extended-hours futures data for selected contracts is downloaded.","Filter the chain on HasData/liquidity before selecting.","Verify the subscription/data-feed configuration covers added contracts."],"exampleFix":"// before\nwhere futuresContract.Expiry > Time.Date.AddDays(90)\n\n// after\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; tighten 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 contracts.","Ensure extended-hours futures data for selected contracts is present.","Filter the chain on HasData before selecting."],"tags":["futures","universe-selection","data","regression-test","extended-market","security-configuration"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}