1
0
mirror of https://github.com/JKorf/CryptoExchange.Net.git synced 2026-08-20 04:42:57 +00:00

Ticking price event

This commit is contained in:
Ben Davison
2019-12-11 13:26:13 +00:00
parent a525709562
commit e7ec10e98d
3 changed files with 186 additions and 3 deletions
@@ -51,7 +51,7 @@ namespace CryptoExchange.Net.OrderBook
/// <summary>
/// The status of the order book. Order book is up to date when the status is `Synced`
/// </summary>
public OrderBookStatus Status
public OrderBookStatus Status
{
get => status;
set
@@ -79,6 +79,12 @@ namespace CryptoExchange.Net.OrderBook
/// Event when the state changes
/// </summary>
public event Action<OrderBookStatus, OrderBookStatus>? OnStatusChange;
/// <summary>
/// Event when the BestBid or BestAsk changes ie a Pricing Tick
/// </summary>
public event Action<ISymbolOrderBookEntry, ISymbolOrderBookEntry>? OnPriceChanged;
/// <summary>
/// Event when order book was updated, containing the changed bids and asks. Be careful! It can generate a lot of events at high-liquidity markets
/// </summary>
@@ -112,7 +118,7 @@ namespace CryptoExchange.Net.OrderBook
/// <summary>
/// The list of bids
/// </summary>
public IEnumerable<ISymbolOrderBookEntry> Bids
public IEnumerable<ISymbolOrderBookEntry> Bids
{
get
{
@@ -136,7 +142,7 @@ namespace CryptoExchange.Net.OrderBook
/// <summary>
/// The best ask currently in the order book
/// </summary>
public ISymbolOrderBookEntry BestAsk
public ISymbolOrderBookEntry BestAsk
{
get
{
@@ -286,9 +292,16 @@ namespace CryptoExchange.Net.OrderBook
log.Write(LogVerbosity.Debug, $"{Id} order book {Symbol} data set: {BidCount} bids, {AskCount} asks. #{orderBookSequenceNumber}");
CheckProcessBuffer();
OnOrderBookUpdate?.Invoke(bidList, askList);
OnPriceChanged?.Invoke(BestBid, BestAsk);
}
}
private bool BestPricingUpdated(ISymbolOrderBookEntry prevBestBid, ISymbolOrderBookEntry prevBestAsk)
{
return BestBid.Price != prevBestBid.Price || BestBid.Quantity != prevBestBid.Quantity ||
BestAsk.Price != prevBestAsk.Price || BestAsk.Quantity != prevBestAsk.Quantity;
}
/// <summary>
/// Update the order book using a single id for an update
/// </summary>
@@ -315,8 +328,12 @@ namespace CryptoExchange.Net.OrderBook
else
{
CheckProcessBuffer();
var prevBestBid = BestBid;
var prevBestAsk = BestAsk;
ProcessSingleSequenceUpdates(rangeUpdateId, bids, asks);
OnOrderBookUpdate?.Invoke(bids, asks);
if (BestPricingUpdated(prevBestBid, prevBestAsk))
OnPriceChanged?.Invoke(BestBid, BestAsk);
}
}
}
@@ -349,8 +366,12 @@ namespace CryptoExchange.Net.OrderBook
else
{
CheckProcessBuffer();
var prevBestBid = BestBid;
var prevBestAsk = BestAsk;
ProcessRangeUpdates(firstUpdateId, lastUpdateId, bids, asks);
OnOrderBookUpdate?.Invoke(bids, asks);
if (BestPricingUpdated(prevBestBid, prevBestAsk))
OnPriceChanged?.Invoke(BestBid, BestAsk);
}
}
}
@@ -376,8 +397,13 @@ namespace CryptoExchange.Net.OrderBook
else
{
CheckProcessBuffer();
var prevBestBid = BestBid;
var prevBestAsk = BestAsk;
ProcessUpdates(bids, asks);
OnOrderBookUpdate?.Invoke(bids, asks);
if (BestPricingUpdated(prevBestBid, prevBestAsk))
OnPriceChanged?.Invoke(BestBid, BestAsk);
}
}
}