Exemple #1
0
        public void Clear()
        {
            _securityData.Clear();

            _allOrdersById.Clear();
            _allOrdersByStringId.Clear();
            _allOrdersByTransactionId.Clear();
            _orders.Clear();

            _newsById.Clear();
            _newsWithoutId.Clear();

            _myTrades.Clear();

            _trades.Clear();
            _tradeStat.Clear(true);

            _orderStatusTransactions.Clear();
            _massCancelationTransactions.Clear();

            _exchangeBoards.Clear();
            _securities.Clear();

            _orderCancelFails.Clear();
            _orderRegisterFails.Clear();

            _positions.Clear();
        }
            public void Stop()
            {
                lock (_data.SyncRoot)
                {
                    _data.Clear();
                    _dataVersion++;

                    switch (_currState)
                    {
                    case States.Starting:
                        _currState = States.Stopping;
                        break;

                    case States.Started:
                        //_currState = States.Stopping;
                        _response.Close();
                        break;

                    case States.Stopping:
                    case States.Stopped:
                        return;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
            }
        /// <summary>
        /// To clear active objects <see cref="ObjectCount"/>.
        /// </summary>
        /// <param name="resetCounter">Whether to clear the objects counter.</param>
        public void Clear(bool resetCounter = false)
        {
            if (resetCounter)
            {
                _objectCount = 0;
            }

            if (!IsObjectTracking)
            {
                return;
            }

            // TODO: WeakReference?
            _objects.Clear();
        }
        private void ProcessReset(Message message)
        {
            _hearbeatAdapters.Values.ForEach(a =>
            {
                a.SendInMessage(message);
                a.Dispose();
            });

            _connectedAdapters.Clear();
            _messageTypeAdapters.Clear();
            _hearbeatAdapters.Clear();
            _subscriptionQueue.Clear();
            _subscriptions.Clear();
            _subscriptionKeys.Clear();
            _subscriptionStates.Clear();
        }
        /// <inheritdoc />
        protected override bool OnSendInMessage(Message message)
        {
            switch (message.Type)
            {
            case MessageTypes.Reset:
            {
                lock (_syncObject)
                {
                    _byId.Clear();
                    _online.Clear();
                    _passThrough.Clear();
                    _allSecSubscriptions.Clear();
                    _allSecSubscriptionsPassThrough.Clear();
                }

                break;
            }

            case MessageTypes.MarketData:
            {
                var mdMsg = (MarketDataMessage)message;

                if (mdMsg.IsSubscribe)
                {
                    if (mdMsg.DataType2 == DataType.MarketDepth)
                    {
                        var transId = mdMsg.TransactionId;

                        lock (_syncObject)
                        {
                            if (mdMsg.SecurityId == default)
                            {
                                if (mdMsg.DoNotBuildOrderBookInrement)
                                {
                                    _allSecSubscriptionsPassThrough.Add(transId);
                                }
                                else
                                {
                                    _allSecSubscriptions.Add(transId);
                                }

                                break;
                            }

                            if (mdMsg.DoNotBuildOrderBookInrement)
                            {
                                _passThrough.Add(transId);
                                break;
                            }

                            var info = new BookInfo(mdMsg.SecurityId)
                            {
                                Builder = { Parent = this }
                            };

                            info.SubscriptionIds.Add(transId);

                            _byId.Add(transId, info);
                        }

                        this.AddInfoLog("OB incr subscribed {0}/{1}.", mdMsg.SecurityId, transId);
                    }
                }
                else
                {
                    RemoveSubscription(mdMsg.OriginalTransactionId);
                }

                break;
            }
            }

            return(base.OnSendInMessage(message));
        }
        /// <inheritdoc />
        protected override bool OnSendInMessage(Message message)
        {
            switch (message.Type)
            {
            case MessageTypes.Reset:
            {
                _subscriptions.Clear();
                _strategyIdMap.Clear();
                _strategySubscriptions.Clear();

                lock (_sync)
                    _positionManager.ProcessMessage(message);

                break;
            }

            case MessageTypes.PortfolioLookup:
            {
                var lookupMsg = (PortfolioLookupMessage)message;

                if (lookupMsg.IsSubscribe)
                {
                    if (!lookupMsg.StrategyId.IsEmpty())
                    {
                        this.AddDebugLog("Subscription (strategy='{1}') {0} added.", lookupMsg.TransactionId, lookupMsg.StrategyId);
                        _strategyIdMap.Add(lookupMsg.TransactionId, lookupMsg.StrategyId);
                        _strategySubscriptions.SafeAdd(lookupMsg.StrategyId).Add(lookupMsg.TransactionId);
                        RaiseNewOutMessage(lookupMsg.CreateResult());
                        return(true);
                    }

                    if (lookupMsg.To == null)
                    {
                        this.AddDebugLog("Subscription {0} added.", lookupMsg.TransactionId);
                        _subscriptions.Add(lookupMsg.TransactionId);

                        lock (_sync)
                            _positionManager.ProcessMessage(message);
                    }

                    if (IsEmulate)
                    {
                        RaiseNewOutMessage(lookupMsg.CreateResult());
                        return(true);
                    }
                }
                else
                {
                    if (_subscriptions.Remove(lookupMsg.OriginalTransactionId))
                    {
                        this.AddDebugLog("Subscription {0} removed.", lookupMsg.OriginalTransactionId);

                        lock (_sync)
                            _positionManager.ProcessMessage(message);
                    }
                    else if (_strategyIdMap.TryGetAndRemove(lookupMsg.OriginalTransactionId, out var strategyId))
                    {
                        _strategySubscriptions.TryGetValue(strategyId)?.Remove(lookupMsg.OriginalTransactionId);
                        this.AddDebugLog("Subscription (strategy='{1}') {0} removed.", lookupMsg.OriginalTransactionId, strategyId);
                        return(true);
                    }

                    if (IsEmulate)
                    {
                        //RaiseNewOutMessage(lookupMsg.CreateResponse());
                        return(true);
                    }
                }

                break;
            }

            default:
            {
                lock (_sync)
                    _positionManager.ProcessMessage(message);

                break;
            }
            }

            return(base.OnSendInMessage(message));
        }
        private void UnderlyingAsset_OnSecuritySelected()
        {
            var security = UnderlyingAsset.SelectedSecurity;

            if (_currentSecurity == security)
            {
                return;
            }

            if (_currentSecurity != null)
            {
                foreach (var option in _options.Cache)
                {
                    new RefuseMarketDataCommand(option, MarketDataTypes.Level1).Process(this);
                }

                new RefuseMarketDataCommand(_currentSecurity, MarketDataTypes.Level1).Process(this);

                _currentSecurity = null;

                _options.Clear();

                Desk.Options = Enumerable.Empty <Security>();
                Desk.RefreshOptions();

                _minAssetPrice = _maxAssetPrice = 0;
                //_minDate = _maxDate = default(DateTime);

                Process(() =>
                {
                    CurrentDate.Minimum = null;
                    CurrentDate.Maximum = null;

                    AssetPriceModified.Value  = 0;
                    AssetPriceReset.IsEnabled = false;

                    CurrentDateModified.Value  = 0;
                    CurrentDateReset.IsEnabled = false;
                });
            }

            _currentSecurity = security;

            if (_currentSecurity != null)
            {
                _options.AddRange(GetOptions());

                foreach (var option in _options.Cache)
                {
                    new RequestMarketDataCommand(option, MarketDataTypes.Level1).Process(this);
                }

                new RequestMarketDataCommand(_currentSecurity, MarketDataTypes.Level1).Process(this);

                Desk.Options = _options.Cache;
                Desk.RefreshOptions();

                SetPriceLimits();
                SetDateLimits();
            }

            Title = LocalizedStrings.Str3265 + " " + _currentSecurity;
        }