diff --git a/src/ExchangeSharp/API/Exchanges/_Base/ExchangeAPIExtensions.cs b/src/ExchangeSharp/API/Exchanges/_Base/ExchangeAPIExtensions.cs index 54a1da06..d248e89b 100644 --- a/src/ExchangeSharp/API/Exchanges/_Base/ExchangeAPIExtensions.cs +++ b/src/ExchangeSharp/API/Exchanges/_Base/ExchangeAPIExtensions.cs @@ -52,21 +52,6 @@ public static async Task GetFullOrderBookWebSocketAsync(this IOrderB ConcurrentDictionary fullBooks = new ConcurrentDictionary(); Dictionary> partialOrderBookQueues = new Dictionary>(); - static void applyDelta(SortedDictionary deltaValues, SortedDictionary bookToEdit) - { - foreach (ExchangeOrderPrice record in deltaValues.Values) - { - if (record.Amount <= 0 || record.Price <= 0) - { - bookToEdit.Remove(record.Price); - } - else - { - bookToEdit[record.Price] = record; - } - } - } - static void updateOrderBook(ExchangeOrderBook fullOrderBook, ExchangeOrderBook freshBook) { lock (fullOrderBook) @@ -74,9 +59,7 @@ static void updateOrderBook(ExchangeOrderBook fullOrderBook, ExchangeOrderBook f // update deltas as long as the full book is at or before the delta timestamp if (fullOrderBook.SequenceId <= freshBook.SequenceId) { - applyDelta(freshBook.Asks, fullOrderBook.Asks); - applyDelta(freshBook.Bids, fullOrderBook.Bids); - fullOrderBook.SequenceId = freshBook.SequenceId; + fullOrderBook.ApplyUpdates(freshBook); } } } diff --git a/src/ExchangeSharp/Model/ExchangeOrderBook.cs b/src/ExchangeSharp/Model/ExchangeOrderBook.cs index 4446c603..8ce612ae 100644 --- a/src/ExchangeSharp/Model/ExchangeOrderBook.cs +++ b/src/ExchangeSharp/Model/ExchangeOrderBook.cs @@ -205,14 +205,15 @@ public void ApplyUpdates(ExchangeOrderBook partialUpdate) { MergeOrderBookDelta(partialUpdate.Asks, this.Asks); MergeOrderBookDelta(partialUpdate.Bids, this.Bids); + SequenceId = partialUpdate.SequenceId; - static void MergeOrderBookDelta( + static void MergeOrderBookDelta( SortedDictionary newData, SortedDictionary bookData) { newData.ToList().ForEach(x => { - if (x.Value.Amount == 0m) + if (x.Value.Amount <= 0m || x.Value.Price <= 0m) bookData.Remove(x.Key); else bookData[x.Key] = x.Value;