private void SetQuote(Quote quote, bool isAggregate) { CheckQuote(quote); Quote outOfDepthQuote = null; lock (_syncRoot) { var quotes = GetQuotes(quote.OrderDirection); var index = GetQuoteIndex(quotes, quote.Price); if (index != -1) { if (isAggregate) { var existedQuote = quotes[index]; if (UseAggregatedQuotes) { var aggQuote = existedQuote as AggregatedQuote; if (aggQuote == null) { aggQuote = new AggregatedQuote { Price = quote.Price, Security = quote.Security, OrderDirection = quote.OrderDirection }; aggQuote.InnerQuotes.Add(existedQuote); quotes[index] = aggQuote; } aggQuote.InnerQuotes.Add(quote); } else { existedQuote.Volume += quote.Volume; } } else { quotes[index] = quote; } } else { for (index = 0; index < quotes.Length; index++) { var currentPrice = quotes[index].Price; if (quote.OrderDirection == Sides.Buy) { if (quote.Price > currentPrice) { break; } } else { if (quote.Price < currentPrice) { break; } } } Array.Resize(ref quotes, quotes.Length + 1); if (index < (quotes.Length - 1)) { Array.Copy(quotes, index, quotes, index + 1, quotes.Length - 1 - index); } quotes[index] = quote; if (quotes.Length > MaxDepth) { outOfDepthQuote = quotes[quotes.Length - 1]; quotes = RemoveAt(quotes, quotes.Length - 1); } if (quote.OrderDirection == Sides.Buy) { Bids = quotes; } else { Asks = quotes; } } UpdateDepthAndTime(); if (quotes.Length > MaxDepth) { throw new InvalidOperationException(LocalizedStrings.Str486Params.Put(MaxDepth, quotes.Length)); } } RaiseQuotesChanged(); if (outOfDepthQuote != null) { QuoteOutOfDepth.SafeInvoke(outOfDepthQuote); } }
/// <summary> /// To refresh the quote. If a quote with the same price is already in the order book, it is updated as passed. Otherwise, it automatically rebuilds the order book. /// </summary> /// <param name="quote">The new quote.</param> public void UpdateQuote(Quote quote) { SetQuote(quote, false); }
/// <summary> /// To add the quote. If a quote with the same price is already in the order book, they are combined into the <see cref="AggregatedQuote"/>. /// </summary> /// <param name="quote">The new quote.</param> public void AddQuote(Quote quote) { SetQuote(quote, true); }
public static QuoteChange ToQuoteChange(this Quote quote) { return(new QuoteChange(quote.Price, quote.Volume, quote.OrdersCount, quote.Condition)); }