diff --git a/src/ExchangeSharp/Model/ExchangeOrderBook.cs b/src/ExchangeSharp/Model/ExchangeOrderBook.cs index 23a9f77f..4446c603 100644 --- a/src/ExchangeSharp/Model/ExchangeOrderBook.cs +++ b/src/ExchangeSharp/Model/ExchangeOrderBook.cs @@ -195,5 +195,30 @@ public decimal GetPriceToSell(decimal amount) return sellPrice; } + + /// + /// Updates this order book with a partial order book update. items with a price-level + /// of 0 are removed from the orderbook, all others are inserted/updated with the supplied value + /// + /// Set of changes to make + public void ApplyUpdates(ExchangeOrderBook partialUpdate) + { + MergeOrderBookDelta(partialUpdate.Asks, this.Asks); + MergeOrderBookDelta(partialUpdate.Bids, this.Bids); + + static void MergeOrderBookDelta( + SortedDictionary newData, + SortedDictionary bookData) + { + newData.ToList().ForEach(x => + { + if (x.Value.Amount == 0m) + bookData.Remove(x.Key); + else + bookData[x.Key] = x.Value; + }); + } + + } } }