Пример #1
0
            public IEnumerable <Subscription> GetSubscriptions(ISubscriptionIdMessage message)
            {
                var time = message is IServerTimeMessage timeMsg ? timeMsg.ServerTime : (DateTimeOffset?)null;

                var processed = new HashSet <SubscriptionInfo>();

                foreach (var id in message.GetSubscriptionIds())
                {
                    var info = TryGetSubscription(id, false, false, time);

                    if (info == null)
                    {
                        continue;
                    }

                    if (!processed.Add(info))
                    {
                        continue;
                    }

                    if (info.Parent == null)
                    {
                        yield return(info.Subscription);
                    }
                    else
                    {
                        if (!processed.Add(info.Parent))
                        {
                            continue;
                        }

                        yield return(info.Parent.Subscription);
                    }
                }
            }
Пример #2
0
            public IEnumerable <Subscription> ProcessLookupResponse <T>(ISubscriptionIdMessage message, T[] items)
            {
                var subscriptions = new List <Subscription>();

                foreach (var id in message.GetSubscriptionIds())
                {
                    var info = TryGetInfo(id, true, false, null, true);

                    if (info == null || info.HasResult)
                    {
                        continue;
                    }

                    if (info.LookupItems == null)
                    {
                        _connector.AddWarningLog(LocalizedStrings.Str2142Params, info.Subscription.SubscriptionMessage);
                        continue;
                    }

                    info.LookupItems.AddRange(items.Cast <object>());
                    subscriptions.Add(info.Subscription);
                }

                return(subscriptions);
            }
Пример #3
0
 private void TrySendToEmulator(ISubscriptionIdMessage message)
 {
     foreach (var id in message.GetSubscriptionIds())
     {
         if (_subscriptionIds.Contains(id))
         {
             SendToEmulator((Message)message);
             break;
         }
     }
 }
Пример #4
0
            public IEnumerable <Subscription> GetSubscriptions(ISubscriptionIdMessage message)
            {
                var time = message is IServerTimeMessage timeMsg ? timeMsg.ServerTime : (DateTimeOffset?)null;

                foreach (var id in message.GetSubscriptionIds())
                {
                    var subscription = TryGetSubscription(id, true, false, time);

                    if (subscription != null)
                    {
                        yield return(subscription);
                    }
                }
            }
Пример #5
0
        private bool CanStore(ISubscriptionIdMessage message)
        {
            if (!Enabled)
            {
                return(false);
            }

            if (!FilterSubscription)
            {
                return(true);
            }

            return(message.GetSubscriptionIds().Any(_subscriptionsById.Contains));
        }
        private void ApplySubscriptionIds(ISubscriptionIdMessage message, ChildSubscription child)
        {
            var ids       = message.GetSubscriptionIds();
            var initialId = child.Parent.Origin.TransactionId;
            var newIds    = child.Subscribers.CachedKeys.Concat(child.Parent.Alls.CachedKeys);

            if (ids.Length == 1 && ids[0] == initialId)
            {
                message.SetSubscriptionIds(newIds);
            }
            else
            {
                message.SetSubscriptionIds(ids.Where(id => id != initialId).Concat(newIds).ToArray());
            }
        }
Пример #7
0
        private bool RaiseReceived <TEntity>(TEntity entity, ISubscriptionIdMessage message, Action <Subscription, TEntity> evt)
        {
            var anyOnline = false;

            foreach (var subscription in _subscriptionManager.GetSubscriptions(message))
            {
                if (!anyOnline && subscription.State == SubscriptionStates.Online)
                {
                    anyOnline = true;
                }

                evt?.Invoke(subscription, entity);
            }

            return(anyOnline);
        }
Пример #8
0
        private void RaiseReceived <TEntity>(TEntity entity, ISubscriptionIdMessage message, Action <Subscription, TEntity> evt)
        {
            if (evt == null)
            {
                return;
            }

            foreach (var id in message.GetSubscriptionIds())
            {
                if (!_subscriptions.TryGetValue(id, out var subscription))
                {
                    continue;
                }

                evt(subscription, entity);
            }
        }
Пример #9
0
        private void RaiseReceived <TEntity>(TEntity entity, ISubscriptionIdMessage message, Action <Subscription, TEntity> evt)
        {
            if (evt == null)
            {
                return;
            }

            foreach (var id in message.GetSubscriptionIds())
            {
                var subscription = TryGetSubscription(id);

                if (subscription != null)
                {
                    evt(subscription, entity);
                }
            }
        }
        private void ApplyTransactionalSubscriptionIds <TMessage>(ISubscriptionIdMessage message, Dictionary <long, SubscriptionInfo <TMessage> > lookupSubscribers)
            where TMessage : Message, ISubscriptionIdMessage
        {
            lock (_sync)
            {
                if (message.OriginalTransactionId > 0 && lookupSubscribers.ContainsKey(message.OriginalTransactionId))
                {
                    message.SubscriptionId = message.OriginalTransactionId;
                }

                if (_pfLookupSubscribers.Count == 0)
                {
                    return;
                }

                message.SubscriptionIds = lookupSubscribers.First().Value.Subscribers.Cache;
            }
        }
