2023-01-06 14:18:07 +01:00
|
|
|
using System.Net.Http;
|
2022-06-09 12:01:40 +02:00
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using BTCPayServer.Rating;
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
|
|
|
namespace BTCPayServer.Services.Rates;
|
|
|
|
|
|
|
|
public class BudaRateProvider : IRateProvider
|
|
|
|
{
|
|
|
|
private readonly HttpClient _httpClient;
|
|
|
|
public BudaRateProvider(HttpClient httpClient)
|
|
|
|
{
|
|
|
|
_httpClient = httpClient ?? new HttpClient();
|
|
|
|
}
|
|
|
|
|
2023-01-30 01:46:12 +01:00
|
|
|
public RateSourceInfo RateSourceInfo => new RateSourceInfo("buda", "Buda", "https://www.buda.com/api/v2/markets/btc-clp/ticker");
|
|
|
|
|
2022-06-09 12:01:40 +02:00
|
|
|
public async Task<PairRate[]> GetRatesAsync(CancellationToken cancellationToken)
|
|
|
|
{
|
2023-12-19 03:44:10 +01:00
|
|
|
using var response = await _httpClient.GetAsync("https://www.buda.com/api/v2/markets/btc-clp/ticker", cancellationToken);
|
2022-06-09 12:01:40 +02:00
|
|
|
var jobj = await response.Content.ReadAsAsync<JObject>(cancellationToken);
|
|
|
|
var minAsk = jobj["ticker"]["min_ask"][0].Value<decimal>();
|
|
|
|
var maxBid = jobj["ticker"]["max_bid"][0].Value<decimal>();
|
|
|
|
return new[] { new PairRate(new CurrencyPair("BTC", "CLP"), new BidAsk(maxBid, minAsk)) };
|
|
|
|
}
|
|
|
|
}
|