mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-20 13:34:37 +01:00
Bitnob rate provider (#5705)
* Bitnob rate provider * Add Bitnob as recommended exchange for NGN
This commit is contained in:
parent
b174977bc7
commit
411e0334d0
4 changed files with 49 additions and 1 deletions
40
BTCPayServer.Rating/Providers/BitnobRateProvider.cs
Normal file
40
BTCPayServer.Rating/Providers/BitnobRateProvider.cs
Normal file
|
@ -0,0 +1,40 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BTCPayServer.Services.Rates;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace BTCPayServer.Rating.Providers
|
||||
{
|
||||
public class BitnobRateProvider : IRateProvider
|
||||
{
|
||||
private readonly HttpClient _httpClient;
|
||||
public BitnobRateProvider(HttpClient httpClient)
|
||||
{
|
||||
_httpClient = httpClient ?? new HttpClient();
|
||||
}
|
||||
public RateSourceInfo RateSourceInfo => new("bitnob", "Bitnob", "https://api.bitnob.co/api/v1/rates/bitcoin/price");
|
||||
|
||||
public async Task<PairRate[]> GetRatesAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
using var response = await _httpClient.GetAsync("https://api.bitnob.co/api/v1/rates/bitcoin/price", cancellationToken);
|
||||
JObject jobj = await response.Content.ReadAsAsync<JObject>(cancellationToken);
|
||||
var dataObject = jobj["data"] as JObject;
|
||||
|
||||
if (dataObject == null)
|
||||
{
|
||||
return Array.Empty<PairRate>();
|
||||
}
|
||||
var pairRates = new List<PairRate>();
|
||||
foreach (var property in dataObject.Properties())
|
||||
{
|
||||
string[] parts = property.Name.Split('_');
|
||||
decimal value = property.Value.Value<decimal>();
|
||||
pairRates.Add(new PairRate(new CurrencyPair("BTC", parts[1]), new BidAsk(value)));
|
||||
}
|
||||
return pairRates.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -191,6 +191,12 @@ namespace BTCPayServer.Tests
|
|||
// Ripio keeps changing their pair, so anything is fine...
|
||||
Assert.NotEmpty(exchangeRates.ByExchange[name]);
|
||||
}
|
||||
else if (name == "bitnob")
|
||||
{
|
||||
Assert.Contains(exchangeRates.ByExchange[name],
|
||||
e => e.CurrencyPair == new CurrencyPair("BTC", "NGN") &&
|
||||
e.BidAsk.Bid > 1.0m); // 1 BTC will always be more than 1 NGN
|
||||
}
|
||||
else if (name == "cryptomarket")
|
||||
{
|
||||
Assert.Contains(exchangeRates.ByExchange[name],
|
||||
|
|
|
@ -202,7 +202,8 @@ namespace BTCPayServer.Data
|
|||
{ "JPY", "bitbank" },
|
||||
{ "TRY", "btcturk" },
|
||||
{ "UGX", "yadio"},
|
||||
{ "RSD", "bitpay"}
|
||||
{ "RSD", "bitpay"},
|
||||
{ "NGN", "bitnob"}
|
||||
};
|
||||
|
||||
public string GetRecommendedExchange() =>
|
||||
|
|
|
@ -551,6 +551,7 @@ namespace BTCPayServer.Hosting
|
|||
services.AddRateProvider<ByllsRateProvider>();
|
||||
services.AddRateProvider<BudaRateProvider>();
|
||||
services.AddRateProvider<BitbankRateProvider>();
|
||||
services.AddRateProvider<BitnobRateProvider>();
|
||||
services.AddRateProvider<BitpayRateProvider>();
|
||||
services.AddRateProvider<RipioExchangeProvider>();
|
||||
services.AddRateProvider<CryptoMarketExchangeRateProvider>();
|
||||
|
|
Loading…
Add table
Reference in a new issue