public async Task <Price[]> GetCurrentCoinPrice() { var response = ""; const string URL = "https://api.coingecko.com/api/v3/simple/price?vs_currencies=nzd&include_last_updated_at=true&ids=bitcoin,ethereum"; try { response = await _httpClient.GetStringAsync(URL); } catch (HttpRequestException e) { Console.WriteLine("\nException Caught!"); Console.WriteLine("Message :{0} ", e.Message); //return empty Price array return(new Price[0]); } Price[] prices = new Price[2]; CurrentPriceResponse currentPrice = JsonConvert.DeserializeObject <CurrentPriceResponse>(response); prices[0] = new Price() { Value = currentPrice.bitcoin.nzd, Date = DateTimeOffset.Now.DateTime, Currency = "Bitcoin" }; prices[1] = new Price() { Value = currentPrice.ethereum.nzd, Date = DateTimeOffset.Now.DateTime, Currency = "Ethereum" }; return(prices); }
public async Task <Price> GetCurrentBtcAndEthereumPrices() { var response = await _httpClient.GetStringAsync("https://api.coingecko.com/api/v3/simple/price?ids=bitcoin%2Cethereum&vs_currencies=nzd"); CurrentPriceResponse currentPrice = JsonConvert.DeserializeObject <CurrentPriceResponse>(response); return(new Price() { BitcoinValue = currentPrice.Bitcoin.RateFloat, EthereumValue = currentPrice.Ethereum.RateFloat, Date = DateTime.UtcNow }); }
public async Task <Price> GetCurrentEthPrice() { //Ethereum API provided by Coinbase var response = await _httpClient.GetStringAsync("https://api.coinbase.com/v2/exchange-rates?currency=ETH"); CurrentPriceResponse currentPrice = JsonConvert.DeserializeObject <CurrentPriceResponse>(response); return(new Price() { Value = currentPrice.Data.Rates.RateFloatNZD, Currency = "Ethereum(ETH)" }); }
public List <CurrentPriceResponse> RemoveUsdt(List <CurrentPriceResponse> response) { var pickles = new List <CurrentPriceResponse>(); foreach (var coin in response) { if (coin.symbol.EndsWith("USDT")) { var tempObject = new CurrentPriceResponse(); tempObject.symbol = coin.symbol.Replace("USDT", ""); tempObject.price = coin.price; pickles.Add(tempObject); } } return(pickles); }