Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 1 addition & 18 deletions src/ExchangeSharp/API/Exchanges/_Base/ExchangeAPIExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,31 +52,14 @@ public static async Task<IWebSocket> GetFullOrderBookWebSocketAsync(this IOrderB
ConcurrentDictionary<string, ExchangeOrderBook> fullBooks = new ConcurrentDictionary<string, ExchangeOrderBook>();
Dictionary<string, Queue<ExchangeOrderBook>> partialOrderBookQueues = new Dictionary<string, Queue<ExchangeOrderBook>>();

static void applyDelta(SortedDictionary<decimal, ExchangeOrderPrice> deltaValues, SortedDictionary<decimal, ExchangeOrderPrice> 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)
{
// 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);
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/ExchangeSharp/Model/ExchangeOrderBook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<decimal, ExchangeOrderPrice> newData,
SortedDictionary<decimal, ExchangeOrderPrice> 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;
Expand Down