Skip to content

Commit

Permalink
remove: duplicate validation from downloader
Browse files Browse the repository at this point in the history
  • Loading branch information
Romazes committed Feb 26, 2024
1 parent 4c2f7fa commit 69e8e20
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 26 deletions.
31 changes: 5 additions & 26 deletions QuantConnect.CoinAPI/CoinAPIDataDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,10 @@ public CoinAPIDataDownloader()

public IEnumerable<BaseData>? Get(DataDownloaderGetParameters dataDownloaderGetParameters)
{
if (dataDownloaderGetParameters.TickType != TickType.Trade)
{
Log.Error($"{nameof(CoinAPIDataDownloader)}.{nameof(Get)}: Not supported data type - {dataDownloaderGetParameters.TickType}. " +
$"Currently available support only for historical of type - {nameof(TickType.Trade)}");
return null;
}

if (dataDownloaderGetParameters.EndUtc < dataDownloaderGetParameters.StartUtc)
{
Log.Error($"{nameof(CoinAPIDataDownloader)}.{nameof(Get)}:InvalidDateRange. The history request start date must precede the end date, no history returned");
return null;
}

var symbol = dataDownloaderGetParameters.Symbol;

var historyRequests = new HistoryRequest(
var history = _historyProvider.GetHistory(
new HistoryRequest(
startTimeUtc: dataDownloaderGetParameters.StartUtc,
endTimeUtc: dataDownloaderGetParameters.EndUtc,
dataType: typeof(TradeBar),
Expand All @@ -62,25 +50,16 @@ public CoinAPIDataDownloader()
includeExtendedMarketHours: true,
isCustomData: false,
dataNormalizationMode: DataNormalizationMode.Raw,
tickType: TickType.Trade);

var history = _historyProvider.GetHistory(historyRequests);
tickType: TickType.Trade)
);

// historyRequest contains wrong data request
if (history == null)
{
return null;
}

return GetHistoryInSlice(history);
}

private IEnumerable<BaseData> GetHistoryInSlice(IEnumerable<BaseData> history)
{
foreach (var slice in history)
{
yield return slice;
}
return history.Select(slice => slice);
}

public void Dispose()
Expand Down
14 changes: 14 additions & 0 deletions QuantConnect.CoinAPI/CoinApiDataHistoryProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public partial class CoinApiDataProvider
/// </summary>
private bool _invalidResolutionTypeWarningFired;

/// <summary>
/// Indicates whether a warning for an invalid start time has been fired, where the start time is greater than or equal to the end time in UTC.
/// </summary>
private bool _invalidStartTimeWarningFired;

public override void Initialize(HistoryProviderInitializeParameters parameters)
{
Expand Down Expand Up @@ -108,6 +112,16 @@ public override void Initialize(HistoryProviderInitializeParameters parameters)
return null;
}

if (historyRequest.EndTimeUtc < historyRequest.StartTimeUtc)
{
if (!_invalidStartTimeWarningFired)
{
Log.Error($"{nameof(CoinAPIDataDownloader)}.{nameof(GetHistory)}:InvalidDateRange. The history request start date must precede the end date, no history returned");
_invalidStartTimeWarningFired = true;
}
return null;
}

return GetHistory(historyRequest.Symbol,
historyRequest.Resolution,
historyRequest.StartTimeUtc,
Expand Down

0 comments on commit 69e8e20

Please sign in to comment.