Skip to content

Commit 6bdffbd

Browse files
authored
Add simple orderbook merging from updates (#627)
* Fix Kraken WS orderbook updates and add checksum support * Update ExchangeOrderBook.cs
1 parent 6f249be commit 6bdffbd

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/ExchangeSharp/Model/ExchangeOrderBook.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,5 +195,30 @@ public decimal GetPriceToSell(decimal amount)
195195

196196
return sellPrice;
197197
}
198+
199+
/// <summary>
200+
/// Updates this order book with a partial order book update. items with a price-level
201+
/// of 0 are removed from the orderbook, all others are inserted/updated with the supplied value
202+
/// </summary>
203+
/// <param name="partialUpdate">Set of changes to make</param>
204+
public void ApplyUpdates(ExchangeOrderBook partialUpdate)
205+
{
206+
MergeOrderBookDelta(partialUpdate.Asks, this.Asks);
207+
MergeOrderBookDelta(partialUpdate.Bids, this.Bids);
208+
209+
static void MergeOrderBookDelta(
210+
SortedDictionary<decimal, ExchangeOrderPrice> newData,
211+
SortedDictionary<decimal, ExchangeOrderPrice> bookData)
212+
{
213+
newData.ToList().ForEach(x =>
214+
{
215+
if (x.Value.Amount == 0m)
216+
bookData.Remove(x.Key);
217+
else
218+
bookData[x.Key] = x.Value;
219+
});
220+
}
221+
222+
}
198223
}
199224
}

0 commit comments

Comments
 (0)