public static async Task ForexDemo() { // use your AlphaVantage API key string apiKey = "1"; // there are 5 more constructors available using var client = new AlphaVantageClient(apiKey); using var forexClient = client.Forex(); ForexTimeSeries forexTimeSeries = await forexClient.GetTimeSeriesAsync( PhysicalCurrency.USD, PhysicalCurrency.ILS, Interval.Daily, OutputSize.Compact); ForexExchangeRate forexExchangeRate = await forexClient.GetExchangeRateAsync(PhysicalCurrency.USD, PhysicalCurrency.ILS); }
public async Task ReturnValidExchangeRate() { using var client = new AlphaVantageClient(_apiKey); using var forexClient = client.Forex(); var fromCurrency = PhysicalCurrency.USD; var toCurrency = PhysicalCurrency.ILS; var exchangeRate = await forexClient.GetExchangeRateAsync(fromCurrency, toCurrency); exchangeRate.Should().NotBeNull() .And.Match <ForexExchangeRate>(er => er.FromCurrencyCode == fromCurrency && string.IsNullOrEmpty(er.FromCurrencyName) == false && er.ToCurrencyCode == toCurrency && string.IsNullOrEmpty(er.ToCurrencyName) == false && er.ExchangeRate != default && er.LastRefreshed != default && string.IsNullOrEmpty(er.TimeZone) == false && er.BidPrice != default && er.AskPrice != default ); }
public async Task ReturnValidTimeSeries(Interval interval, OutputSize outputSize) { using var client = new AlphaVantageClient(_apiKey); using var forexClient = client.Forex(); var fromCurrency = PhysicalCurrency.USD; var toCurrency = PhysicalCurrency.ILS; var timeSeries = await forexClient.GetTimeSeriesAsync(fromCurrency, toCurrency, interval, outputSize); timeSeries.Should().NotBeNull() .And.Match <ForexTimeSeries>(ts => ts.Interval == interval && ts.FromCurrency == fromCurrency && ts.ToCurrency == toCurrency); timeSeries.MetaData.Should().NotBeNull() .And.HaveCountGreaterThan(1); timeSeries.DataPoints.Should().NotBeNull() .And.HaveCountGreaterThan(1) .And.NotContainNulls() .And.OnlyContain(dp => IsDataPointValid(dp)); }