From 15e1169f6211f401e7a53ae4b576243bef565ca7 Mon Sep 17 00:00:00 2001 From: Kukks Date: Wed, 10 Aug 2022 08:20:41 +0200 Subject: [PATCH] Fix Kraken rate provider --- .../Providers/KrakenExchangeRateProvider.cs | 8 +++++++- BTCPayServer.Tests/ThirdPartyTests.cs | 15 +++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/BTCPayServer.Rating/Providers/KrakenExchangeRateProvider.cs b/BTCPayServer.Rating/Providers/KrakenExchangeRateProvider.cs index 83a7eafc9..3ca425eae 100644 --- a/BTCPayServer.Rating/Providers/KrakenExchangeRateProvider.cs +++ b/BTCPayServer.Rating/Providers/KrakenExchangeRateProvider.cs @@ -177,9 +177,15 @@ namespace BTCPayServer.Services.Rates var result = JsonConvert.DeserializeObject(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); } diff --git a/BTCPayServer.Tests/ThirdPartyTests.cs b/BTCPayServer.Tests/ThirdPartyTests.cs index 61cd82a15..94dd9a711 100644 --- a/BTCPayServer.Tests/ThirdPartyTests.cs +++ b/BTCPayServer.Tests/ThirdPartyTests.cs @@ -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(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]