mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-20 02:28:31 +01:00
5e469ff9c0
* Removes Chaincoin shitcoin which is so dead even its website is gone * Add ExchangeRateHost and FreeCurrencyRates as new rate providers * Add recommended rate providers for UGX and RSD * Fix BTX rate by switching to graviex * Fix BTC rate by switching to exmo * Fix LCAD rate script
37 lines
1.3 KiB
C#
37 lines
1.3 KiB
C#
using System.Collections.Generic;
|
|
using System.Net.Http;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using BTCPayServer.Rating;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
namespace BTCPayServer.Services.Rates;
|
|
|
|
public class FreeCurrencyRatesRateProvider : IRateProvider
|
|
{
|
|
public RateSourceInfo RateSourceInfo => new("free-currency-rates", "Free Currency Rates", "https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/latest/currencies/btc.min.json");
|
|
private readonly HttpClient _httpClient;
|
|
public FreeCurrencyRatesRateProvider(HttpClient httpClient)
|
|
{
|
|
_httpClient = httpClient ?? new HttpClient();
|
|
}
|
|
|
|
public async Task<PairRate[]> GetRatesAsync(CancellationToken cancellationToken)
|
|
{
|
|
var response = await _httpClient.GetAsync(RateSourceInfo.Url, cancellationToken);
|
|
response.EnsureSuccessStatusCode();
|
|
var jobj = await response.Content.ReadAsAsync<JObject>(cancellationToken);
|
|
var results = (JObject) jobj["btc"] ;
|
|
//key value is currency code to rate value
|
|
var list = new List<PairRate>();
|
|
foreach (var item in results)
|
|
{
|
|
string name = item.Key;
|
|
var value = item.Value.Value<decimal>();
|
|
list.Add(new PairRate(new CurrencyPair("BTC", name), new BidAsk(value)));
|
|
}
|
|
|
|
return list.ToArray();
|
|
}
|
|
}
|