Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public async Task getData()
- {
- var client = new HttpClient();
- HttpResponseMessage response = await client.GetAsync(new Uri("https://api.nomics.com/v1/currencies/ticker?key=d841f8fbafb482e9fa268028947844ea7783b5dd&interval=1d&limit=10"));
- var jsonString = await response.Content.ReadAsStringAsync();
- JsonArray root = JsonValue.Parse(jsonString).GetArray();
- for (uint i = 0; i < root.Count; i++)
- {
- string id = root.GetObjectAt(i).GetNamedString("id");
- string name = root.GetObjectAt(i).GetNamedString("name");
- decimal price = decimal.Parse(root.GetObjectAt(i).GetNamedString("price"));
- Coins.Add(new Coin {
- id = id,
- name = name,
- price = price,
- logo = "https://cryptoicon-api.vercel.app/api/icon/" + id.ToLower()
- });
- };
- foreach (var coin in Coins)
- {
- OldCoins.Add(coin);
- }
- }
- public async Task refreshData()
- {
- var client = new HttpClient();
- HttpResponseMessage response = await client.GetAsync(new Uri("https://api.nomics.com/v1/currencies/ticker?key=d841f8fbafb482e9fa268028947844ea7783b5dd&interval=1d&limit=10"));
- var jsonString = await response.Content.ReadAsStringAsync();
- JsonArray root = JsonValue.Parse(jsonString).GetArray();
- for (uint i = 0; i < root.Count; i++)
- {
- string id = root.GetObjectAt(i).GetNamedString("id");
- string name = root.GetObjectAt(i).GetNamedString("name");
- decimal price = decimal.Parse(root.GetObjectAt(i).GetNamedString("price"));
- Coins.Add(new Coin
- {
- id = id,
- name = name,
- price = price,
- logo = "https://cryptoicon-api.vercel.app/api/icon/" + id.ToLower()
- });
- }
- foreach(var item in OldCoins)
- {
- Coins.Remove(item);
- }
- }
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- refreshData();
- }
Advertisement
Add Comment
Please, Sign In to add comment