Skip to content

NDAX: fix Trades websocket #534

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

Merged
merged 1 commit into from
Apr 15, 2020
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: 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