Skip to content

Commit

Permalink
Implement Validation for SecurityType Symbol (#5)
Browse files Browse the repository at this point in the history
* feat: condition to validate security type

* feat: add flag (SecurityType & DataType) to prevent spamming user

* remove: not support SecurityTypes from README
  • Loading branch information
Romazes committed Feb 9, 2024
1 parent 65b1906 commit 3fed7cc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ public static IEnumerable<TestCaseData> 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");
}
}

Expand Down
28 changes: 26 additions & 2 deletions QuantConnect.AlphaVantage/AlphaVantageDataDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ public class AlphaVantageDataDownloader : IDataDownloader, IDisposable
private readonly RateGate _rateGate;
private bool _disposed;

/// <summary>
/// Indicates whether the warning for invalid history <see cref="TickType"/> has been fired.
/// </summary>
private bool _invalidHistoryDataTypeWarningFired;

/// <summary>
/// Indicates whether the warning for invalid <see cref="SecurityType"/> has been fired.
/// </summary>
private bool _invalidSecurityTypeWarningFired;

/// <summary>
/// Represents a mapping of symbols to their corresponding time zones for exchange information.
/// </summary>
Expand Down Expand Up @@ -120,8 +130,22 @@ public IEnumerable<BaseData> 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<BaseData>();
}

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<BaseData>();
}

Expand Down
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit 3fed7cc

Please sign in to comment.