private async Task <CryptoCompareJSON> GetQuotes() { CryptoCompareJSON cryptoCompareJSON = null; string fsyms = ""; if (cardViewDict.Keys.Count == 0) { return(cryptoCompareJSON); } foreach (string key in cardViewDict.Keys) { fsyms += key + ","; } fsyms = fsyms.Remove(fsyms.LastIndexOf(',')); string url = "https://min-api.cryptocompare.com/data/pricemultifull?fsyms=" + fsyms + "&tsyms=USD"; //string url = "https://min-api.cryptocompare.com/data/pricemultifull?fsyms=BTC,ETH,XRP,ZEC,LTC&tsyms=USD"; HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(url)); request.ContentType = "application/json"; request.Method = "GET"; using (WebResponse response = await request.GetResponseAsync()) { using (Stream stream = response.GetResponseStream()) { var serializer = new JsonSerializer(); StreamReader sr = new System.IO.StreamReader(stream); using (var jst = new JsonTextReader(sr)) { cryptoCompareJSON = await Task.Run(() => serializer.Deserialize <CryptoCompareJSON>(jst)); return(cryptoCompareJSON); } } } }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Use this to return your custom view for this Fragment var view = inflater.Inflate(Resource.Layout.quotepanelfragment, container, false); cardViewGridLayout = view.FindViewById <GridLayout>(Resource.Id.gridCardLayout); var activity = (MainActivity)Activity; cardViewDict = new Dictionary <string, CardView>(); //GenerateCards(); GenerateCardsFromDatabase(); UpdateCoinBalances(); webQuoteTimer.Elapsed += async(sender, e) => { CryptoCompareJSON crypotCompareJSON = await GetQuotes(); if (crypotCompareJSON == null) { return; } RAW raw = crypotCompareJSON.Raw; System.Reflection.PropertyInfo[] propertyInfo = raw.GetType().GetProperties(); foreach (var propInfo in propertyInfo) { var value = propInfo.GetValue(raw, null); SYMBOL sym = value as SYMBOL; if (sym == null) { continue; } string symbol = sym.Usd.FROMSYMBOL; double price = sym.Usd.PRICE; DateTime lastUpdate = DateTimeOffset.FromUnixTimeSeconds(sym.Usd.LASTUPDATE).LocalDateTime; double change = sym.Usd.CHANGEDAY; double changePct = sym.Usd.CHANGEPCTDAY; Activity.RunOnUiThread(() => { UpdateCardView(symbol, price, change, changePct, lastUpdate); activity.SetTotalValue(symbolValues.Sum(x => x.Value)); }); } }; webQuoteTimer.Start(); return(view); }