From 153c5b5f6deba9b638a9a228ffcd1808b8ed2e8b Mon Sep 17 00:00:00 2001 From: Romazes Date: Fri, 30 Jan 2026 20:25:39 +0200 Subject: [PATCH 1/2] feat: add MappedSynchronizingHistoryProvider base class Introduces an abstract class for history providers that handle symbol mapping and time-aligned data slices. Uses IMapFileProvider to resolve ticker changes, provides an abstract method for mapped history retrieval, and overrides GetHistory to synchronize results. Enables nullable reference types and adds documentation. --- .../MappedSynchronizingHistoryProvider.cs | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 Engine/HistoricalData/MappedSynchronizingHistoryProvider.cs diff --git a/Engine/HistoricalData/MappedSynchronizingHistoryProvider.cs b/Engine/HistoricalData/MappedSynchronizingHistoryProvider.cs new file mode 100644 index 000000000000..46af61a6cd5b --- /dev/null +++ b/Engine/HistoricalData/MappedSynchronizingHistoryProvider.cs @@ -0,0 +1,80 @@ +/* + * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals. + * Lean Algorithmic Trading Engine v2.0. Copyright 2026 QuantConnect Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +#nullable enable + +using NodaTime; +using System.Linq; +using QuantConnect.Data; +using QuantConnect.Util; +using QuantConnect.Interfaces; +using System.Collections.Generic; +using QuantConnect.Lean.Engine.DataFeeds; + +namespace QuantConnect.Lean.Engine.HistoricalData +{ + /// + /// Base class for history providers that resolve symbol mappings + /// and synchronize multiple data streams into time-aligned slices. + /// + public abstract class MappedSynchronizingHistoryProvider : SynchronizingHistoryProvider + { + /// + /// Resolves map files to correctly handle current and historical ticker symbols. + /// + private readonly IMapFileProvider _mapFileProvider = Composer.Instance.GetPart(); + + /// + /// Gets historical data for a single resolved history request. + /// Implementations should assume the symbol is already correctly mapped. + /// + /// The resolved history request. + /// The historical data. + public abstract IEnumerable? GetHistory(HistoryRequest request); + + /// + /// Gets the history for the requested securities + /// + /// The historical data requests + /// The time zone used when time stamping the slice instances + /// An enumerable of the slices of data covering the span specified in each request + public override IEnumerable? GetHistory(IEnumerable requests, DateTimeZone sliceTimeZone) + { + var subscriptions = new List(); + foreach (var request in requests) + { + var history = request + .SplitHistoryRequestWithUpdatedMappedSymbol(_mapFileProvider) + .SelectMany(x => GetHistory(x) ?? []); + var subscription = CreateSubscription(request, history); + if (!subscription.MoveNext()) + { + continue; + } + + subscriptions.Add(subscription); + subscription = null; + } + + if (subscriptions.Count == 0) + { + return null; + } + + // Ownership of subscription is transferred to CreateSliceEnumerableFromSubscriptions + return CreateSliceEnumerableFromSubscriptions(subscriptions, sliceTimeZone); + } + } +} From 0267cf5683ff6d8be9c037ff3fdba1de5df7ae1e Mon Sep 17 00:00:00 2001 From: Martin Molinero Date: Fri, 30 Jan 2026 16:54:19 -0300 Subject: [PATCH 2/2] Minor tweaks --- .../HistoricalData/MappedSynchronizingHistoryProvider.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Engine/HistoricalData/MappedSynchronizingHistoryProvider.cs b/Engine/HistoricalData/MappedSynchronizingHistoryProvider.cs index 46af61a6cd5b..d0339a8e38f5 100644 --- a/Engine/HistoricalData/MappedSynchronizingHistoryProvider.cs +++ b/Engine/HistoricalData/MappedSynchronizingHistoryProvider.cs @@ -13,8 +13,7 @@ * limitations under the License. */ -#nullable enable - +using System; using NodaTime; using System.Linq; using QuantConnect.Data; @@ -34,7 +33,7 @@ public abstract class MappedSynchronizingHistoryProvider : SynchronizingHistoryP /// /// Resolves map files to correctly handle current and historical ticker symbols. /// - private readonly IMapFileProvider _mapFileProvider = Composer.Instance.GetPart(); + private static readonly Lazy _mapFileProvider = new(Composer.Instance.GetPart); /// /// Gets historical data for a single resolved history request. @@ -56,7 +55,7 @@ public abstract class MappedSynchronizingHistoryProvider : SynchronizingHistoryP foreach (var request in requests) { var history = request - .SplitHistoryRequestWithUpdatedMappedSymbol(_mapFileProvider) + .SplitHistoryRequestWithUpdatedMappedSymbol(_mapFileProvider.Value) .SelectMany(x => GetHistory(x) ?? []); var subscription = CreateSubscription(request, history); if (!subscription.MoveNext()) @@ -65,7 +64,6 @@ public abstract class MappedSynchronizingHistoryProvider : SynchronizingHistoryP } subscriptions.Add(subscription); - subscription = null; } if (subscriptions.Count == 0)