Fix the ExchangeSharpRateProvider for some pairs

This commit is contained in:
nicolas.dorier 2022-07-11 23:39:11 +09:00
parent 03fbd51fab
commit 499352e51c
No known key found for this signature in database
GPG Key ID: 6618763EF09186FE
3 changed files with 13 additions and 5 deletions

View File

@ -44,6 +44,9 @@ namespace BTCPayServer.Services.Rates
{
if (notFoundSymbols.TryGetValue(ticker.Key, out _))
return null;
if (ticker.Key.Contains("XMR"))
{
}
try
{
CurrencyPair pair;

View File

@ -103,16 +103,14 @@ namespace BTCPayServer.Services.Rates
var p2 = symbol.Substring(mapped1.KrakenTicker.Length);
if (_TickerMapping.TryGetValue(p2, out var mapped2))
p2 = mapped2;
global = $"{p2}_{mapped1.PayTicker}";
global = $"{mapped1.PayTicker}_{p2}";
}
else
{
global = await helper.ExchangeMarketSymbolToGlobalMarketSymbolAsync(symbol);
var s = global.Split('-');
global = $"{s[1]}_{s[0]}";
}
if (CurrencyPair.TryParse(global, out var pair))
result.Add(new PairRate(pair.Inverse(), new BidAsk(ticker.Bid, ticker.Ask)));
result.Add(new PairRate(pair, new BidAsk(ticker.Bid, ticker.Ask)));
else
notFoundSymbols.TryAdd(symbol, symbol);
}

View File

@ -130,7 +130,7 @@ namespace BTCPayServer.Tests
{
if (name == "kraken")
{
Assert.Contains(exchangeRates.ByExchange[name], e => e.CurrencyPair == new CurrencyPair("XMR", "BTC"));
Assert.Contains(exchangeRates.ByExchange[name], e => e.CurrencyPair == new CurrencyPair("XMR", "BTC") && e.BidAsk.Bid < 1.0m);
}
// This check if the currency pair is using right currency pair
Assert.Contains(exchangeRates.ByExchange[name],
@ -153,6 +153,13 @@ namespace BTCPayServer.Tests
// Kraken emit one request only after first GetRates
factory.Providers["kraken"].GetRatesAsync(default).GetAwaiter().GetResult();
using (var c = new HttpClient())
{
var p = new ExchangeSharpRateProvider<ExchangeSharp.ExchangeKrakenAPI>(c);
var rates = p.GetRatesAsync(default).GetAwaiter().GetResult();
Assert.Contains(rates, e => e.CurrencyPair == new CurrencyPair("XXMR", "XXBT") && e.BidAsk.Bid < 1.0m);
}
}
[Fact]