mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-01-18 21:32:27 +01:00
Remove ability to set custom cache, fix coinaverage not really using coinaverage
This commit is contained in:
parent
9739f3fb25
commit
7d545ca682
@ -11,11 +11,17 @@ namespace BTCPayServer.Rating
|
|||||||
public string Name { get; }
|
public string Name { get; }
|
||||||
public string Url { get; }
|
public string Url { get; }
|
||||||
public string Id { get; }
|
public string Id { get; }
|
||||||
|
public string SourceId { get; }
|
||||||
public RateSource Source { get; }
|
public RateSource Source { get; }
|
||||||
|
|
||||||
public AvailableRateProvider(string id, string name, string url, RateSource source)
|
public AvailableRateProvider(string id, string name, string url) : this(id, id, name, url, RateSource.Direct)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
public AvailableRateProvider(string id, string sourceId, string name, string url, RateSource source)
|
||||||
{
|
{
|
||||||
Id = id;
|
Id = id;
|
||||||
|
SourceId = sourceId;
|
||||||
Name = name;
|
Name = name;
|
||||||
Url = url;
|
Url = url;
|
||||||
Source = source;
|
Source = source;
|
||||||
|
@ -54,7 +54,7 @@ namespace BTCPayServer.Services.Rates
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This class is a decorator which handle caching and pre-emptive query to the underlying exchange
|
/// This class is a decorator which handle caching and pre-emptive query to the underlying rate provider
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class BackgroundFetcherRateProvider : IRateProvider
|
public class BackgroundFetcherRateProvider : IRateProvider
|
||||||
{
|
{
|
||||||
@ -139,6 +139,9 @@ namespace BTCPayServer.Services.Rates
|
|||||||
}
|
}
|
||||||
|
|
||||||
TimeSpan _RefreshRate = TimeSpan.FromSeconds(30);
|
TimeSpan _RefreshRate = TimeSpan.FromSeconds(30);
|
||||||
|
/// <summary>
|
||||||
|
/// The timespan after which <see cref="UpdateIfNecessary(CancellationToken)"/> will get the rates from the underlying rate provider
|
||||||
|
/// </summary>
|
||||||
public TimeSpan RefreshRate
|
public TimeSpan RefreshRate
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@ -156,6 +159,9 @@ namespace BTCPayServer.Services.Rates
|
|||||||
}
|
}
|
||||||
|
|
||||||
TimeSpan _ValidatyTime = TimeSpan.FromMinutes(10);
|
TimeSpan _ValidatyTime = TimeSpan.FromMinutes(10);
|
||||||
|
/// <summary>
|
||||||
|
/// The timespan after which calls to <see cref="GetRatesAsync(CancellationToken)"/> will fails if the rate has not been updated
|
||||||
|
/// </summary>
|
||||||
public TimeSpan ValidatyTime
|
public TimeSpan ValidatyTime
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
@ -23,9 +23,6 @@ namespace BTCPayServer.Services.Rates
|
|||||||
{
|
{
|
||||||
public string PublicKey { get; set; }
|
public string PublicKey { get; set; }
|
||||||
public string PrivateKey { get; set; }
|
public string PrivateKey { get; set; }
|
||||||
[DefaultValue(15)]
|
|
||||||
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
|
|
||||||
public int CacheInMinutes { get; set; } = 15;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface ICoinAverageAuthenticator
|
public interface ICoinAverageAuthenticator
|
||||||
|
@ -100,18 +100,18 @@ namespace BTCPayServer.Services.Rates
|
|||||||
}
|
}
|
||||||
internal IEnumerable<AvailableRateProvider> GetDirectlySupportedExchanges()
|
internal IEnumerable<AvailableRateProvider> GetDirectlySupportedExchanges()
|
||||||
{
|
{
|
||||||
yield return new AvailableRateProvider("binance", "Binance", "https://api.binance.com/api/v1/ticker/24hr", RateSource.Direct);
|
yield return new AvailableRateProvider("binance", "Binance", "https://api.binance.com/api/v1/ticker/24hr");
|
||||||
yield return new AvailableRateProvider("bittrex", "Bittrex", "https://bittrex.com/api/v1.1/public/getmarketsummaries", RateSource.Direct);
|
yield return new AvailableRateProvider("bittrex", "Bittrex", "https://bittrex.com/api/v1.1/public/getmarketsummaries");
|
||||||
yield return new AvailableRateProvider("poloniex", "Poloniex", "https://poloniex.com/public?command=returnTicker", RateSource.Direct);
|
yield return new AvailableRateProvider("poloniex", "Poloniex", "https://poloniex.com/public?command=returnTicker");
|
||||||
yield return new AvailableRateProvider("hitbtc", "HitBTC", "https://api.hitbtc.com/api/2/public/ticker", RateSource.Direct);
|
yield return new AvailableRateProvider("hitbtc", "HitBTC", "https://api.hitbtc.com/api/2/public/ticker");
|
||||||
yield return new AvailableRateProvider("ndax", "NDAX", "https://ndax.io/api/returnTicker", RateSource.Direct);
|
yield return new AvailableRateProvider("ndax", "NDAX", "https://ndax.io/api/returnTicker");
|
||||||
|
|
||||||
yield return new AvailableRateProvider(CoinGeckoRateProvider.CoinGeckoName, "Coin Gecko", "https://api.coingecko.com/api/v3/exchange_rates", RateSource.Direct);
|
yield return new AvailableRateProvider(CoinGeckoRateProvider.CoinGeckoName, "Coin Gecko", "https://api.coingecko.com/api/v3/exchange_rates");
|
||||||
yield return new AvailableRateProvider(CoinAverageRateProvider.CoinAverageName, "Coin Average", "https://apiv2.bitcoinaverage.com/indices/global/ticker/short", RateSource.Direct);
|
yield return new AvailableRateProvider(CoinAverageRateProvider.CoinAverageName, "Coin Average", "https://apiv2.bitcoinaverage.com/indices/global/ticker/short");
|
||||||
yield return new AvailableRateProvider("kraken", "Kraken", "https://api.kraken.com/0/public/Ticker?pair=ATOMETH,ATOMEUR,ATOMUSD,ATOMXBT,BATETH,BATEUR,BATUSD,BATXBT,BCHEUR,BCHUSD,BCHXBT,DAIEUR,DAIUSD,DAIUSDT,DASHEUR,DASHUSD,DASHXBT,EOSETH,EOSXBT,ETHCHF,ETHDAI,ETHUSDC,ETHUSDT,GNOETH,GNOXBT,ICXETH,ICXEUR,ICXUSD,ICXXBT,LINKETH,LINKEUR,LINKUSD,LINKXBT,LSKETH,LSKEUR,LSKUSD,LSKXBT,NANOETH,NANOEUR,NANOUSD,NANOXBT,OMGETH,OMGEUR,OMGUSD,OMGXBT,PAXGETH,PAXGEUR,PAXGUSD,PAXGXBT,SCETH,SCEUR,SCUSD,SCXBT,USDCEUR,USDCUSD,USDCUSDT,USDTCAD,USDTEUR,USDTGBP,USDTZUSD,WAVESETH,WAVESEUR,WAVESUSD,WAVESXBT,XBTCHF,XBTDAI,XBTUSDC,XBTUSDT,XDGEUR,XDGUSD,XETCXETH,XETCXXBT,XETCZEUR,XETCZUSD,XETHXXBT,XETHZCAD,XETHZEUR,XETHZGBP,XETHZJPY,XETHZUSD,XLTCXXBT,XLTCZEUR,XLTCZUSD,XMLNXETH,XMLNXXBT,XMLNZEUR,XMLNZUSD,XREPXETH,XREPXXBT,XREPZEUR,XXBTZCAD,XXBTZEUR,XXBTZGBP,XXBTZJPY,XXBTZUSD,XXDGXXBT,XXLMXXBT,XXMRXXBT,XXMRZEUR,XXMRZUSD,XXRPXXBT,XXRPZEUR,XXRPZUSD,XZECXXBT,XZECZEUR,XZECZUSD", RateSource.Direct);
|
yield return new AvailableRateProvider("kraken", "Kraken", "https://api.kraken.com/0/public/Ticker?pair=ATOMETH,ATOMEUR,ATOMUSD,ATOMXBT,BATETH,BATEUR,BATUSD,BATXBT,BCHEUR,BCHUSD,BCHXBT,DAIEUR,DAIUSD,DAIUSDT,DASHEUR,DASHUSD,DASHXBT,EOSETH,EOSXBT,ETHCHF,ETHDAI,ETHUSDC,ETHUSDT,GNOETH,GNOXBT,ICXETH,ICXEUR,ICXUSD,ICXXBT,LINKETH,LINKEUR,LINKUSD,LINKXBT,LSKETH,LSKEUR,LSKUSD,LSKXBT,NANOETH,NANOEUR,NANOUSD,NANOXBT,OMGETH,OMGEUR,OMGUSD,OMGXBT,PAXGETH,PAXGEUR,PAXGUSD,PAXGXBT,SCETH,SCEUR,SCUSD,SCXBT,USDCEUR,USDCUSD,USDCUSDT,USDTCAD,USDTEUR,USDTGBP,USDTZUSD,WAVESETH,WAVESEUR,WAVESUSD,WAVESXBT,XBTCHF,XBTDAI,XBTUSDC,XBTUSDT,XDGEUR,XDGUSD,XETCXETH,XETCXXBT,XETCZEUR,XETCZUSD,XETHXXBT,XETHZCAD,XETHZEUR,XETHZGBP,XETHZJPY,XETHZUSD,XLTCXXBT,XLTCZEUR,XLTCZUSD,XMLNXETH,XMLNXXBT,XMLNZEUR,XMLNZUSD,XREPXETH,XREPXXBT,XREPZEUR,XXBTZCAD,XXBTZEUR,XXBTZGBP,XXBTZJPY,XXBTZUSD,XXDGXXBT,XXLMXXBT,XXMRXXBT,XXMRZEUR,XXMRZUSD,XXRPXXBT,XXRPZEUR,XXRPZUSD,XZECXXBT,XZECZEUR,XZECZUSD");
|
||||||
yield return new AvailableRateProvider("bylls", "Bylls", "https://bylls.com/api/price?from_currency=BTC&to_currency=CAD", RateSource.Direct);
|
yield return new AvailableRateProvider("bylls", "Bylls", "https://bylls.com/api/price?from_currency=BTC&to_currency=CAD");
|
||||||
yield return new AvailableRateProvider("bitbank", "Bitbank", "https://public.bitbank.cc/prices", RateSource.Direct);
|
yield return new AvailableRateProvider("bitbank", "Bitbank", "https://public.bitbank.cc/prices");
|
||||||
yield return new AvailableRateProvider("bitpay", "Bitpay", "https://bitpay.com/rates", RateSource.Direct);
|
yield return new AvailableRateProvider("bitpay", "Bitpay", "https://bitpay.com/rates");
|
||||||
}
|
}
|
||||||
void InitExchanges()
|
void InitExchanges()
|
||||||
{
|
{
|
||||||
@ -141,16 +141,8 @@ namespace BTCPayServer.Services.Rates
|
|||||||
if (provider.Key == "cryptopia") // Shitty exchange, rate often unavailable, it spams the logs
|
if (provider.Key == "cryptopia") // Shitty exchange, rate often unavailable, it spams the logs
|
||||||
continue;
|
continue;
|
||||||
var prov = new BackgroundFetcherRateProvider(provider.Key, Providers[provider.Key]);
|
var prov = new BackgroundFetcherRateProvider(provider.Key, Providers[provider.Key]);
|
||||||
if (provider.Key == CoinGeckoRateProvider.CoinGeckoName)
|
prov.RefreshRate = TimeSpan.FromMinutes(1.0);
|
||||||
{
|
prov.ValidatyTime = TimeSpan.FromMinutes(5.0);
|
||||||
prov.RefreshRate = CacheSpan;
|
|
||||||
prov.ValidatyTime = CacheSpan + TimeSpan.FromMinutes(1.0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
prov.RefreshRate = TimeSpan.FromMinutes(1.0);
|
|
||||||
prov.ValidatyTime = TimeSpan.FromMinutes(5.0);
|
|
||||||
}
|
|
||||||
Providers[provider.Key] = prov;
|
Providers[provider.Key] = prov;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,8 +166,9 @@ namespace BTCPayServer.Services.Rates
|
|||||||
{
|
{
|
||||||
if (!Providers.ContainsKey(supportedExchange.Id))
|
if (!Providers.ContainsKey(supportedExchange.Id))
|
||||||
{
|
{
|
||||||
var coinAverage = new CoinGeckoRateProvider(_httpClientFactory)
|
var coinAverage = new CoinAverageRateProvider()
|
||||||
{
|
{
|
||||||
|
HttpClient = _httpClientFactory.CreateClient("RATEPROVIDER_COINAVERAGE"),
|
||||||
Exchange = supportedExchange.Id
|
Exchange = supportedExchange.Id
|
||||||
};
|
};
|
||||||
var cached = new CachedRateProvider(supportedExchange.Id, coinAverage, cache)
|
var cached = new CachedRateProvider(supportedExchange.Id, coinAverage, cache)
|
||||||
@ -275,17 +268,17 @@ namespace BTCPayServer.Services.Rates
|
|||||||
(DisplayName: "itBit", Name: "itbit"),
|
(DisplayName: "itBit", Name: "itbit"),
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
yield return new AvailableRateProvider(item.Name, item.DisplayName, $"https://apiv2.bitcoinaverage.com/exchanges/{item.Name}", RateSource.CoinAverage);
|
yield return new AvailableRateProvider(item.Name, item.Name, item.DisplayName, $"https://apiv2.bitcoinaverage.com/exchanges/{item.Name}", RateSource.CoinAverage);
|
||||||
}
|
}
|
||||||
yield return new AvailableRateProvider("gdax", string.Empty, $"https://apiv2.bitcoinaverage.com/exchanges/gdax", RateSource.CoinAverage);
|
yield return new AvailableRateProvider("gdax", "coinbasepro", string.Empty, $"https://apiv2.bitcoinaverage.com/exchanges/coinbasepro", RateSource.CoinAverage);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal IEnumerable<AvailableRateProvider> GetCoinGeckoSupportedExchanges()
|
internal IEnumerable<AvailableRateProvider> GetCoinGeckoSupportedExchanges()
|
||||||
{
|
{
|
||||||
return JArray.Parse(CoinGeckoRateProvider.SupportedExchanges).Select(token =>
|
return JArray.Parse(CoinGeckoRateProvider.SupportedExchanges).Select(token =>
|
||||||
new AvailableRateProvider(Normalize(token["id"].ToString().ToLowerInvariant()), token["name"].ToString(),
|
new AvailableRateProvider(Normalize(token["id"].ToString().ToLowerInvariant()), token["id"].ToString().ToLowerInvariant(), token["name"].ToString(),
|
||||||
$"https://api.coingecko.com/api/v3/exchanges/{token["id"]}/tickers", RateSource.Coingecko))
|
$"https://api.coingecko.com/api/v3/exchanges/{token["id"]}/tickers", RateSource.Coingecko))
|
||||||
.Concat(new[] { new AvailableRateProvider("gdax", string.Empty, $"https://api.coingecko.com/api/v3/exchanges/gdax", RateSource.Coingecko) });
|
.Concat(new[] { new AvailableRateProvider("gdax", "gdax", string.Empty, $"https://api.coingecko.com/api/v3/exchanges/gdax", RateSource.Coingecko) });
|
||||||
}
|
}
|
||||||
|
|
||||||
private string Normalize(string name)
|
private string Normalize(string name)
|
||||||
|
@ -91,7 +91,6 @@ namespace BTCPayServer.Controllers
|
|||||||
|
|
||||||
var vm = new RatesViewModel()
|
var vm = new RatesViewModel()
|
||||||
{
|
{
|
||||||
CacheMinutes = rates.CacheInMinutes,
|
|
||||||
PrivateKey = rates.PrivateKey,
|
PrivateKey = rates.PrivateKey,
|
||||||
PublicKey = rates.PublicKey
|
PublicKey = rates.PublicKey
|
||||||
};
|
};
|
||||||
@ -119,7 +118,6 @@ namespace BTCPayServer.Controllers
|
|||||||
var rates = (await _SettingsRepository.GetSettingAsync<RatesSetting>()) ?? new RatesSetting();
|
var rates = (await _SettingsRepository.GetSettingAsync<RatesSetting>()) ?? new RatesSetting();
|
||||||
rates.PrivateKey = vm.PrivateKey;
|
rates.PrivateKey = vm.PrivateKey;
|
||||||
rates.PublicKey = vm.PublicKey;
|
rates.PublicKey = vm.PublicKey;
|
||||||
rates.CacheInMinutes = vm.CacheMinutes;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var service = GetCoinaverageService(vm, true);
|
var service = GetCoinaverageService(vm, true);
|
||||||
|
@ -146,7 +146,6 @@ namespace BTCPayServer.HostedServices
|
|||||||
async Task RefreshCoinAverageSettings()
|
async Task RefreshCoinAverageSettings()
|
||||||
{
|
{
|
||||||
var rates = (await _SettingsRepository.GetSettingAsync<RatesSetting>()) ?? new RatesSetting();
|
var rates = (await _SettingsRepository.GetSettingAsync<RatesSetting>()) ?? new RatesSetting();
|
||||||
_RateProviderFactory.CacheSpan = TimeSpan.FromMinutes(rates.CacheInMinutes);
|
|
||||||
if (!string.IsNullOrWhiteSpace(rates.PrivateKey) && !string.IsNullOrWhiteSpace(rates.PublicKey))
|
if (!string.IsNullOrWhiteSpace(rates.PrivateKey) && !string.IsNullOrWhiteSpace(rates.PublicKey))
|
||||||
{
|
{
|
||||||
_coinAverageSettings.KeyPair = (rates.PublicKey, rates.PrivateKey);
|
_coinAverageSettings.KeyPair = (rates.PublicKey, rates.PrivateKey);
|
||||||
|
@ -12,9 +12,6 @@ namespace BTCPayServer.Models.ServerViewModels
|
|||||||
[Display(Name = "Bitcoin average api keys")]
|
[Display(Name = "Bitcoin average api keys")]
|
||||||
public string PublicKey { get; set; }
|
public string PublicKey { get; set; }
|
||||||
public string PrivateKey { get; set; }
|
public string PrivateKey { get; set; }
|
||||||
[Display(Name = "Cache the rates for ... minutes")]
|
|
||||||
[Range(0, 60)]
|
|
||||||
public int CacheMinutes { get; set; }
|
|
||||||
public GetRateLimitsResponse RateLimits { get; internal set; }
|
public GetRateLimitsResponse RateLimits { get; internal set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ namespace BTCPayServer.Models.StoreViewModels
|
|||||||
public void SetExchangeRates(IEnumerable<AvailableRateProvider> supportedList, string preferredExchange)
|
public void SetExchangeRates(IEnumerable<AvailableRateProvider> supportedList, string preferredExchange)
|
||||||
{
|
{
|
||||||
var defaultStore = preferredExchange ?? CoinGeckoRateProvider.CoinGeckoName;
|
var defaultStore = preferredExchange ?? CoinGeckoRateProvider.CoinGeckoName;
|
||||||
supportedList = supportedList.Select(a => new AvailableRateProvider(a.Id, GetName(a), a.Url, a.Source)).ToArray();
|
supportedList = supportedList.Select(a => new AvailableRateProvider(a.Id, a.SourceId, GetName(a), a.Url, a.Source)).ToArray();
|
||||||
var chosen = supportedList.FirstOrDefault(f => f.Id == defaultStore) ?? supportedList.FirstOrDefault();
|
var chosen = supportedList.FirstOrDefault(f => f.Id == defaultStore) ?? supportedList.FirstOrDefault();
|
||||||
Exchanges = new SelectList(supportedList, nameof(chosen.Id), nameof(chosen.Name), chosen);
|
Exchanges = new SelectList(supportedList, nameof(chosen.Id), nameof(chosen.Name), chosen);
|
||||||
PreferredExchange = chosen.Id;
|
PreferredExchange = chosen.Id;
|
||||||
|
@ -28,11 +28,6 @@
|
|||||||
<input asp-for="PrivateKey" style="width:50%;" class="form-control" placeholder="Private key" />
|
<input asp-for="PrivateKey" style="width:50%;" class="form-control" placeholder="Private key" />
|
||||||
<p class="form-text text-muted">You can find the information on the <a target="_blank" href="https://bitcoinaverage.com/en/apikeys">bitcoinaverage api key page</a></p>
|
<p class="form-text text-muted">You can find the information on the <a target="_blank" href="https://bitcoinaverage.com/en/apikeys">bitcoinaverage api key page</a></p>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="CacheMinutes"></label>
|
|
||||||
<input asp-for="CacheMinutes" class="form-control" />
|
|
||||||
<span asp-validation-for="CacheMinutes" class="text-danger"></span>
|
|
||||||
</div>
|
|
||||||
@if(Model.RateLimits != null)
|
@if(Model.RateLimits != null)
|
||||||
{
|
{
|
||||||
<h5>Current Bitcoin Average Quotas:</h5>
|
<h5>Current Bitcoin Average Quotas:</h5>
|
||||||
|
Loading…
Reference in New Issue
Block a user