Beispiel #1
0
        public async Task <Top10RootObject> GetTop10Details()
        {
            HttpClient httpClient     = new HttpClient();
            string     apiUrl         = $"https://api.coinmarketcap.com/v2/ticker/?limit=25";
            string     responseString = await httpClient.GetStringAsync(apiUrl);

            Top10RootObject details = JsonConvert.DeserializeObject <Top10RootObject>(responseString);

            return(details);
        }
        private async Task GetInfo()
        {
            Top10CoinsDetailsRetriever details   = new Top10CoinsDetailsRetriever();
            Top10RootObject            Top10Root = await details.GetTop10Details();

            GlobalDetailsRetriever GlobalDetails = new GlobalDetailsRetriever();

            GlobalData.GlobalDataRootObject GlobalDataRoot = await GlobalDetails.GetGlobalDataDetails();

            Global_Data_viewmodels.Active_Cryptocurrencies          = GlobalDataRoot.data.active_cryptocurrencies;
            Global_Data_viewmodels.Active_Markets                   = GlobalDataRoot.data.active_markets;
            Global_Data_viewmodels.Bitcoin_Percentage_Of_Market_Cap = GlobalDataRoot.data.bitcoin_percentage_of_market_cap;
            Global_Data_viewmodels.Total_Market_Cap                 = GlobalDataRoot.data.quotes.USD.total_market_cap;
            Global_Data_viewmodels.Total_Volume_24h                 = GlobalDataRoot.data.quotes.USD.total_volume_24h;

            foreach (var v in Top10Root.data)
            {
                TopTenViewModel temp = new TopTenViewModel();
                temp.Coin_Name               = v.Value.name;
                temp.Coin_Rank               = v.Value.rank;
                temp.Coin_Ticker_Tape        = v.Value.symbol;
                temp.Coin_Price_USD          = v.Value.quotes.USD.price;
                temp.Coin_24_Hour_Change     = v.Value.quotes.USD.percent_change_24h;
                temp.Coin_24_Hour_Volume     = v.Value.quotes.USD.volume_24h;
                temp.Coin_Circulating_Supply = v.Value.total_supply;
                temp.Coin_Market_Cap         = v.Value.quotes.USD.market_cap;
                temp.Coin_Picture            = "ms-appx:///Assets/CryptoSVG/PNG/" + temp.Coin_Ticker_Tape + ".png";

                temp.Coin_CMC_String            = " $" + String.Format("{0:#,##0.##}", temp.Coin_Market_Cap);
                temp.Coin_Circ_String           = " " + String.Format("{0:#,##0.##}", temp.Coin_Circulating_Supply);
                temp.Coin_Volume_String         = " $" + String.Format("{0:#,##0.##}", temp.Coin_24_Hour_Volume);
                temp.Coin_24_Hour_Change_String = " " + temp.Coin_24_Hour_Change + "%";

                double Coin_Market_Share_Percent = ((double)(temp.Coin_Market_Cap) / (long)(Global_Data_viewmodels.Total_Market_Cap));
                int    scale = (int)((Coin_Market_Share_Percent / Global_Data_viewmodels.Bitcoin_Percentage_Of_Market_Cap) * 25000000);
                temp.Coin_Picture_Scale = (int)(Math.Sqrt(scale));
                if (temp.Coin_Rank == 1 && temp.Coin_Price_USD > 7000)
                {
                    //mediaPlayer.Play();
                }
                if (temp.Coin_24_Hour_Change < 0)
                {
                    temp.Coin_Sign = new SolidColorBrush(Color.FromArgb(230, 201, 19, 19));
                }
                else
                {
                    temp.Coin_Sign = new SolidColorBrush(Color.FromArgb(230, 19, 201, 31));
                }
                Top_ten_viewmodels.Add(temp);
            }
        }