Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NDAX: fix symbol separator bug #498

Merged
merged 1 commit into from
Nov 27, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/ExchangeSharp/API/Exchanges/NDAX/ExchangeNDAXAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected override async Task<IEnumerable<KeyValuePair<string, ExchangeTicker>>>
{
var result =
await MakeJsonRequestAsync<Dictionary<string, NDAXTicker>>("returnticker", "https://ndax.io/api", null, "GET");
_marketSymbolToInstrumentIdMapping = result.ToDictionary(pair => pair.Key, pair => pair.Value.Id);
_marketSymbolToInstrumentIdMapping = result.ToDictionary(pair => pair.Key.Replace("_", ""), pair => pair.Value.Id); // remove the _
return result.Select(pair =>
new KeyValuePair<string, ExchangeTicker>(pair.Key, pair.Value.ToExchangeTicker(pair.Key)));
}
Expand Down Expand Up @@ -345,12 +345,16 @@ private async Task EnsureInstrumentIdsAvailable()
{
marketSymbol = marketSymbol.ToUpperInvariant();
await EnsureInstrumentIdsAvailable();
if (_marketSymbolToInstrumentIdMapping.TryGetValue(marketSymbol, out var value))
{
return value;
}

return null;
if (_marketSymbolToInstrumentIdMapping.TryGetValue(marketSymbol, out var value))
{
return value;
}
else if (_marketSymbolToInstrumentIdMapping.TryGetValue(marketSymbol.Replace("_", ""), out var value2))
{ // try again w/o the _
return value2;
}

return null;
}

private async Task<long?[]> GetInstrumentIdFromMarketSymbol(string[] marketSymbols)
Expand All @@ -367,6 +371,7 @@ private async Task<string> GetMarketSymbolFromInstrumentId(long instrumentId)

protected override async Task<IWebSocket> OnGetTickersWebSocketAsync(Action<IReadOnlyCollection<KeyValuePair<string, ExchangeTicker>>> tickers, params string[] marketSymbols)
{
await EnsureInstrumentIdsAvailable();
var instrumentIds = marketSymbols == null || marketSymbols.Length == 0 ?
(await GetMarketSymbolsMetadataAsync()).Select(s => (long?)long.Parse(s.AltMarketSymbol)).ToArray() :
await GetInstrumentIdFromMarketSymbol(marketSymbols);
Expand Down Expand Up @@ -416,6 +421,7 @@ await socket.SendMessageAsync(new MessageFrame

protected override async Task<IWebSocket> OnGetTradesWebSocketAsync(Func<KeyValuePair<string, ExchangeTrade>, Task> callback, params string[] marketSymbols)
{
await EnsureInstrumentIdsAvailable();
var instrumentIds = marketSymbols == null || marketSymbols.Length == 0 ?
(await GetMarketSymbolsMetadataAsync()).Select(s => (long?)long.Parse(s.AltMarketSymbol)).ToArray() :
await GetInstrumentIdFromMarketSymbol(marketSymbols);
Expand Down