Exemplo n.º 1
0
        ////////////////////////////////////////////////////////////////////////////////////////
        internal async static Task GetHisto(string crypto, string time, int limit)
        {
            //CCCAGG    Bitstamp Bitfinex Coinbase HitBTC Kraken Poloniex
            String URL = "https://min-api.cryptocompare.com/data/histo" + time + "?e=CCCAGG&fsym="
                         + crypto + "&tsym=" + coin + "&limit=" + limit;

            if (limit == 0)
            {
                URL = "https://min-api.cryptocompare.com/data/histoday?e=CCCAGG&fsym=" + crypto + "&tsym=" + coin + "&allData=true";
            }

            Uri                 uri          = new Uri(URL);
            HttpClient          httpClient   = new HttpClient();
            HttpResponseMessage httpResponse = new HttpResponseMessage();

            string response = "";

            try {
                response = await httpClient.GetStringAsync(uri);

                var data = JToken.Parse(response);

                historic.Clear();
                int lastIndex = ((JContainer)data["Data"]).Count;
                for (int i = 0; i < lastIndex; i++)
                {
                    historic.Add(PricePoint.GetPricePointHisto(data["Data"][i]));
                }
                switch (crypto)
                {
                case "BTC":
                    BTC_now = (float)Math.Round((float)data["Data"][lastIndex - 1]["close"], 2);
                    BTC_old = (float)Math.Round((float)data["Data"][0]["close"], 2);
                    break;

                case "ETH":
                    ETH_now = (float)Math.Round((float)data["Data"][lastIndex - 1]["close"], 2);
                    ETH_old = (float)Math.Round((float)data["Data"][0]["close"], 2);
                    break;

                case "LTC":
                    LTC_now = (float)Math.Round((float)data["Data"][lastIndex - 1]["close"], 2);
                    LTC_old = (float)Math.Round((float)data["Data"][0]["close"], 2);
                    break;

                case "XRP":
                    XRP_now = (float)Math.Round((float)data["Data"][lastIndex - 1]["close"], 2);
                    XRP_old = (float)Math.Round((float)data["Data"][0]["close"], 2);
                    break;
                }
            } catch (Exception ex) {
                //var dontWait = await new MessageDialog(ex.Message).ShowAsync();
            }
        }