Files
quantconnect--lean/Common/Data/DownloaderExtensions.cs
T
Roman Yavnikov 7e568bf4ac
API Tests / build (push) Has been cancelled
Benchmarks / build (push) Has been cancelled
Build & Test Lean / build (push) Has been cancelled
Regression Tests / build (push) Has been cancelled
Report Generator Tests / build (push) Has been cancelled
Research Regression Tests / build (push) Has been cancelled
Python Virtual Environments / build (push) Has been cancelled
Feature: find different Ticker data download parameters (#7845)
* refactor: map files in lean/data folder

* feat: Indexers in MapFile

* feat: extension for mapFile and downloader param

* refactor: getAllTickers from MapFiles

* feat: addition out variable in TryParsePath
fix: tests with new variable

* refactor: DownloadDataProvider with getting all ticker with different DateTime Ranges
feat: test

* revert: "refactor: map files in lean/data folder"

This reverts commit 41fa26eb8627446028d4f2d4c536511ea82a9a48.

* revert: "feat: addition out variable in TryParsePath"
refactor: some actual changing

This reverts commit 9de482bd6490eecd1eeee83e035dfc1ece8d6415.

* revert: "feat: Indexers in MapFile"
fix: actual changes

This reverts commit 393181c6316a354a8cdcbfb093707cb545383a8a.

* remove: high performance Any validation
feat: validation on ticker start with specific sign
fix: option test

* feat: validation on mapping
refactor: when resolution less hour
test: new test cases + validation of SecurityType

* refactor: add additional day when return date range from MapFile
fix: FirstTicker instead of Permtick when generate new Equity
feat: validation of request Date in DownloaderDataProvider
refactor: by style proj DownloaderDataProvider
test:fix: starting Date in TestCases

* remove: duplicate code

* fix: check of income data.Time with requested Start/End-Date

* test:fix: download test cuz we can not get/write future data

* remove:  extra Symbol Create mthd

* test:feat: validate of TryParse returns correct symbol

* remove: excess if condition

* test:remove: extra chaning
connected # 3a62adf54c42b01d28ff410e93e1ce277ee6d534

* refactor: split big method to small ones (add readability)

* fix: typo in xml description

* refactor: get the correct symbol value

* refactor: use local time instead of Utc in download Param extension
refactor: use struct instead of class

* test:fix: convert time to Utc from local time
2024-03-18 14:43:11 -03:00

82 lines
3.9 KiB
C#

/*
* QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
* Lean Algorithmic Trading Engine v2.0. Copyright 2014 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.
*/
using System;
using QuantConnect.Interfaces;
using System.Collections.Generic;
using QuantConnect.Data.Auxiliary;
using NodaTime;
namespace QuantConnect.Data
{
/// <summary>
/// Contains extension methods for the Downloader functionality.
/// </summary>
public static class DownloaderExtensions
{
/// <summary>
/// Get <see cref="DataDownloaderGetParameters"/> for all mapped <seealso cref="Symbol"/> with appropriate ticker name in specific date time range.
/// </summary>
/// <param name="dataDownloaderParameter">Generated class in "Lean.Engine.DataFeeds.DownloaderDataProvider"</param>
/// <param name="mapFileProvider">Provides instances of <see cref="MapFileResolver"/> at run time</param>
/// <param name="exchangeTimeZone">Provides the time zone this exchange</param>
/// <returns>
/// Return DataDownloaderGetParameters with different
/// <see cref="DataDownloaderGetParameters.StartUtc"/> - <seealso cref="DataDownloaderGetParameters.EndUtc"/> range
/// and <seealso cref="Symbol"/>
/// </returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="dataDownloaderParameter"/> is null.</exception>
public static IEnumerable<DataDownloaderGetParameters> GetDataDownloaderParameterForAllMappedSymbols(
this DataDownloaderGetParameters dataDownloaderParameter,
IMapFileProvider mapFileProvider,
DateTimeZone exchangeTimeZone)
{
if (dataDownloaderParameter == null)
{
throw new ArgumentNullException(nameof(dataDownloaderParameter));
}
if (dataDownloaderParameter.Symbol.SecurityType != SecurityType.Future
&& dataDownloaderParameter.Symbol.RequiresMapping()
&& dataDownloaderParameter.Resolution >= Resolution.Hour)
{
var yieldMappedSymbol = default(bool);
foreach (var symbolDateRange in mapFileProvider.RetrieveAllMappedSymbolInDateRange(dataDownloaderParameter.Symbol))
{
var endDateTimeUtc = symbolDateRange.EndDateTimeLocal.ConvertToUtc(exchangeTimeZone);
// The first start date returns from mapFile like IPO (DateTime) and can not be greater then request StartTime
// The Downloader doesn't know start DateTime exactly, it always download all data
var startDateTime = symbolDateRange.StartDateTimeLocal.ConvertToUtc(exchangeTimeZone);
var endDateTime = endDateTimeUtc > dataDownloaderParameter.EndUtc ? dataDownloaderParameter.EndUtc : endDateTimeUtc;
yield return new DataDownloaderGetParameters(
symbolDateRange.Symbol, dataDownloaderParameter.Resolution, startDateTime, endDateTime, dataDownloaderParameter.TickType);
yieldMappedSymbol = true;
}
if (!yieldMappedSymbol)
{
yield return dataDownloaderParameter;
}
}
else
{
yield return dataDownloaderParameter;
}
}
}
}