Example #1
0
        private Message ProcessBuilders(ExecutionMessage execMsg)
        {
            List <long> nonBuilderIds = null;

            foreach (var subscriptionId in execMsg.GetSubscriptionIds())
            {
                if (!_subscriptionIds.TryGetValue(subscriptionId, out var info))
                {
                    if (nonBuilderIds == null)
                    {
                        nonBuilderIds = new List <long>();
                    }

                    nonBuilderIds.Add(subscriptionId);

                    // can be non OL->MB subscription
                    //this.AddDebugLog("OL processing {0}/{1} not found.", execMsg.SecurityId, subscriptionId);
                    continue;
                }

                if (!info.IsTicks)
                {
                    try
                    {
                        QuoteChangeMessage depth;

                        lock (info.Lock)
                        {
                            depth = info.Builder.Update(execMsg);

                            if (info.State != SubscriptionStates.Online)
                            {
                                depth = null;
                            }
                            else
                            {
                                depth = depth?.TypedClone();
                            }
                        }

                        this.AddDebugLog("OL->MD processing {0}={1}.", execMsg.SecurityId, depth != null);

                        if (depth != null)
                        {
                            depth.SetSubscriptionIds(subscriptionId: subscriptionId);
                            base.OnInnerAdapterNewOutMessage(depth);
                        }
                    }
                    catch (Exception ex)
                    {
                        // если ОЛ поврежден, то не нарушаем весь цикл обработки сообщения
                        // а только выводим сообщение в лог
                        base.OnInnerAdapterNewOutMessage(ex.ToErrorMessage());
                    }
                }
                else
                {
                    this.AddDebugLog("OL->TICK processing {0}.", execMsg.SecurityId);
                    base.OnInnerAdapterNewOutMessage(execMsg.ToTick());
                }
            }

            if (nonBuilderIds is null)
            {
                return(null);
            }

            execMsg.SetSubscriptionIds(nonBuilderIds.ToArray());
            return(execMsg);
        }