Skip to content

Commit

Permalink
NDAX: fix Trades websocket (#534)
Browse files Browse the repository at this point in the history
- there is a bug in OnGetTickersAsync() which will need to be fixed at some point
- changed OnGetMarketSymbolsMetadataAsync() to fill in _marketSymbolToInstrumentIdMapping
- changed EnsureInstrumentIdsAvailable() to use OnGetMarketSymbolsMetadataAsync() instead
- fixes OnGetTradesWebSocketAsync()
  • Loading branch information
vslee authored Apr 15, 2020
1 parent d2d2ecf commit 9415b28
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/ExchangeSharp/API/Exchanges/NDAX/ExchangeNDAXAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ protected internal override async Task<IEnumerable<ExchangeMarket>> OnGetMarketS
var result = await MakeJsonRequestAsync<IEnumerable<Instrument>>("GetInstruments", null,
new Dictionary<string, object>()
{ {"OMSId", 1}}, "POST");

return result.Select(instrument => instrument.ToExchangeMarket());
_marketSymbolToInstrumentIdMapping = result.ToDictionary(keySelector: instrument => instrument.Symbol.Replace("_", ""),
elementSelector: instrument => instrument.InstrumentId);
return result.Select(instrument => instrument.ToExchangeMarket());
}

protected override async Task<IEnumerable<ExchangeOrderResult>> OnGetCompletedOrderDetailsAsync(string symbol = null,
Expand Down Expand Up @@ -325,7 +326,7 @@ private async Task EnsureInstrumentIdsAvailable()
{
if (_marketSymbolToInstrumentIdMapping == null)
{
await GetTickersAsync();
await OnGetMarketSymbolsMetadataAsync();
}
}

Expand Down Expand Up @@ -421,11 +422,14 @@ 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);

long?[] instrumentIds;
if (marketSymbols == null || marketSymbols.Length == 0)
instrumentIds = (await GetMarketSymbolsMetadataAsync()).Select(s => (long?)long.Parse(s.AltMarketSymbol)).ToArray();
else
{
await EnsureInstrumentIdsAvailable();
instrumentIds = await GetInstrumentIdFromMarketSymbol(marketSymbols);
}
return await ConnectWebSocketAsync("", async (socket, bytes) =>
{
var messageFrame =
Expand Down

0 comments on commit 9415b28

Please sign in to comment.