using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Net.Http; using System.Text; using System.Threading; using System.Threading.Tasks; using BTCPayServer.Rating; using Newtonsoft.Json.Linq; using Newtonsoft.Json; namespace BTCPayServer.Services.Rates { public class YadioRateProvider : IRateProvider { private readonly HttpClient _httpClient; public YadioRateProvider(HttpClient httpClient) { _httpClient = httpClient ?? new HttpClient(); } public async Task GetRatesAsync(CancellationToken cancellationToken) { var response = await _httpClient.GetAsync("https://api.yadio.io/exrates/BTC", cancellationToken); response.EnsureSuccessStatusCode(); var jobj = await response.Content.ReadAsAsync(cancellationToken); var results = jobj["BTC"]; var list = new List(); foreach (var item in results) { string name = ((JProperty)item).Name; var value = results[name].Value(); list.Add(new PairRate(new CurrencyPair("BTC", name), new BidAsk(value))); } return list.ToArray(); } } }