Fix Kraken rate provider

This commit is contained in:
Kukks 2022-08-10 08:20:41 +02:00
parent de92677b69
commit 15e1169f62
No known key found for this signature in database
GPG Key ID: 8E5530D9D1C93097
2 changed files with 14 additions and 9 deletions

View File

@ -177,9 +177,15 @@ namespace BTCPayServer.Services.Rates
var result = JsonConvert.DeserializeObject<T>(stringResult);
if (result is JToken json)
{
if (!(json is JArray) && json["result"] is JObject {Count: > 0} pairResult)
{
return (T)(object)(pairResult);
}
if (!(json is JArray) && json["error"] is JArray error && error.Count != 0)
{
throw new APIException(error[0].ToStringInvariant());
throw new APIException(string.Join("\n",
error.Select(token => token.ToStringInvariant()).Distinct()));
}
result = (T)(object)(json["result"] ?? json);
}

View File

@ -72,10 +72,10 @@ namespace BTCPayServer.Tests
}
[Fact]
public void CanQueryDirectProviders()
public async Task CanQueryDirectProviders()
{
// TODO: Check once in a while whether or not they are working again
string[] brokenShitcoinCasinos = { "okex" };
string[] brokenShitcoinCasinos = { };
var factory = FastTests.CreateBTCPayRateFactory();
var directlySupported = factory.GetSupportedExchanges().Where(s => s.Source == RateSource.Direct)
.Select(s => s.Id).ToHashSet();
@ -154,12 +154,11 @@ 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);
}
var p = new KrakenExchangeRateProvider();
var rates = await p.GetRatesAsync(default);
Assert.Contains(rates, e => e.CurrencyPair == new CurrencyPair("XMR", "BTC") && e.BidAsk.Bid < 1.0m);
}
[Fact]