public InnerQuotesList(AggregatedQuote parent)
            {
                if (parent == null)
                {
                    throw new ArgumentNullException("parent");
                }

                _parent = parent;
            }
        /// <summary>
        /// Create a copy of <see cref="AggregatedQuote"/>.
        /// </summary>
        /// <returns>Copy.</returns>
        public override Quote Clone()
        {
            var clone = new AggregatedQuote(_checkInnerPrice)
            {
                Security       = Security,
                Price          = Price,
                OrderDirection = OrderDirection
            };

            clone.InnerQuotes.AddRange(InnerQuotes.Select(q => q.Clone()));
            return(clone);
        }
Beispiel #3
0
        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);
            }
        }
 public InnerQuotesList(AggregatedQuote parent)
 {
     _parent = parent ?? throw new ArgumentNullException(nameof(parent));
 }