예제 #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;
            }
        }