Пример #1
0
        private OrderMarket OnOrderMarketChange(OrderMarketChange marketChange)
        {
            OrderMarket market = _markets.GetOrAdd(marketChange.Id, id => new OrderMarket(this, id));

            market.OnOrderMarketChange(marketChange);
            return(market);
        }
Пример #2
0
        public void OnOrderChange(ChangeMessage <OrderMarketChange> changeMessage)
        {
            if (changeMessage.IsStartOfNewSubscription)
            {
                //clear cache
                _markets.Clear();
            }
            if (changeMessage.Items != null)
            {
                //lazy build events
                List <OrderMarketChangedEventArgs> batch = BatchOrderMarketsChanged == null ? null : new List <OrderMarketChangedEventArgs>(changeMessage.Items.Count);

                foreach (OrderMarketChange marketChange in changeMessage.Items)
                {
                    bool isImage = marketChange.FullImage == true;
                    if (isImage)
                    {
                        // Clear market from cache if it is being re-imaged
                        OrderMarket removed;
                        _markets.TryRemove(marketChange.Id, out removed);
                    }

                    OrderMarket market = OnOrderMarketChange(marketChange);

                    if (IsOrderMarketRemovedOnClose && market.IsClosed)
                    {
                        //remove on close
                        OrderMarket removed;
                        _markets.TryRemove(market.MarketId, out removed);
                    }
                    //lazy build events
                    if (batch != null || OrderMarketChanged != null)
                    {
                        OrderMarketChangedEventArgs arg = new OrderMarketChangedEventArgs()
                        {
                            Change = marketChange, OrderMarket = market
                        };
                        if (OrderMarketChanged != null)
                        {
                            DispatchOrderMarketChanged(arg);
                        }
                        if (batch != null)
                        {
                            batch.Add(arg);
                        }
                    }
                }
                if (batch != null)
                {
                    DispatchBatchOrderMarketsChanged(new BatchOrderMarketsChangedEventArgs()
                    {
                        Changes = batch
                    });
                }
            }
        }
 public OrderMarketRunner(OrderMarket market, RunnerId runnerId)
 {
     _market   = market;
     _runnerId = runnerId;
 }