mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-22 06:21:44 +01:00
Fix HitBTC provider
This commit is contained in:
parent
66d01aecc3
commit
f4ad04ec2e
3 changed files with 42 additions and 2 deletions
39
BTCPayServer.Rating/Providers/HitBTCRateProvider.cs
Normal file
39
BTCPayServer.Rating/Providers/HitBTCRateProvider.cs
Normal file
|
@ -0,0 +1,39 @@
|
|||
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
|
||||
{
|
||||
public class HitBTCRateProvider : IRateProvider
|
||||
{
|
||||
private readonly HttpClient _httpClient;
|
||||
public HitBTCRateProvider(HttpClient httpClient)
|
||||
{
|
||||
_httpClient = httpClient ?? new HttpClient();
|
||||
}
|
||||
|
||||
public async Task<PairRate[]> GetRatesAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var response = await _httpClient.GetAsync("https://api.hitbtc.com/api/2/public/ticker", cancellationToken);
|
||||
var jarray = await response.Content.ReadAsAsync<JArray>(cancellationToken);
|
||||
return jarray
|
||||
.Children<JObject>()
|
||||
.Where(p => CurrencyPair.TryParse(p["symbol"].Value<string>(), out _))
|
||||
.Select(p => new PairRate(CurrencyPair.Parse(p["symbol"].Value<string>()), CreateBidAsk(p)))
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
private BidAsk CreateBidAsk(JObject p)
|
||||
{
|
||||
var bid = p["bid"].Value<decimal>();
|
||||
var ask = p["ask"].Value<decimal>();
|
||||
return new BidAsk(bid, ask);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -90,10 +90,10 @@ namespace BTCPayServer.Services.Rates
|
|||
AddExchangeSharpProviders<ExchangeBinanceAPI>("binance");
|
||||
AddExchangeSharpProviders<ExchangeBittrexAPI>("bittrex");
|
||||
AddExchangeSharpProviders<ExchangePoloniexAPI>("poloniex");
|
||||
AddExchangeSharpProviders<ExchangeHitBTCAPI>("hitbtc");
|
||||
AddExchangeSharpProviders<ExchangeNDAXAPI>("ndax");
|
||||
|
||||
// Handmade providers
|
||||
Providers.Add("hitbtc", new HitBTCRateProvider(_httpClientFactory?.CreateClient("EXCHANGE_HITBTC")));
|
||||
Providers.Add("coingecko", new CoinGeckoRateProvider(_httpClientFactory));
|
||||
Providers.Add("kraken", new KrakenExchangeRateProvider() { HttpClient = _httpClientFactory?.CreateClient("EXCHANGE_KRAKEN") });
|
||||
Providers.Add("bylls", new ByllsRateProvider(_httpClientFactory?.CreateClient("EXCHANGE_BYLLS")));
|
||||
|
|
|
@ -11,8 +11,9 @@
|
|||
|
||||
### Bug fixes
|
||||
* Fix some crashes when switching from Altcoins edition to Bitcoin-Only. (@Kukks @NicolasDorier)
|
||||
* Fix invoices CSV Export formatting introduced in 1.0.5.4
|
||||
* Fix invoices CSV Export formatting introduced in 1.0.5.4 (@NicolasDorier)
|
||||
* UI: Fix custom-select glitch (#1822 @DennisReimann)
|
||||
* Fix crash with hitbtc rate provider (@NicolasDorier)
|
||||
|
||||
## 1.0.5.4:
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue