Beispiel #1
0
        /// <inheritdoc />
        public override void SendInMessage(Message message)
        {
            switch (message.Type)
            {
            case MessageTypes.Reset:
            {
                _subscriptions.Clear();
                break;
            }

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

                if (mdMsg.IsSubscribe)
                {
                    if (!mdMsg.IsBasket())
                    {
                        break;
                    }

                    if (_securityProvider.LookupById(mdMsg.SecurityId) is BasketSecurity basket)
                    {
                        var processor = _processorProvider.CreateProcessor(basket);
                        var tuple     = Tuple.Create(processor, mdMsg.TransactionId);

                        var info = _subscriptions.SafeAdd(mdMsg.DataType);

                        var ids = new long[processor.BasketLegs.Length];

                        for (var i = 0; i < ids.Length; i++)
                        {
                            ids[i] = TransactionIdGenerator.GetNextId();
                            info.ByTransactionIds.Add(ids[i], tuple);
                        }

                        foreach (var id in ids)
                        {
                            var clone = (MarketDataMessage)mdMsg.Clone();
                            clone.TransactionId = id;
                            SendInMessage(clone);
                        }

                        return;
                    }
                }
                else
                {
                }



                break;
            }
            }

            base.SendInMessage(message);
        }
        /// <inheritdoc />
        public override void SendInMessage(Message message)
        {
            switch (message.Type)
            {
            case MessageTypes.Reset:
            {
                _subscriptions.Clear();
                _subscriptionsById.Clear();
                break;
            }

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

                if (mdMsg.SecurityId.IsDefault())
                {
                    break;
                }

                var security = _securityProvider.LookupById(mdMsg.SecurityId);

                if (security == null)
                {
                    if (!mdMsg.IsBasket())
                    {
                        break;
                    }

                    security = mdMsg.ToSecurity(_exchangeInfoProvider).ToBasket(_processorProvider);
                }
                else if (!security.IsBasket())
                {
                    break;
                }

                if (mdMsg.IsSubscribe)
                {
                    var processor = _processorProvider.CreateProcessor(security);
                    var info      = new SubscriptionInfo(processor, mdMsg.TransactionId);

                    var dict = _subscriptions.SafeAdd(mdMsg.DataType);
                    _subscriptionsById.Add(mdMsg.TransactionId, info);

                    var inners = new MarketDataMessage[processor.BasketLegs.Length];

                    for (var i = 0; i < inners.Length; i++)
                    {
                        var inner = (MarketDataMessage)mdMsg.Clone();

                        inner.TransactionId = TransactionIdGenerator.GetNextId();
                        inner.SecurityId    = processor.BasketLegs[i];

                        inners[i] = inner;

                        info.LegsSubscriptions.Add(inner.TransactionId);
                        dict.Add(inner.TransactionId, info);
                    }

                    foreach (var inner in inners)
                    {
                        base.SendInMessage(inner);
                    }
                }
                else
                {
                    if (!_subscriptionsById.TryGetValue(mdMsg.OriginalTransactionId, out var info))
                    {
                        break;
                    }

                    _subscriptionsById.Remove(mdMsg.OriginalTransactionId);

                    foreach (var id in info.LegsSubscriptions)
                    {
                        base.SendInMessage(new MarketDataMessage
                            {
                                TransactionId         = TransactionIdGenerator.GetNextId(),
                                IsSubscribe           = false,
                                OriginalTransactionId = id
                            });
                    }
                }

                RaiseNewOutMessage(new MarketDataMessage
                    {
                        OriginalTransactionId = mdMsg.TransactionId
                    });

                return;
            }
            }

            base.SendInMessage(message);
        }