Skip to content

Commit 2411365

Browse files
authored
Better symbol name translation and error detection in KrakenExchange.OnGetTickersAsync() (#618)
* Update .gitignore Navigating to a folder using the "Finder" on Mac generates a .DS_Store file holding metadata about the folder (e.g. thumbnails etc.). These files can pollute your git commits and are annoying. * Update MovingAverageCalculator.cs Pull methods and expose accessors on base class for consistency. * Better symbol name translation and error detection in KrakenExchange.OnGetTickersAsync()
1 parent 1bebd2e commit 2411365

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/ExchangeSharp/API/Exchanges/Kraken/ExchangeKrakenAPI.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,8 @@ protected override async Task<IEnumerable<KeyValuePair<string, ExchangeTicker>>>
551551
var csvPairsList = string.Join(",", normalizedPairsList);
552552
JToken apiTickers = await MakeJsonRequestAsync<JToken>("/0/public/Ticker", null, new Dictionary<string, object> { { "pair", csvPairsList } });
553553
var tickers = new List<KeyValuePair<string, ExchangeTicker>>();
554+
var unfoundSymbols = new List<String>();
555+
554556
foreach (string marketSymbol in normalizedPairsList)
555557
{
556558
JToken ticker = apiTickers[marketSymbol];
@@ -559,9 +561,14 @@ protected override async Task<IEnumerable<KeyValuePair<string, ExchangeTicker>>>
559561

560562
if (ticker == null)
561563
{
562-
// Some pairs like USDTZUSD are not found, but they can be found using Metadata.
564+
// Some pairs like USDTZUSD are not found, but they (hopefully) can be found using Metadata.
563565
var symbols = (await GetMarketSymbolsMetadataAsync()).ToList();
564-
var symbol = symbols.FirstOrDefault(a => a.MarketSymbol.Replace("/", "").Equals(marketSymbol));
566+
ExchangeMarket symbol = symbols.FirstOrDefault(a => a.AltMarketSymbol.Equals(marketSymbol));
567+
if (symbol == null)
568+
{
569+
unfoundSymbols.Add(marketSymbol);
570+
continue;
571+
}
565572
ticker = apiTickers[symbol.BaseCurrency + symbol.QuoteCurrency];
566573
}
567574

@@ -571,11 +578,15 @@ protected override async Task<IEnumerable<KeyValuePair<string, ExchangeTicker>>>
571578
{
572579
tickers.Add(new KeyValuePair<string, ExchangeTicker>(marketSymbol, await ConvertToExchangeTickerAsync(marketSymbol, ticker)));
573580
}
574-
catch
581+
catch(Exception e)
575582
{
576-
// if Kraken throws bogus json at us, just eat it
583+
Logger.Error(e);
577584
}
578585
}
586+
if(unfoundSymbols.Count > 0)
587+
{
588+
Logger.Warn($"Of {marketSymbols.Count()} symbols, tickers could not be found for {unfoundSymbols.Count}: [{String.Join(", ", unfoundSymbols)}]");
589+
}
579590
return tickers;
580591
}
581592

0 commit comments

Comments
 (0)