Exemplo n.º 1
0
        private void UpdateIfDepthDirty()
        {
            IEnumerable <MarketDepthPair> top = null;

            lock (_lastDepthSync)
            {
                if (_needToClear)
                {
                    _needToClear = false;
                    top          = Enumerable.Empty <MarketDepthPair>();
                }
                else if (_lastDepth != null)
                {
                    top = _lastDepth.GetTopPairs(MaxDepth);
                }
                else if (_lastQuoteMsg != null)
                {
                    top = _lastQuoteMsg.ToMarketDepth(_prevSecurity).GetTopPairs(MaxDepth);
                }

                _lastDepth = null;
            }

            if (top == null)
            {
                return;
            }

            var index = 0;

            foreach (var pair in top)
            {
                var bid = _quotes[GetQuoteIndex(Sides.Buy, index)];
                if (pair.Bid != null)
                {
                    bid.Init(pair.Bid, _ordersRegistry.GetContainer(pair.Bid.Price), _stopOrdersRegistry.GetContainer(pair.Bid.Price) /*, trades.TryGetValue(pair.Bid.Price), myTrades.TryGetValue(pair.Bid.Price)*/);
                    bid.IsBest = index == 0;
                }
                else
                {
                    bid.Init();
                }

                var ask = _quotes[GetQuoteIndex(Sides.Sell, index)];
                if (pair.Ask != null)
                {
                    ask.Init(pair.Ask, _ordersRegistry.GetContainer(pair.Ask.Price), _stopOrdersRegistry.GetContainer(pair.Ask.Price) /*, trades.TryGetValue(pair.Ask.Price), myTrades.TryGetValue(pair.Ask.Price)*/);
                    ask.IsBest = index == 0;
                }
                else
                {
                    ask.Init();
                }

                index++;
            }

            for (var i = 0; i < (MaxDepth - index); i++)
            {
                _quotes[GetQuoteIndex(Sides.Buy, index + i)].Init();
                _quotes[GetQuoteIndex(Sides.Sell, index + i)].Init();
            }
        }