From 38473627163ef16b8d610b144751bd5a62957367 Mon Sep 17 00:00:00 2001 From: Simon Riis Olesen Date: Thu, 28 Mar 2024 16:40:11 +0100 Subject: [PATCH] "Extended IOKXSocketClientUnifiedApiExchangeData to give the possibility to subscribe on ticker updates for mutiple symbols. (#34) Ex: { "op": "subscribe", "args": [ { "channel": "tickers", "instId": "BTC-USDT" } , { "channel": "tickers", "instId": "BTC-BRL" } ] }" [feat/add-support-for-subscribe-on-multiple-symbols 911565e] Extended IOKXSocketClientUnifiedApiExchangeData to give the possibility to subscribe on ticker updates for multiple symbols. Ex: { op: subscribe, args: [ { channel: tickers, instId: BTC-USDT } , { channel: tickers, instId: BTC-BRL } ] } --- .../OKXSocketClientUnifiedApiExchangeData.cs | 17 +++++++++++++++++ .../IOKXSocketClientUnifiedApiExchangeData.cs | 11 +++++++++++ 2 files changed, 28 insertions(+) diff --git a/OKX.Net/Clients/UnifiedApi/OKXSocketClientUnifiedApiExchangeData.cs b/OKX.Net/Clients/UnifiedApi/OKXSocketClientUnifiedApiExchangeData.cs index cc5b76d..aff4fc1 100644 --- a/OKX.Net/Clients/UnifiedApi/OKXSocketClientUnifiedApiExchangeData.cs +++ b/OKX.Net/Clients/UnifiedApi/OKXSocketClientUnifiedApiExchangeData.cs @@ -54,6 +54,23 @@ public virtual async Task> SubscribeToTickerUpdat return await _client.SubscribeInternalAsync(_client.GetUri("/ws/v5/public"), subscription, ct).ConfigureAwait(false); } + + /// + public virtual async Task> SubscribeToTickerUpdatesAsync(IEnumerable symbols, Action> onData, CancellationToken ct = default) + { + var symbolSubs = symbols.Select(symbol => + new Objects.Sockets.Models.OKXSocketArgs + { + Channel = "tickers", + Symbol = symbol + } + ).ToList(); + + var subscription = new OKXSubscription(_logger, symbolSubs , onData, null, false); + + return await _client.SubscribeInternalAsync(_client.GetUri("/ws/v5/public"), subscription, ct).ConfigureAwait(false); + } + /// public virtual async Task> SubscribeToOpenInterestUpdatesAsync(string symbol, Action> onData, CancellationToken ct = default) { diff --git a/OKX.Net/Interfaces/Clients/UnifiedApi/IOKXSocketClientUnifiedApiExchangeData.cs b/OKX.Net/Interfaces/Clients/UnifiedApi/IOKXSocketClientUnifiedApiExchangeData.cs index f0b76f9..a96413a 100644 --- a/OKX.Net/Interfaces/Clients/UnifiedApi/IOKXSocketClientUnifiedApiExchangeData.cs +++ b/OKX.Net/Interfaces/Clients/UnifiedApi/IOKXSocketClientUnifiedApiExchangeData.cs @@ -162,6 +162,17 @@ public interface IOKXSocketClientUnifiedApiExchangeData /// Task> SubscribeToTickerUpdatesAsync(string symbol, Action> onData, CancellationToken ct = default); + + /// + /// Subscribe to the last traded price updates, bid price, ask price and 24-hour trading volume of instruments. Data will be pushed every 100 ms. + /// + /// + /// Symbol + /// On Data Handler + /// Cancellation Token + /// + Task> SubscribeToTickerUpdatesAsync(IEnumerable symbols, Action> onData, CancellationToken ct = default); + /// /// Subscribe to the recent trades data updates. Data will be pushed whenever there is a trade. ///