Exemple #1
0
        private bool CheckCondition(Security sec)
        {
            var filter  = SecurityFilter;
            var secType = SelectedType;

            return(!_excludeSecurities.Contains(sec) &&
                   (secType == null || sec.Type == secType) &&
                   (filter.IsEmpty() ||
                    (!sec.Code.IsEmpty() && sec.Code.ContainsIgnoreCase(filter)) ||
                    (!sec.Name.IsEmpty() && sec.Name.ContainsIgnoreCase(filter)) ||
                    (!sec.ShortName.IsEmpty() && sec.ShortName.ContainsIgnoreCase(filter)) ||
                    sec.Id.ContainsIgnoreCase(filter)));
        }
Exemple #2
0
        private bool AddOrder(Order o)
        {
            if (_chartOrders.Contains(o))
            {
                return(false);
            }

            _chartOrders.Add(o);
            Orders.Add(o);

            return(true);
        }
Exemple #3
0
 /// <summary>
 /// Whether contains the specified leg.
 /// </summary>
 /// <param name="securityId">Security ID.</param>
 /// <returns><see langword="true"/> if the leg exist, otherwise <see langword="false"/>.</returns>
 protected bool ContainsLeg(SecurityId securityId) => _basketLegs.Contains(securityId);
        /// <inheritdoc />
        protected override void OnInnerAdapterNewOutMessage(Message message)
        {
            List <QuoteChangeMessage> clones = null;

            switch (message.Type)
            {
            case MessageTypes.SubscriptionResponse:
            {
                var responseMsg = (SubscriptionResponseMessage)message;

                if (!responseMsg.IsOk())
                {
                    RemoveSubscription(responseMsg.OriginalTransactionId);
                }

                break;
            }

            case MessageTypes.SubscriptionFinished:
            {
                RemoveSubscription(((SubscriptionFinishedMessage)message).OriginalTransactionId);
                break;
            }

            case MessageTypes.SubscriptionOnline:
            {
                var id = ((SubscriptionOnlineMessage)message).OriginalTransactionId;

                lock (_syncObject)
                {
                    if (_byId.TryGetValue(id, out var info))
                    {
                        var secId = info.Builder.SecurityId;

                        if (_online.TryGetValue(secId, out var online))
                        {
                            online.SubscriptionIds.Add(id);
                            _byId.Remove(id);
                        }
                        else
                        {
                            _online.Add(secId, info);
                        }
                    }
                }

                break;
            }

            case MessageTypes.QuoteChange:
            {
                var quoteMsg = (QuoteChangeMessage)message;

                if (quoteMsg.State == null)
                {
                    break;
                }

                lock (_syncObject)
                {
                    if (_allSecSubscriptions.Count == 0 &&
                        _allSecSubscriptionsPassThrough.Count == 0 &&
                        _byId.Count == 0 &&
                        _passThrough.Count == 0 &&
                        _online.Count == 0)
                    {
                        break;
                    }
                }

                List <long> passThrough = null;

                foreach (var subscriptionId in quoteMsg.GetSubscriptionIds())
                {
                    QuoteChangeMessage newQuoteMsg;
                    long[]             ids;

                    lock (_syncObject)
                    {
                        if (!_byId.TryGetValue(subscriptionId, out var info))
                        {
                            if (_passThrough.Contains(subscriptionId) || _allSecSubscriptionsPassThrough.Contains(subscriptionId))
                            {
                                if (passThrough is null)
                                {
                                    passThrough = new List <long>();
                                }

                                passThrough.Add(subscriptionId);
                            }

                            continue;
                        }

                        newQuoteMsg = info.Builder.TryApply(quoteMsg, subscriptionId);

                        if (newQuoteMsg == null)
                        {
                            continue;
                        }

                        ids = info.SubscriptionIds.Cache;
                    }

                    if (_allSecSubscriptions.Count > 0)
                    {
                        ids = ids.Concat(_allSecSubscriptions.Cache);
                    }

                    if (clones == null)
                    {
                        clones = new List <QuoteChangeMessage>();
                    }

                    newQuoteMsg.SetSubscriptionIds(ids);
                    clones.Add(newQuoteMsg);
                }

                if (passThrough is null)
                {
                    message = null;
                }
                else
                {
                    quoteMsg.SetSubscriptionIds(passThrough.ToArray());
                }

                break;
            }
            }

            if (message != null)
            {
                base.OnInnerAdapterNewOutMessage(message);
            }

            if (clones != null)
            {
                foreach (var clone in clones)
                {
                    base.OnInnerAdapterNewOutMessage(clone);
                }
            }
        }
        private void OnSecuritiesChanged(IEnumerable <Security> securities)
        {
            if (_currentSecurity == null)
            {
                return;
            }

            var hasUnderlying = false;
            var hasStrikes    = false;

            var newStrikes = GetStrikes(securities)
                             .Where(s =>
            {
                var isOld = _options.Contains(s);

                if (!hasUnderlying)
                {
                    hasUnderlying = s == _currentSecurity;
                }

                if (!hasStrikes)
                {
                    hasStrikes = isOld;
                }

                return(!isOld);
            })
                             .ToArray();

            if (newStrikes.Length > 0)
            {
                _options.AddRange(newStrikes);

                SetDateLimits();

                Desk.Options = _options.Cache;

                lock (_needRefreshLock)
                    _needRefresh = true;

                if (_minAssetPrice == 0 && _maxAssetPrice == 0 && newStrikes.Contains(_currentSecurity))
                {
                    SetPriceLimits();
                }

                return;
            }

            if (!hasUnderlying && !hasStrikes)
            {
                return;
            }

            if (_minAssetPrice == 0 && _maxAssetPrice == 0)
            {
                SetPriceLimits();
            }

            lock (_needRefreshLock)
                _needRefresh = true;
        }