mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-19 09:54:30 +01:00
42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
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<PairRate[]> GetRatesAsync(CancellationToken cancellationToken)
|
|
{
|
|
var response = await _httpClient.GetAsync("https://api.yadio.io/exrates/BTC", cancellationToken);
|
|
response.EnsureSuccessStatusCode();
|
|
var jobj = await response.Content.ReadAsAsync<JObject>(cancellationToken);
|
|
var results = jobj["BTC"];
|
|
var list = new List<PairRate>();
|
|
foreach (var item in results)
|
|
{
|
|
|
|
string name = ((JProperty)item).Name;
|
|
var value = results[name].Value<decimal>();
|
|
list.Add(new PairRate(new CurrencyPair("BTC", name), new BidAsk(value)));
|
|
}
|
|
|
|
return list.ToArray();
|
|
}
|
|
}
|
|
}
|