using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Text; using System.Threading; using System.Threading.Tasks; using BTCPayServer.Services.Rates; using Newtonsoft.Json.Linq; namespace BTCPayServer.Rating.Providers { public class BtcTurkRateProvider : IRateProvider { class Ticker { public string pairNormalized { get; set; } public decimal? bid { get; set; } public decimal? ask { get; set; } } private readonly HttpClient _httpClient; public BtcTurkRateProvider(HttpClient httpClient) { _httpClient = httpClient ?? new HttpClient(); } public async Task GetRatesAsync(CancellationToken cancellationToken) { var response = await _httpClient.GetAsync("https://api.btcturk.com/api/v2/ticker", cancellationToken); var jarray = (JArray)(await response.Content.ReadAsAsync(cancellationToken))["data"]; var tickers = jarray.ToObject(); return tickers .Where(t => t.bid is not null && t.ask is not null) .Select(t => new PairRate(CurrencyPair.Parse(t.pairNormalized), new BidAsk(t.bid.Value, t.ask.Value))).ToArray(); } } }