Exemplo n.º 1
0
        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>());
            }
        }
Exemplo n.º 2
0
        /* ###############################################################################################
         * Gets the top 100 coins (by marketcap)
         *
         * Arguments: none
         *
         */
        internal async static Task <List <Top100card> > GetTop100()
        {
            int limit    = 100;
            var currency = App.currency;

            var top100 = new List <Top100card>();

            try {
                var resp = await Ioc.Default.GetService <ICryptoCompare>().GetTop100(currency, limit);

                var response = JsonSerializer.Deserialize <object>(resp.ToString());

                var data = ((JsonElement)response).GetProperty("Data");

                for (int i = 0; i < limit; i++)
                {
                    var _coinInfo = data[i].GetProperty("CoinInfo");
                    var coinInfo  = JsonSerializer.Deserialize <CoinInfo>(_coinInfo.ToString());

                    Raw raw       = new Raw();
                    var rawExists = data[i].TryGetProperty("RAW", out var _raw);
                    if (rawExists)
                    {
                        _raw = _raw.GetProperty(currency.ToUpperInvariant());
                        raw  = JsonSerializer.Deserialize <Raw>(_raw.ToString());
                    }

                    /// quick fixes
                    coinInfo.ImageUrl = IconsHelper.GetIcon(coinInfo.Name);
                    coinInfo.FavIcon  = App.pinnedCoins.Contains(coinInfo.Name) ? "\uEB52" : "\uEB51";
                    coinInfo.ChangeFG = (raw.CHANGE24HOUR < 0) ? (SolidColorBrush)App.Current.Resources["pastelRed"] : (SolidColorBrush)App.Current.Resources["pastelGreen"];
                    //coinInfo.MarketCap = NumberHelper.AddUnitPrefix(raw.MKTCAP);
                    //coinInfo.Volume = NumberHelper.AddUnitPrefix(raw.TOTALVOLUME24HTO);
                    //raw.CHANGEPCT24HOUR = Math.Round(raw.CHANGEPCT24HOUR, 2);
                    //raw.CHANGE24HOUR = NumberHelper.Rounder(raw.CHANGE24HOUR);
                    //raw.PRICE = NumberHelper.Rounder(raw.PRICE);

                    top100.Add(new Top100card()
                    {
                        CoinInfo = coinInfo,
                        Raw      = raw
                    });
                }
                top100.Sort((x, y) => y.Raw.MKTCAP.CompareTo(x.Raw.MKTCAP));
                for (int i = 0; i < limit; i++)
                {
                    top100[i].CoinInfo.Rank = i;
                }
                return(top100);
            }
            catch (Exception ex) {
                return(top100);
            }
        }
Exemplo n.º 3
0
        // #########################################################################################
        private async void InitPage()
        {
            g = await App.GetGlobalStats();

            DataContext = g;

            topCoins = await App.GetTop100();

            for (int i = 0; i < topCoins.Count; i++)
            {
                topCoins[i].LogoURL = IconsHelper.GetIcon(topCoins[i].Symbol);
            }

            top100ListView.ItemsSource = topCoins;
        }
Exemplo n.º 4
0
        // #########################################################################################
        private List <SuggestionCoinList> FilterCoins(AutoSuggestBox box)
        {
            var filtered = App.coinList.Where(x => x.Name.Contains(box.Text) || x.FullName.Contains(box.Text)).ToList();
            List <SuggestionCoinList> list = new List <SuggestionCoinList>();

            foreach (JSONcoins coin in filtered)
            {
                list.Add(new SuggestionCoinList {
                    Icon = IconsHelper.GetIcon(coin.Name),
                    Name = coin.Name
                });
            }

            return(list);
        }
Exemplo n.º 5
0
 public SuggestionCoin(Coin coin)
 {
     Icon   = IconsHelper.GetIcon(coin.Name);
     Name   = coin.FullName;
     Symbol = coin.Name;
 }
Exemplo n.º 6
0
 public SuggestionCoin(string name, string fullName)
 {
     Icon   = IconsHelper.GetIcon(name);
     Name   = fullName;
     Symbol = name;
 }