using System.Net.Http; using System.Threading; using System.Threading.Tasks; using BTCPayServer.Rating; using Newtonsoft.Json.Linq; namespace BTCPayServer.Services.Rates { public class ByllsRateProvider : IRateProvider { private readonly HttpClient _httpClient; public ByllsRateProvider(HttpClient httpClient) { _httpClient = httpClient ?? new HttpClient(); } public async Task GetRatesAsync(CancellationToken cancellationToken) { var response = await _httpClient.GetAsync("https://bylls.com/api/price?from_currency=BTC&to_currency=CAD", cancellationToken); var jobj = await response.Content.ReadAsAsync(cancellationToken); var value = jobj["public_price"]["to_price"].Value(); return new[] { new PairRate(new CurrencyPair("BTC", "CAD"), new BidAsk(value)) }; } } }