public static async Task <List <CoinMarket> > GetCoinsMarkets_(this ICoinGecko service, string currency = "") { if (currency == "") { currency = Ioc.Default.GetService <LocalSettings>().Get <string>(UserSettings.Currency); } var currencySym = Currencies.GetCurrencySymbol(currency); try { var response = await service.GetCoinsMarkets(currency); var pinnedCoins = Ioc.Default.GetService <LocalSettings>().Get <string>(UserSettings.PinnedCoins); var pinned = pinnedCoins.Split("|").ToList(); var data = JsonSerializer.Deserialize <List <CoinMarket> >(response.ToString()); foreach (var d in data) { var z = ((JsonElement)d.sparkline_in_7d).GetProperty("price"); d.sparkline_7d = JsonSerializer.Deserialize <List <double> >(z.ToString()); var img = IconsHelper.GetIcon(d.symbol.ToUpperInvariant()); d.image = img.StartsWith("/Assets") ? img : d.image; d.IsFav = pinned.Contains(d.symbol.ToUpperInvariant()); d.currencySymbol = currencySym; } return(data); } catch (Exception ex) { return(new List <CoinMarket>()); } }
public static async Task <List <CoinGeckoCoin> > GetCoinList_(this ICoinGecko service) { try { var response = await service.GetCoinList(); return(JsonSerializer.Deserialize <List <CoinGeckoCoin> >(response.ToString())); } catch (Exception ex) { return(new List <CoinGeckoCoin>()); } }
public static async Task <int> GetPrice_(this ICoinGecko service, string cryptos, string currency = "") { if (currency == "") { currency = Ioc.Default.GetService <LocalSettings>().Get <string>(UserSettings.Currency); } var currencySym = Currencies.GetCurrencySymbol(currency); try { var response = await service.GetPrice(cryptos, currency); return(3); } catch (Exception ex) { return(0); } }