Skip to content

Commit d1c5137

Browse files
authored
Use AltMarketSymbol to hanlde Kraken WebSocket symbol difference and Gemini lower case symbol names. Pass isWebsocket flag in console app. (#594)
1 parent 463551a commit d1c5137

File tree

5 files changed

+24
-7
lines changed

5 files changed

+24
-7
lines changed

src/ExchangeSharp/API/Exchanges/Gemini/ExchangeGeminiAPI.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ protected internal override async Task<IEnumerable<ExchangeMarket>> OnGetMarketS
175175
}
176176
decimal incrementSize = incrementNode.InnerText.Substring(0, incrementSizePos).ConvertInvariant<decimal>();
177177
market.MarketSymbol = symbol;
178+
market.AltMarketSymbol = symbol.ToUpper();
178179
market.BaseCurrency = symbol.Substring(0, symbol.Length - 3);
179180
market.QuoteCurrency = symbol.Substring(symbol.Length - 3);
180181
market.MinTradeSize = minOrderSize;
@@ -412,7 +413,7 @@ static void PublishTicker(ExchangeTicker ticker, string marketSymbol, Concurrent
412413
if (changesToken != null)
413414
{
414415
string marketSymbol = token["symbol"].ToStringInvariant();
415-
if (changesToken.FirstOrDefault()is JArray candleArray)
416+
if (changesToken.FirstOrDefault() is JArray candleArray)
416417
{
417418
decimal volume = candleArray[5].ConvertInvariant<decimal>();
418419
volumeDict[marketSymbol] = volume;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,8 @@ protected override async Task<IEnumerable<string>> OnGetMarketSymbolsAsync(bool
410410
.ToList();
411411
}
412412

413+
names.Sort();
414+
413415
return names;
414416
}
415417

src/ExchangeSharp/API/Exchanges/_Base/ExchangeAPI.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -679,18 +679,32 @@ public virtual async Task<IEnumerable<ExchangeMarket>> GetMarketSymbolsMetadataA
679679
// not sure if this is needed, but adding it just in case
680680
await new SynchronizationContextRemover();
681681
Dictionary<string, ExchangeMarket> lookup = await this.GetExchangeMarketDictionaryFromCacheAsync();
682-
if (lookup != null && lookup.TryGetValue(marketSymbol, out ExchangeMarket market))
682+
683+
foreach(KeyValuePair<string, ExchangeMarket> kvp in lookup)
683684
{
684-
return market;
685+
if ((kvp.Key == marketSymbol)
686+
|| (kvp.Value.MarketSymbol == marketSymbol)
687+
|| (kvp.Value.AltMarketSymbol == marketSymbol)
688+
|| (kvp.Value.AltMarketSymbol2 == marketSymbol))
689+
{
690+
return kvp.Value;
691+
}
685692
}
686693

687694
// try again with a fresh request
688695
Cache.Remove(nameof(GetMarketSymbolsMetadataAsync));
689696
Cache.Remove(nameof(ExchangeAPIExtensions.GetExchangeMarketDictionaryFromCacheAsync));
690697
lookup = await this.GetExchangeMarketDictionaryFromCacheAsync();
691-
if (lookup != null && lookup.TryGetValue(marketSymbol, out market))
698+
699+
foreach (KeyValuePair<string, ExchangeMarket> kvp in lookup)
692700
{
693-
return market;
701+
if ((kvp.Key == marketSymbol)
702+
|| (kvp.Value.MarketSymbol == marketSymbol)
703+
|| (kvp.Value.AltMarketSymbol == marketSymbol)
704+
|| (kvp.Value.AltMarketSymbol2 == marketSymbol))
705+
{
706+
return kvp.Value;
707+
}
694708
}
695709
}
696710
catch

src/ExchangeSharpConsole/Options/WebSocketsTickersOption.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public override async Task RunCommand()
1717
{
1818
async Task<IWebSocket> GetWebSocket(IExchangeAPI api)
1919
{
20-
var symbols = await ValidateMarketSymbolsAsync(api, MarketSymbols.ToArray());
20+
var symbols = await ValidateMarketSymbolsAsync(api, MarketSymbols.ToArray(), true);
2121

2222
return await api.GetTickersWebSocketAsync(freshTickers =>
2323
{

src/ExchangeSharpConsole/Options/WebSocketsTradesOption.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public override async Task RunCommand()
1717
{
1818
async Task<IWebSocket> GetWebSocket(IExchangeAPI api)
1919
{
20-
var symbols = await ValidateMarketSymbolsAsync(api, MarketSymbols.ToArray());
20+
var symbols = await ValidateMarketSymbolsAsync(api, MarketSymbols.ToArray(), true);
2121

2222
return await api.GetTradesWebSocketAsync(message =>
2323
{

0 commit comments

Comments
 (0)