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;
|
2018-04-14 22:35:52 +09:00
|
|
|
|
using NBitcoin;
|
2018-05-03 03:32:42 +09:00
|
|
|
|
using BTCPayServer.Rating;
|
2017-09-13 15:47:34 +09:00
|
|
|
|
|
2017-09-15 16:06:57 +09:00
|
|
|
|
namespace BTCPayServer.Services.Rates
|
2017-09-13 15:47:34 +09:00
|
|
|
|
{
|
2017-10-27 17:53:04 +09:00
|
|
|
|
public class BitpayRateProvider : IRateProvider
|
|
|
|
|
{
|
2018-05-03 03:32:42 +09:00
|
|
|
|
public const string BitpayName = "bitpay";
|
2017-10-27 17:53:04 +09:00
|
|
|
|
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()
|
2017-10-27 17:53:04 +09:00
|
|
|
|
{
|
2018-05-03 03:32:42 +09:00
|
|
|
|
return new ExchangeRates((await _Bitpay.GetRatesAsync().ConfigureAwait(false))
|
2017-10-27 17:53:04 +09:00
|
|
|
|
.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-10-27 17:53:04 +09:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-13 15:47:34 +09:00
|
|
|
|
}
|