예제 #1
0
				private bool TryProcess<T>(T tradeId, HashSet<T> trades, ExecutionMessage currItem)
				{
					if (!trades.Add(tradeId))
						return false;

					trades.Remove(tradeId);
					Current = currItem.ToTick();
					return true;
				}
예제 #2
0
        private void ProcessBuilders(ExecutionMessage execMsg)
        {
            if (execMsg.IsSystem == false)
            {
                return;
            }

            foreach (var subscriptionId in execMsg.GetSubscriptionIds())
            {
                if (!_subscriptionIds.TryGetValue(subscriptionId, out var tuple))
                {
                    // can be non OL->MB subscription
                    //this.AddDebugLog("OL processing {0}/{1} not found.", execMsg.SecurityId, subscriptionId);
                    continue;
                }

                if (tuple.First)
                {
                    var sync = tuple.Third;

                    IOrderLogMarketDepthBuilder builder = tuple.Second;

                    try
                    {
                        QuoteChangeMessage depth;

                        lock (sync)
                            depth = builder.Update(execMsg)?.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());
                }
            }
        }
예제 #3
0
        private void ProcessBuilders(ExecutionMessage execMsg)
        {
            if (execMsg.IsSystem == false)
            {
                return;
            }

            var secId = GetSecurityId(execMsg.SecurityId);

            var depthBuilder = InnerAdapter.IsSupportSubscriptionBySecurity
                                ? _depthBuilders.TryGetValue(execMsg.SecurityId)
                                : _depthBuilders.ContainsKey(secId) ? _depthBuilders.SafeAdd(execMsg.SecurityId, key => new OrderLogMarketDepthBuilder(key)) : null;

            if (depthBuilder != null)
            {
                try
                {
                    var updated = depthBuilder.Update(execMsg);

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

                    if (updated)
                    {
                        base.OnInnerAdapterNewOutMessage(depthBuilder.Depth.Clone());
                    }
                }
                catch (Exception ex)
                {
                    // если ОЛ поврежден, то не нарушаем весь цикл обработки сообщения
                    // а только выводим сообщение в лог
                    base.OnInnerAdapterNewOutMessage(new ErrorMessage {
                        Error = ex
                    });
                }
            }
            else
            {
                this.AddDebugLog("OL->MD processing {0} not found.", execMsg.SecurityId);
            }

            if (_tickBuilders.Contains(secId))
            {
                this.AddDebugLog("OL->TICK processing {0}.", secId);
                base.OnInnerAdapterNewOutMessage(execMsg.ToTick());
            }
        }
예제 #4
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);
        }