From 111fbfa2cac54bf31ff71bb1c28f85b8dc46a51b Mon Sep 17 00:00:00 2001 From: Josue Nina Date: Tue, 3 Feb 2026 13:28:38 -0500 Subject: [PATCH 1/3] Add test for tick history consistency --- Tests/Algorithm/AlgorithmHistoryTests.cs | 41 ++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/Tests/Algorithm/AlgorithmHistoryTests.cs b/Tests/Algorithm/AlgorithmHistoryTests.cs index 72e9fac5ec4d..2922b5baf734 100644 --- a/Tests/Algorithm/AlgorithmHistoryTests.cs +++ b/Tests/Algorithm/AlgorithmHistoryTests.cs @@ -3975,9 +3975,9 @@ public void HistoryRequestUsesSecurityConfigOrExplicitValues(bool explicitParame var start = new DateTime(2013, 10, 28); var algorithm = GetAlgorithm(start); var future = algorithm.AddFuture( - Futures.Indices.SP500EMini, - dataNormalizationMode: DataNormalizationMode.BackwardsRatio, - dataMappingMode: DataMappingMode.LastTradingDay, + Futures.Indices.SP500EMini, + dataNormalizationMode: DataNormalizationMode.BackwardsRatio, + dataMappingMode: DataMappingMode.LastTradingDay, contractDepthOffset: 0, extendedMarketHours: true); @@ -4040,6 +4040,41 @@ public void HistoryRequestUsesSecurityConfigOrExplicitValues(bool explicitParame } } + [Test] + public void TickHistoryRequestsForFuturesShouldReturnSameDataCount() + { + var start = new DateTime(2013, 10, 09); + _algorithm = GetAlgorithm(start); + _algorithm.SetEndDate(2013, 10, 10); + + + var symbol = Symbol.CreateFuture(Futures.Metals.Gold, Market.COMEX, new DateTime(2013, 10, 29)); + _algorithm.AddFutureContract(symbol, Resolution.Tick); + + var startDate = new DateTime(2013, 10, 08, 9, 30, 0); + var endDate = startDate.AddHours(1); + + var history1 = _algorithm.History(symbol, startDate, endDate, Resolution.Tick).ToList(); + var history1Count = history1.Count; + int history2Count = 0; + int history3Count = 0; + using (Py.GIL()) + { + _algorithm.SetPandasConverter(); + var type = typeof(Tick).ToPython(); + + dynamic history2 = _algorithm.History(symbol.ToPython(), startDate, endDate, Resolution.Tick); + history2Count = history2.shape[0].As(); + + dynamic history3 = _algorithm.History(type, symbol.ToPython(), startDate, endDate, Resolution.Tick); + history3Count = history3.shape[0].As(); + } + + Assert.Greater(history1Count, 0); + Assert.AreEqual(history1Count, history2Count); + Assert.AreEqual(history1Count, history3Count); + } + private class CustomTestHistoryProvider : SubscriptionDataReaderHistoryProvider { public List HistoryRequests { get; } = new List(); From 184e1f863d587984c6a67eba9be50ce120d4f464 Mon Sep 17 00:00:00 2001 From: Josue Nina Date: Tue, 3 Feb 2026 15:13:57 -0500 Subject: [PATCH 2/3] Add test cases --- Tests/Algorithm/AlgorithmHistoryTests.cs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Tests/Algorithm/AlgorithmHistoryTests.cs b/Tests/Algorithm/AlgorithmHistoryTests.cs index 2922b5baf734..16703f370f74 100644 --- a/Tests/Algorithm/AlgorithmHistoryTests.cs +++ b/Tests/Algorithm/AlgorithmHistoryTests.cs @@ -4040,16 +4040,27 @@ public void HistoryRequestUsesSecurityConfigOrExplicitValues(bool explicitParame } } - [Test] - public void TickHistoryRequestsForFuturesShouldReturnSameDataCount() + [TestCase(Resolution.Tick)] + [TestCase(Resolution.Second)] + [TestCase(Resolution.Minute)] + [TestCase(Resolution.Hour)] + [TestCase(Resolution.Daily)] + [TestCase(null)] + public void TickHistoryRequestsForFuturesShouldReturnSameDataCount(Resolution? resolution) { var start = new DateTime(2013, 10, 09); _algorithm = GetAlgorithm(start); _algorithm.SetEndDate(2013, 10, 10); - var symbol = Symbol.CreateFuture(Futures.Metals.Gold, Market.COMEX, new DateTime(2013, 10, 29)); - _algorithm.AddFutureContract(symbol, Resolution.Tick); + if (resolution == null) + { + _algorithm.AddFutureContract(symbol); + } + else + { + _algorithm.AddFutureContract(symbol, resolution); + } var startDate = new DateTime(2013, 10, 08, 9, 30, 0); var endDate = startDate.AddHours(1); From 7ca05a813898215a8695a704e2b252839f66f8d8 Mon Sep 17 00:00:00 2001 From: Josue Nina Date: Tue, 3 Feb 2026 16:29:50 -0500 Subject: [PATCH 3/3] Minor fix --- Tests/Algorithm/AlgorithmHistoryTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/Algorithm/AlgorithmHistoryTests.cs b/Tests/Algorithm/AlgorithmHistoryTests.cs index 16703f370f74..e6c615377946 100644 --- a/Tests/Algorithm/AlgorithmHistoryTests.cs +++ b/Tests/Algorithm/AlgorithmHistoryTests.cs @@ -4063,7 +4063,7 @@ public void TickHistoryRequestsForFuturesShouldReturnSameDataCount(Resolution? r } var startDate = new DateTime(2013, 10, 08, 9, 30, 0); - var endDate = startDate.AddHours(1); + var endDate = startDate.AddMinutes(10); var history1 = _algorithm.History(symbol, startDate, endDate, Resolution.Tick).ToList(); var history1Count = history1.Count; @@ -4081,7 +4081,7 @@ public void TickHistoryRequestsForFuturesShouldReturnSameDataCount(Resolution? r history3Count = history3.shape[0].As(); } - Assert.Greater(history1Count, 0); + Assert.AreEqual(4923, history1Count); Assert.AreEqual(history1Count, history2Count); Assert.AreEqual(history1Count, history3Count); }