{"record":{"id":"a8a1299cdfa3aaca","repo":"QuantConnect/Lean","slug":"the-time-zone-of-security-secondcustomsecurity-s","errorCode":null,"errorMessage":"The time zone of security {secondCustomSecurity} should be {TimeZones.Utc}, but it was {secondCustomSecurity.Exchange.TimeZone}","messagePattern":"The time zone of security (.+?) should be (.+?), but it was (.+?)","errorType":"exception","errorClass":"RegressionTestException","httpStatus":null,"severity":"error","filePath":"Algorithm.CSharp/CustomDataWorksWithDifferentExchangesRegressionAlgorithm.cs","lineNumber":45,"sourceCode":"    {\n        private bool _noDataPointsReceived;\n        public override void Initialize()\n        {\n            SetStartDate(2014, 05, 02);\n            SetEndDate(2014, 05, 03);\n\n            var market1 = AddForex(\"EURUSD\", Resolution.Hour, Market.FXCM);\n            var firstCustomSecurity = AddData<ExampleCustomData>(market1.Symbol, Resolution.Hour, TimeZones.Utc, false);\n            if (firstCustomSecurity.Exchange.TimeZone != TimeZones.Utc)\n            {\n                throw new RegressionTestException($\"The time zone of security {firstCustomSecurity} should be {TimeZones.Utc}, but it was {firstCustomSecurity.Exchange.TimeZone}\");\n            }\n\n            var market2 = AddForex(\"EURUSD\", Resolution.Hour, Market.Oanda);\n            var secondCustomSecurity = AddData<ExampleCustomData>(market2.Symbol, Resolution.Hour, TimeZones.Utc, false);\n            if (secondCustomSecurity.Exchange.TimeZone != TimeZones.Utc)\n            {\n                throw new RegressionTestException($\"The time zone of security {secondCustomSecurity} should be {TimeZones.Utc}, but it was {secondCustomSecurity.Exchange.TimeZone}\");\n            }\n            _noDataPointsReceived = true;\n        }\n\n\n        public override void OnData(Slice slice)\n        {\n            _noDataPointsReceived = false;\n            if (slice.Count != ActiveSecurities.Count)\n            {\n                throw new RegressionTestException($\"{ActiveSecurities.Count.ToString().ToCamelCase()} data points were expected, but only {slice.Count} were received\");\n            }\n        }\n\n        public override void OnEndOfAlgorithm()\n        {\n            if (_noDataPointsReceived)\n            {","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.CSharp/CustomDataWorksWithDifferentExchangesRegressionAlgorithm.cs#L27-L63","documentation":"Same integrity check as the first security, applied to the second custom-data security built on an Oanda EURUSD symbol. After AddData<ExampleCustomData>(market2.Symbol, Resolution.Hour, TimeZones.Utc, false), secondCustomSecurity.Exchange.TimeZone must be Utc. The test deliberately registers the same custom type on two different market variants to ensure each keeps its own supplied zone.","triggerScenarios":"Registering custom data on a second market (Oanda) of an already-added symbol and reading Exchange.TimeZone; it inherits the first security's zone or the market default instead of Utc.","commonSituations":"Symbol/Security sharing logic that caches one exchange-zone per underlying ticker; AddData not isolating config per market; or a refactor that merged configs across markets.","solutions":["Ensure each AddData call builds an independent SubscriptionDataConfig with its own ExchangeTimeZone rather than reusing the first security's config.","Confirm the Oanda forex symbol is treated as distinct from the FXCM one (different SID/market) so its custom data config is independent.","Inspect SubscriptionManager to confirm no dedup collapses the two custom-data securities into one.","Re-run with logging on config creation to verify both zones are stored as Utc."],"exampleFix":"// before: second AddData reuses first security's config/zone\nvar secondCustomSecurity = AddData<ExampleCustomData>(market2.Symbol, Resolution.Hour, false, false);\n\n// after: independent config with its own Utc zone\nvar secondCustomSecurity = AddData<ExampleCustomData>(market2.Symbol, Resolution.Hour, TimeZones.Utc, false);","handlingStrategy":"validation","validationCode":"var s2 = AddData<ExampleCustomData>(market2.Symbol, Resolution.Hour, TimeZones.Utc, false);\nif (s2.Exchange.TimeZone != TimeZones.Utc)\n    throw new InvalidOperationException($\"Second security zone mismatch: {s2.Exchange.TimeZone}\");","typeGuard":"bool ConfigsAreIndependent(Security a, Security b) => !ReferenceEquals(a.Subscriptions.First(), b.Subscriptions.First());","tryCatchPattern":null,"preventionTips":["Treat each AddData call as independent; assert each security keeps its supplied zone.","When adding the same custom type across markets, verify SubscriptionDataConfigs are not deduplicated.","Log config.ExchangeTimeZone at registration to catch silent reuse."],"tags":["regression-test","custom-data","time-zone","multi-market"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}