From 928a1bf1003383d495a24e5368a711c5d266a5b7 Mon Sep 17 00:00:00 2001 From: Jonnern <10881387+Jonnern@users.noreply.github.com> Date: Wed, 3 Apr 2024 10:39:00 +0200 Subject: [PATCH] Add diffUpdates as optional argument to book subscription --- CoinEx.Net/Clients/SpotApi/CoinExSocketClientSpotApi.cs | 4 ++-- .../Interfaces/Clients/SpotApi/ICoinExSocketClientSpotApi.cs | 3 ++- CoinEx.Net/SymbolOrderBooks/CoinExSpotSymbolOrderBook.cs | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CoinEx.Net/Clients/SpotApi/CoinExSocketClientSpotApi.cs b/CoinEx.Net/Clients/SpotApi/CoinExSocketClientSpotApi.cs index 2811530..4ae8d20 100644 --- a/CoinEx.Net/Clients/SpotApi/CoinExSocketClientSpotApi.cs +++ b/CoinEx.Net/Clients/SpotApi/CoinExSocketClientSpotApi.cs @@ -181,13 +181,13 @@ public async Task> SubscribeToAllTickerUpdatesAsy } /// - public async Task> SubscribeToOrderBookUpdatesAsync(string symbol, int limit, int mergeDepth, Action> onMessage, CancellationToken ct = default) + public async Task> SubscribeToOrderBookUpdatesAsync(string symbol, int limit, int mergeDepth, Action> onMessage, bool diffUpdates, CancellationToken ct = default) { symbol.ValidateCoinExSymbol(); mergeDepth.ValidateIntBetween(nameof(mergeDepth), 0, 8); limit.ValidateIntValues(nameof(limit), 5, 10, 20); - var subscription = new CoinExDepthSubscription(_logger, symbol, new object[] { symbol, limit, CoinExHelpers.MergeDepthIntToString(mergeDepth), true }, onMessage); + var subscription = new CoinExDepthSubscription(_logger, symbol, new object[] { symbol, limit, CoinExHelpers.MergeDepthIntToString(mergeDepth), diffUpdates }, onMessage); return await SubscribeAsync(subscription, ct).ConfigureAwait(false); } diff --git a/CoinEx.Net/Interfaces/Clients/SpotApi/ICoinExSocketClientSpotApi.cs b/CoinEx.Net/Interfaces/Clients/SpotApi/ICoinExSocketClientSpotApi.cs index 63c6e18..60db0a3 100644 --- a/CoinEx.Net/Interfaces/Clients/SpotApi/ICoinExSocketClientSpotApi.cs +++ b/CoinEx.Net/Interfaces/Clients/SpotApi/ICoinExSocketClientSpotApi.cs @@ -76,9 +76,10 @@ public interface ICoinExSocketClientSpotApi : ISocketApiClient, IDisposable /// The limit of results to receive in a update /// The depth of merging, based on 8 decimals. 1 mergeDepth will merge the last decimals of all order in the book, 7 will merge the last 7 decimals of all orders together /// Data handler + /// Set to true to get snapshot first, then diff updates /// Cancellation token for closing this subscription /// A stream subscription. This stream subscription can be used to be notified when the socket is disconnected/reconnected - Task> SubscribeToOrderBookUpdatesAsync(string symbol, int limit, int mergeDepth, Action> onMessage, CancellationToken ct = default); + Task> SubscribeToOrderBookUpdatesAsync(string symbol, int limit, int mergeDepth, Action> onMessage, bool diffUpdates = false, CancellationToken ct = default); /// /// Gets the latest trades on a symbol diff --git a/CoinEx.Net/SymbolOrderBooks/CoinExSpotSymbolOrderBook.cs b/CoinEx.Net/SymbolOrderBooks/CoinExSpotSymbolOrderBook.cs index b98a58e..7337222 100644 --- a/CoinEx.Net/SymbolOrderBooks/CoinExSpotSymbolOrderBook.cs +++ b/CoinEx.Net/SymbolOrderBooks/CoinExSpotSymbolOrderBook.cs @@ -64,7 +64,7 @@ public CoinExSpotSymbolOrderBook(string symbol, /// protected override async Task> DoStartAsync(CancellationToken ct) { - var result = await _socketClient.SpotApi.SubscribeToOrderBookUpdatesAsync(Symbol, Levels!.Value, 0, HandleUpdate).ConfigureAwait(false); + var result = await _socketClient.SpotApi.SubscribeToOrderBookUpdatesAsync(Symbol, Levels!.Value, 0, HandleUpdate, diffUpdates: true).ConfigureAwait(false); if (!result) return result;