From 3fed7cca26afb3fee42be5111f1e7cd6bb9cae67 Mon Sep 17 00:00:00 2001 From: Roman Yavnikov <45608740+Romazes@users.noreply.github.com> Date: Fri, 9 Feb 2024 15:33:51 +0200 Subject: [PATCH] Implement Validation for `SecurityType` Symbol (#5) * feat: condition to validate security type * feat: add flag (SecurityType & DataType) to prevent spamming user * remove: not support SecurityTypes from README --- .../AlphaVantageDataDownloaderTests.cs | 4 +++ .../AlphaVantageDataDownloader.cs | 28 +++++++++++++++++-- README.md | 6 ---- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/QuantConnect.AlphaVantage.Tests/AlphaVantageDataDownloaderTests.cs b/QuantConnect.AlphaVantage.Tests/AlphaVantageDataDownloaderTests.cs index 32e997e..61518fe 100644 --- a/QuantConnect.AlphaVantage.Tests/AlphaVantageDataDownloaderTests.cs +++ b/QuantConnect.AlphaVantage.Tests/AlphaVantageDataDownloaderTests.cs @@ -109,6 +109,10 @@ public static IEnumerable DownloaderInvalidCaseData .SetDescription($"Not supported {nameof(Resolution.Second)} -> throw Exception"); yield return new TestCaseData(symbol, Resolution.Minute, endUtc, startUtc, TickType.Trade, false) .SetDescription("startDateTime > endDateTime -> empty result"); + yield return new TestCaseData(Symbol.Create("USDJPY", SecurityType.Forex, Market.Oanda), Resolution.Minute, startUtc, endUtc, TickType.Trade, false) + .SetDescription($"Not supported {nameof(SecurityType.Forex)} -> empty result"); + yield return new TestCaseData(Symbol.Create("BTCUSD", SecurityType.Crypto, Market.Coinbase), Resolution.Minute, startUtc, endUtc, TickType.Trade, false) + .SetDescription($"Not supported {nameof(SecurityType.Crypto)} -> empty result"); } } diff --git a/QuantConnect.AlphaVantage/AlphaVantageDataDownloader.cs b/QuantConnect.AlphaVantage/AlphaVantageDataDownloader.cs index 383cbad..88fdf53 100644 --- a/QuantConnect.AlphaVantage/AlphaVantageDataDownloader.cs +++ b/QuantConnect.AlphaVantage/AlphaVantageDataDownloader.cs @@ -45,6 +45,16 @@ public class AlphaVantageDataDownloader : IDataDownloader, IDisposable private readonly RateGate _rateGate; private bool _disposed; + /// + /// Indicates whether the warning for invalid history has been fired. + /// + private bool _invalidHistoryDataTypeWarningFired; + + /// + /// Indicates whether the warning for invalid has been fired. + /// + private bool _invalidSecurityTypeWarningFired; + /// /// Represents a mapping of symbols to their corresponding time zones for exchange information. /// @@ -120,8 +130,22 @@ public IEnumerable Get(DataDownloaderGetParameters dataDownloaderGetPa if (tickType != TickType.Trade) { - Log.Error($"{nameof(AlphaVantageDataDownloader)}.{nameof(Get)}: Not supported data type - {tickType}. " + - $"Currently available support only for historical of type - TradeBar"); + if (!_invalidHistoryDataTypeWarningFired) + { + Log.Error($"{nameof(AlphaVantageDataDownloader)}.{nameof(Get)}: Not supported data type - {tickType}. " + + $"Currently available support only for historical of type - TradeBar"); + _invalidHistoryDataTypeWarningFired = true; + } + return Enumerable.Empty(); + } + + if (symbol.SecurityType != SecurityType.Equity) + { + if (!_invalidSecurityTypeWarningFired) + { + Log.Trace($"{nameof(AlphaVantageDataDownloader)}.{nameof(Get)}: Unsupported SecurityType '{symbol.SecurityType}' for symbol '{symbol}'"); + _invalidSecurityTypeWarningFired = true; + } return Enumerable.Empty(); } diff --git a/README.md b/README.md index 2f9622b..3935ad3 100644 --- a/README.md +++ b/README.md @@ -20,12 +20,6 @@ Alpha Vantage provides real-time and historical financial market data through a - **Symbol SecurityType Support:** The library currently supports the following symbol security types: - [x] Equity - - [ ] Option - - [ ] Commodity - - [ ] Forex - - [ ] Future - - [ ] Crypto - - [ ] Index - **Backtesting and Research:** Test your algorithm in backtest and research modes within [QuantConnect.Lean CLI](https://www.quantconnect.com/docs/v2/lean-cli), leveraging the Alpha Vantage API data to refine and optimize your trading strategies.