Пример #11
0
        private void RaiseReceived <TEntity>(TEntity entity, ISubscriptionIdMessage message, Action <Subscription, TEntity> evt)
        {
            if (evt == null)
            {
                return;
            }

            var time = message is IServerTimeMessage timeMsg ? timeMsg.ServerTime : (DateTimeOffset?)null;

            foreach (var id in message.GetSubscriptionIds())
            {
                var subscription = _subscriptionManager.TryGetSubscription(id, false, time);

                if (subscription != null)
                {
                    evt(subscription, entity);
                }
            }
        }
Пример #12
0
            public void ProcessLookupResponse(ISubscriptionIdMessage message, object item)
            {
                foreach (var id in message.GetSubscriptionIds())
                {
                    var info = TryGetInfo(id, false);

                    if (info == null)
                    {
                        continue;
                    }

                    if (info.Lookup == null)
                    {
                        _connector.AddWarningLog(LocalizedStrings.Str2142Params, info.Subscription.SubscriptionMessage);
                        continue;
                    }

                    info.Lookup.Items.Add(item);
                }
            }
            public void ProcessLookupResponse <T>(ISubscriptionIdMessage message, T[] items)
            {
                foreach (var id in message.GetSubscriptionIds())
                {
                    var info = TryGetInfo(id, false);

                    if (info == null || info.HasResult)
                    {
                        continue;
                    }

                    if (info.LookupItems == null)
                    {
                        _connector.AddWarningLog(LocalizedStrings.Str2142Params, info.Subscription.SubscriptionMessage);
                        continue;
                    }

                    info.LookupItems.AddRange(items.Cast <object>());
                }
            }
Пример #14
0
        private void ApplySubscriptionIds(ISubscriptionIdMessage subscrMsg, ParentSubscription parent, long[] newIds)
        {
            var ids       = subscrMsg.GetSubscriptionIds();
            var initialId = parent.Origin.TransactionId;

            newIds = newIds.Concat(parent.Alls.CachedKeys);

            if (subscrMsg is ISecurityIdMessage secIdMsg && parent.NonAlls.TryGetValue(secIdMsg.SecurityId, out var set))
            {
                newIds = newIds.Concat(set.Cache);
            }

            if (ids.Length == 1 && ids[0] == initialId)
            {
                subscrMsg.SetSubscriptionIds(newIds);
            }
            else
            {
                subscrMsg.SetSubscriptionIds(ids.Where(id => id != initialId).Concat(newIds).ToArray());
            }
        }
Пример #15
0
 private bool?RaiseReceived <TEntity>(TEntity entity, ISubscriptionIdMessage message, Action <Subscription, TEntity> evt)
 {
     return(RaiseReceived(entity, message, evt, out _));
 }
Пример #16
0
 private void ApplySubscriptionIds(ISubscriptionIdMessage subscrMsg, ChildSubscription child)
 {
     ApplySubscriptionIds(subscrMsg, child.Parent, child.Subscribers.CachedKeys);
 }
Пример #17
0
 public IEnumerable <Subscription> ProcessLookupResponse <T>(ISubscriptionIdMessage message, T item)
 {
     return(ProcessLookupResponse(message, new[] { item }));
 }
 public void ProcessLookupResponse <T>(ISubscriptionIdMessage message, T item)
 {
     ProcessLookupResponse(message, new[] { item });
 }
Пример #19
0
 private bool?RaiseReceived <TEntity>(TEntity entity, ISubscriptionIdMessage message, Action <Subscription, TEntity> evt, out bool?anyCanOnline)
 {
     return(RaiseReceived(entity, _subscriptionManager.GetSubscriptions(message), evt, out anyCanOnline));
 }
        private void ApplySubscriptionIds(ISubscriptionIdMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            long originTransId;

            switch (message)
            {
            case CandleMessage candleMsg:
                originTransId = candleMsg.OriginalTransactionId;
                break;

            case ExecutionMessage execMsg:
                switch (execMsg.ExecutionType)
                {
                case ExecutionTypes.Tick:
                case ExecutionTypes.OrderLog:
                    originTransId = execMsg.OriginalTransactionId;
                    break;

                default:
                    ApplyTransactionalSubscriptionIds(execMsg, _orderStatusSubscribers);
                    return;
                }

                break;

            case NewsMessage newsMsg:
                originTransId = newsMsg.OriginalTransactionId;
                break;

            case BoardMessage boardStateMsg:
                originTransId = boardStateMsg.OriginalTransactionId;
                break;

            case BoardStateMessage boardStateMsg:
                originTransId = boardStateMsg.OriginalTransactionId;
                break;

            case PortfolioMessage _:
            case BasePositionChangeMessage _:
                ApplyTransactionalSubscriptionIds(message, _pfLookupSubscribers);
                return;

            default:
                throw new ArgumentOutOfRangeException(nameof(message), message.ToString());
            }

            lock (_sync)
            {
                if (!_mdSubscribersById.TryGetValue(originTransId, out var info))
                {
                    return;
                }

                //if (info.Message.TransactionId == originTransId && info.Subscribers.Count > 1)
                message.SubscriptionIds = info.Subscribers.Cache;
            }
        }