mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-22 14:22:40 +01:00
Yadio is a service which provides exchange rates for many currencies such as the Lebanese Pound which have the real exchange rate which differs from the official rate significantly (32,525 LBP for USD real rate vs 1,510 official rate). See more details here: https://yadio.io/info.html See discussions here: https://github.com/btcpayserver/btcpayserver/discussions/4001 https://github.com/btcpayserver/btcpayserver/discussions/2489#discussioncomment-3102370
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;
|
|
int value = results[name].Value<int>();
|
|
|
|
list.Add(new PairRate(new CurrencyPair("BTC", name), new BidAsk(value)));
|
|
}
|
|
|
|
return list.ToArray();
|
|
}
|
|
}
|
|
}
|