Ejemplo n.º 1
0
            public Security ProcessResponse(MarketDataMessage response, out MarketDataMessage originalMsg, out bool unexpectedCancelled)
            {
                unexpectedCancelled = false;

                var tuple = TryGetRequest(response.OriginalTransactionId);

                if (tuple == null)
                {
                    originalMsg = null;
                    return(null);
                }

                //_requests.Remove(response.OriginalTransactionId);

                var subscriber = tuple.Item2;

                originalMsg = tuple.Item1;

                if (originalMsg.DataType.IsSecurityRequired())
                {
                    lock (_subscribers.SyncRoot)
                    {
                        if (originalMsg.IsSubscribe)
                        {
                            if (response.IsOk())
                            {
                                _subscribers.SafeAdd(originalMsg.DataType).Add(subscriber);
                            }
                            else
                            {
                                var set = _subscribers.TryGetValue(originalMsg.DataType);

                                if (set != null && set.Remove(subscriber))
                                {
                                    unexpectedCancelled = true;
                                }
                            }
                        }
                        else
                        {
                            var dict = _subscribers.TryGetValue(originalMsg.DataType);

                            if (dict != null)
                            {
                                dict.Remove(subscriber);

                                if (dict.Count == 0)
                                {
                                    _subscribers.Remove(originalMsg.DataType);
                                }
                            }
                        }
                    }
                }

                return(subscriber);
            }
Ejemplo n.º 2
0
            public Subscription ProcessResponse(MarketDataMessage response, out MarketDataMessage originalMsg, out bool unexpectedCancelled)
            {
                var addLog = false;

                try
                {
                    lock (_syncObject)
                    {
                        unexpectedCancelled = false;

                        if (!_requests.TryGetValue(response.OriginalTransactionId, out var tuple))
                        {
                            addLog      = true;
                            originalMsg = null;
                            return(null);
                        }

                        _requests.Remove(response.OriginalTransactionId);

                        originalMsg = (MarketDataMessage)tuple.Item1;

                        var info = originalMsg.IsSubscribe
                                                        ? TryGetInfo(originalMsg.TransactionId, false)
                                                        : TryGetInfo(originalMsg.OriginalTransactionId, true);

                        if (originalMsg.IsSubscribe)
                        {
                            if (response.IsOk())
                            {
                                info.Active = true;
                            }
                            else
                            {
                                _subscriptions.Remove(info.Subscription.TransactionId);
                                unexpectedCancelled = info.Active;
                            }
                        }
                        else
                        {
                            _subscriptions.Remove(info.Subscription.TransactionId);
                        }

                        return(info.Subscription);
                    }
                }
                finally
                {
                    if (addLog)
                    {
                        _connector.AddWarningLog(LocalizedStrings.SubscriptionNonExist, response.OriginalTransactionId);
                    }
                }
            }
        private IEnumerable <MarketDataMessage> ProcessSubscriptionResult <T>(Dictionary <T, SubscriptionInfo <MarketDataMessage> > subscriptions, T key, SubscriptionInfo <MarketDataMessage> info, MarketDataMessage message)
        {
            //var info = subscriptions.TryGetValue(key);

            if (!subscriptions.ContainsKey(key))
            {
                return(null);
            }

            var isSubscribe = info.Message.IsSubscribe;
            var removeInfo  = !isSubscribe || !message.IsOk();

            info.IsSubscribed = isSubscribe && message.IsOk();

            var replies = new List <MarketDataMessage>();

            // TODO только нужная подписка
            foreach (var subscription in info.Subscriptions)
            {
                var reply = (MarketDataMessage)subscription.Clone();
                reply.OriginalTransactionId = subscription.TransactionId;
                //reply.TransactionId = message.TransactionId;
                reply.Error          = message.Error;
                reply.IsNotSupported = message.IsNotSupported;

                replies.Add(reply);
            }

            if (removeInfo)
            {
                subscriptions.Remove(key);
                _subscribersById.RemoveWhere(p => p.Value == info);
            }

            return(replies);
        }
Ejemplo n.º 4
0
            public Subscription ProcessResponse(MarketDataMessage response, out MarketDataMessage originalMsg, out bool unexpectedCancelled)
            {
                originalMsg = null;

                try
                {
                    lock (_syncObject)
                    {
                        unexpectedCancelled = false;

                        if (!_requests.TryGetValue(response.OriginalTransactionId, out var tuple))
                        {
                            originalMsg = null;
                            return(null);
                        }

                        _requests.Remove(response.OriginalTransactionId);

                        originalMsg = (MarketDataMessage)tuple.Item1;

                        var info = originalMsg.IsSubscribe
                                                        ? TryGetInfo(originalMsg.TransactionId, false, addLog: false)
                                                        : TryGetInfo(originalMsg.OriginalTransactionId, true, addLog: false);

                        if (info == null)
                        {
                            originalMsg = null;
                            return(null);
                        }

                        var subscription = info.Subscription;

                        if (originalMsg.IsSubscribe)
                        {
                            if (response.IsOk())
                            {
                                ChangeState(subscription, SubscriptionStates.Active);
                            }
                            else
                            {
                                ChangeState(subscription, SubscriptionStates.Error);

                                _subscriptions.Remove(subscription.TransactionId);
                                unexpectedCancelled = subscription.State == SubscriptionStates.Active;
                            }
                        }
                        else
                        {
                            ChangeState(subscription, SubscriptionStates.Stopped);

                            _subscriptions.Remove(subscription.TransactionId);
                        }

                        return(subscription);
                    }
                }
                finally
                {
                    if (originalMsg == null)
                    {
                        TryWriteLog(response.OriginalTransactionId);
                    }
                }
            }