btcpayserver/BTCPayServer/Services/Rates/BitpayRateProvider.cs

32 lines
924 B
C#
Raw Normal View History

2017-09-13 15:47:34 +09:00
using NBitpayClient;
using System.Linq;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using NBitcoin;
2018-05-03 03:32:42 +09:00
using BTCPayServer.Rating;
2017-09-13 15:47:34 +09:00
namespace BTCPayServer.Services.Rates
2017-09-13 15:47:34 +09:00
{
public class BitpayRateProvider : IRateProvider
{
2018-05-03 03:32:42 +09:00
public const string BitpayName = "bitpay";
Bitpay _Bitpay;
public BitpayRateProvider(Bitpay bitpay)
{
if (bitpay == null)
throw new ArgumentNullException(nameof(bitpay));
_Bitpay = bitpay;
}
2017-09-13 15:47:34 +09:00
2018-05-03 03:32:42 +09:00
public async Task<ExchangeRates> GetRatesAsync()
{
2018-05-03 03:32:42 +09:00
return new ExchangeRates((await _Bitpay.GetRatesAsync().ConfigureAwait(false))
.AllRates
2018-05-03 03:32:42 +09:00
.Select(r => new ExchangeRate() { Exchange = BitpayName, CurrencyPair = new CurrencyPair("BTC", r.Code), Value = r.Value })
.ToList());
}
}
2017-09-13 15:47:34 +09:00
}