public async Task ForexDownload(string currency) { ExchangeRatesApi exchangeRatesApi = new ExchangeRatesApi(new HttpClient(), this.twelveDataapiKey); DateTime? lastRecordTime = (await this.influxRepo.GetLastWrittenRecordsTime(this.dataSourceIdentification)) .SingleOrDefault(r => string.Compare(r.Currency, currency.ToString(), true) == 0)?.Time; CurrencyData data = await exchangeRatesApi.GetCurrencyHistory(new DateTime(2019, 1, 1), DateTime.Now, currency.ToString()).ConfigureAwait(false); foreach ((string currencySymbol, decimal value, DateTime Date)model in data.PriceOfAnotherCurrencies.Where(p => p.Date > (lastRecordTime ?? DateTime.MinValue))) { await this.SaveDataToInflux(model, data.BaseCurrency).ConfigureAwait(false); } }
public void Setup() { _exchangeRatesApi = new ExchangeRatesApi(new HttpClient(), true); }