{"record":{"id":"a287837998ea8501","repo":"QuantConnect/Lean","slug":"the-time-zone-of-security-firstcustomsecurity-sh","errorCode":null,"errorMessage":"The time zone of security {firstCustomSecurity} should be {TimeZones.Utc}, but it was {firstCustomSecurity.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":38,"sourceCode":"\nnamespace QuantConnect.Algorithm.CSharp\n{\n    /// <summary>\n    /// Regression algorithm to assert we can have custom data subscriptions with different exchanges\n    /// </summary>\n    public class CustomDataWorksWithDifferentExchangesRegressionAlgorithm : QCAlgorithm, IRegressionAlgorithmDefinition\n    {\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\");","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.CSharp/CustomDataWorksWithDifferentExchangesRegressionAlgorithm.cs#L20-L56","documentation":"Asserts that AddData<T>(symbol, resolution, exchangeTimeZone, fillForward) honored the third argument as the exchange time zone. After registering ExampleCustomData on an FXCM EURUSD symbol with TimeZones.Utc, the Security.Exchange.TimeZone must equal Utc. A mismatch means AddData ignored or overrode the supplied time-zone parameter.","triggerScenarios":"Calling the AddData overload that accepts a DateTimeZone and reading firstCustomSecurity.Exchange.TimeZone immediately; it returns a different zone (often the underlying forex security's zone or NewYork).","commonSituations":"Lean version change that altered the AddData time-zone overload signature or default; a refactor that forces the exchange zone to the market-hours zone; or a custom data type whose BaseData.ExchangeTimezone override wins over the AddData argument.","solutions":["Verify the AddData overload being called is the one taking exchangeTimeZone (not fillForward/leverage), and that you pass TimeZones.Utc in the time-zone slot.","If the custom data type overrides time-zone resolution, ensure it does not clobber the value supplied to AddData.","Check the Lean version changelog for AddData signature changes that shifted parameter positions.","Trace through AddData -> SubscriptionDataConfig creation to confirm config.ExchangeTimeZone is the supplied zone."],"exampleFix":"// before: zone silently defaulted to the forex market zone\nvar s = AddData<ExampleCustomData>(market1.Symbol, Resolution.Hour, false, false);\n\n// after: explicitly pass the exchange time zone in the correct slot\nvar s = AddData<ExampleCustomData>(market1.Symbol, Resolution.Hour, TimeZones.Utc, false);","handlingStrategy":"validation","validationCode":"// Validate the time zone immediately after AddData and fail fast with context\nvar s = AddData<ExampleCustomData>(market1.Symbol, Resolution.Hour, TimeZones.Utc, false);\nif (s.Exchange.TimeZone != TimeZones.Utc)\n    throw new InvalidOperationException($\"AddData ignored exchange time zone; got {s.Exchange.TimeZone}\");","typeGuard":"bool HasExpectedTimeZone(Security s, DateTimeZone expected) => s.Exchange.TimeZone.Equals(expected);","tryCatchPattern":null,"preventionTips":["Always pass the exchange time zone explicitly to AddData and assert it after the call.","Pin your Lean version; AddData overload signatures have shifted across releases.","Do not let a custom data type's time-zone override win over the AddData argument."],"tags":["regression-test","custom-data","time-zone","add-data"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}