Guest User

Untitled

a guest
Jul 1st, 2021
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. public async Task getData()
  2. {
  3. var client = new HttpClient();
  4. HttpResponseMessage response = await client.GetAsync(new Uri("https://api.nomics.com/v1/currencies/ticker?key=d841f8fbafb482e9fa268028947844ea7783b5dd&interval=1d&limit=10"));
  5. var jsonString = await response.Content.ReadAsStringAsync();
  6. JsonArray root = JsonValue.Parse(jsonString).GetArray();
  7. for (uint i = 0; i < root.Count; i++)
  8. {
  9. string id = root.GetObjectAt(i).GetNamedString("id");
  10. string name = root.GetObjectAt(i).GetNamedString("name");
  11. decimal price = decimal.Parse(root.GetObjectAt(i).GetNamedString("price"));
  12. Coins.Add(new Coin {
  13. id = id,
  14. name = name,
  15. price = price,
  16. logo = "https://cryptoicon-api.vercel.app/api/icon/" + id.ToLower()
  17. });
  18. };
  19. foreach (var coin in Coins)
  20. {
  21. OldCoins.Add(coin);
  22. }
  23. }
  24.  
  25. public async Task refreshData()
  26. {
  27. var client = new HttpClient();
  28. HttpResponseMessage response = await client.GetAsync(new Uri("https://api.nomics.com/v1/currencies/ticker?key=d841f8fbafb482e9fa268028947844ea7783b5dd&interval=1d&limit=10"));
  29. var jsonString = await response.Content.ReadAsStringAsync();
  30. JsonArray root = JsonValue.Parse(jsonString).GetArray();
  31. for (uint i = 0; i < root.Count; i++)
  32. {
  33. string id = root.GetObjectAt(i).GetNamedString("id");
  34. string name = root.GetObjectAt(i).GetNamedString("name");
  35. decimal price = decimal.Parse(root.GetObjectAt(i).GetNamedString("price"));
  36. Coins.Add(new Coin
  37. {
  38. id = id,
  39. name = name,
  40. price = price,
  41. logo = "https://cryptoicon-api.vercel.app/api/icon/" + id.ToLower()
  42. });
  43.  
  44. }
  45. foreach(var item in OldCoins)
  46. {
  47. Coins.Remove(item);
  48. }
  49. }
  50.  
  51. private void Button_Click(object sender, RoutedEventArgs e)
  52. {
  53. refreshData();
  54. }
Advertisement
Add Comment
Please, Sign In to add comment