public async Task <List <Currency> > UpdateCurrencies() { // Start watch var stopwatch = new Stopwatch(); stopwatch.Start(); // Get all currencies from CoinMarketCap var result = await _coinpaprikaClient.GetTickersAsync(); var tickers = result.Value.Where(x => x.Id == "btc-bitcoin" || x.Id == "xrp-xrp" || x.Id == "eth-ethereum" || x.Id == "bch-bitcoin-cash" || x.Id == "xlm-stellar" || x.Id == "eos-eos" || x.Id == "ada-cardano").ToList(); // Build currencies var newCurrencies = _mapper.Map <List <Currency> >(tickers); // Get all currencies var currencies = await _mainDbContext.Currencies.ToListAsync(); // Update _mainDbContext.UpdateCollection(currencies, newCurrencies); // Save await _mainDbContext.SaveChangesAsync(); // Stop watch stopwatch.Stop(); // Log into Splunk _logger.LogSplunkInformation("UpdateCurrencies", new { newCurrencies.Count, ExecutionTime = stopwatch.Elapsed.TotalSeconds }); // Return return(newCurrencies); }
static async Task TestTickerAllAsync() { Console.WriteLine("fetching ticker..."); var ticker = await _client.GetTickersAsync(new[] { "USD", "BTC" }); if (ticker.Error == null) { Console.WriteLine("CoinPaprika Tickers: "); foreach (var t in ticker.Value.OrderBy(c => c.Rank)) { Console.WriteLine($"{t.Name}({t.Id}({t.Symbol})) - {t.Rank} - BTC:{t.Quotes["BTC"].Price}/USD:{t.Quotes["USD"].Price} - PercentChange24h:{t.Quotes["BTC"].PercentChange24H}%(BTC)/{t.Quotes["USD"].PercentChange24H}%(USD)"); } Console.WriteLine("Press any key to finish test..."); Console.ReadLine(); Console.WriteLine("Bye!"); } }
public async Task <List <Currency> > ImportCurrencies() { // Start watch var stopwatch = new Stopwatch(); stopwatch.Start(); // Get all currencies from CoinMarketCap var result = await _coinpaprikaClient.GetTickersAsync(); var tickers = result.Value.Where(x => x.Symbol == "BTC" || x.Symbol == "XRP" || x.Symbol == "ETH" || x.Symbol == "BCH" || x.Symbol == "XML" || x.Symbol == "EOS" || x.Symbol == "ADA").GroupBy(x => x.Symbol).Select(x => x.First()).ToList(); // Build currencies var newCurrencies = _mapper.Map <List <Currency> >(tickers); // Get all currencies var currencies = await _mainDbContext.Currencies.ToListAsync(); // Update _mainDbContext.UpdateCollection(currencies, newCurrencies); // Save await _mainDbContext.SaveChangesAsync(); // Stop watch stopwatch.Stop(); // Log _logger.LogInformation("{@Event}, {@Count}, {@ExecutionTime}", "CurrenciesImported", newCurrencies.Count, stopwatch.Elapsed.TotalSeconds); // Return return(newCurrencies); }