/// <summary>
 /// Create a copy of <see cref="SubscriptionMessageAdapter"/>.
 /// </summary>
 /// <returns>Copy.</returns>
 public override IMessageChannel Clone()
 {
     return(new SubscriptionMessageAdapter(InnerAdapter.TypedClone())
     {
         IsRestoreSubscriptionOnErrorReconnect = IsRestoreSubscriptionOnErrorReconnect,
     });
 }
Пример #2
0
 /// <summary>
 /// Create a copy of <see cref="HeartbeatMessageAdapter"/>.
 /// </summary>
 /// <returns>Copy.</returns>
 public override IMessageChannel Clone()
 {
     return(new HeartbeatMessageAdapter((IMessageAdapter)InnerAdapter.Clone())
     {
         SuppressReconnectingErrors = SuppressReconnectingErrors
     });
 }
Пример #3
0
        private void ProcessRisk(Message message)
        {
            foreach (var rule in RiskManager.ProcessRules(message))
            {
                InnerAdapter.AddWarningLog(LocalizedStrings.Str855Params,
                                           rule.GetType().GetDisplayName(), rule.Title, rule.Action);

                switch (rule.Action)
                {
                case RiskActions.ClosePositions:
                {
                    break;
                }

                case RiskActions.StopTrading:
                    InnerAdapter.SendInMessage(new DisconnectMessage());
                    break;

                case RiskActions.CancelOrders:
                    InnerAdapter.SendInMessage(new OrderGroupCancelMessage {
                        TransactionId = InnerAdapter.TransactionIdGenerator.GetNextId()
                    });
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
Пример #4
0
 /// <summary>
 /// Create a copy of <see cref="StorageMetaInfoMessageAdapter"/>.
 /// </summary>
 /// <returns>Copy.</returns>
 public override IMessageChannel Clone()
 {
     return(new StorageMetaInfoMessageAdapter(InnerAdapter.TypedClone(), _securityStorage, _positionStorage, _exchangeInfoProvider, _storageProcessor)
     {
         OverrideSecurityData = OverrideSecurityData,
     });
 }
Пример #5
0
 /// <summary>
 /// Create a copy of <see cref="StorageMetaInfoMessageAdapter"/>.
 /// </summary>
 /// <returns>Copy.</returns>
 public override IMessageChannel Clone()
 {
     return(new StorageMetaInfoMessageAdapter((IMessageAdapter)InnerAdapter.Clone(), _securityStorage, _positionStorage, _exchangeInfoProvider, StorageRegistry, SnapshotRegistry, CandleBuilderProvider)
     {
         OverrideSecurityData = OverrideSecurityData,
     });
 }
Пример #6
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public virtual void Dispose()
        {
            InnerAdapter.NewOutMessage -= OnInnerAdapterNewOutMessage;

            if (OwnInnerAdaper)
            {
                InnerAdapter.Dispose();
            }
        }
Пример #7
0
        /// <inheritdoc />
        protected override bool OnSendInMessage(Message message)
        {
            switch (message.Type)
            {
            case MessageTypes.Reset:
                _depths.Clear();
                break;

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

                if (mdMsg.SecurityId == default)
                {
                    break;
                }

                if (mdMsg.DataType2 == DataType.MarketDepth)
                {
                    if (mdMsg.IsSubscribe)
                    {
                        if (mdMsg.PassThroughOrderBookInrement)
                        {
                            break;
                        }

                        if (mdMsg.MaxDepth != null)
                        {
                            var actualDepth = mdMsg.MaxDepth.Value;

                            var supportedDepth = InnerAdapter.NearestSupportedDepth(actualDepth);

                            if (supportedDepth != actualDepth)
                            {
                                mdMsg          = mdMsg.TypedClone();
                                mdMsg.MaxDepth = supportedDepth;

                                _depths.Add(mdMsg.TransactionId, actualDepth);

                                this.AddInfoLog("MD truncate {0}/{1} ({2}->{3}).", mdMsg.SecurityId, mdMsg.TransactionId, actualDepth, supportedDepth);
                            }
                        }
                    }
                    else
                    {
                        RemoveSubscription(mdMsg.OriginalTransactionId);
                    }
                }

                break;
            }
            }

            return(base.OnSendInMessage(message));
        }
Пример #8
0
        /// <summary>
        /// Send message.
        /// </summary>
        /// <param name="message">Message.</param>
        public override void SendInMessage(Message message)
        {
            switch (message.Type)
            {
            case MessageTypes.Connect:
            {
                if (_isFirstTimeConnect)
                {
                    _isFirstTimeConnect = false;
                }
                else
                {
                    InnerAdapter.SendInMessage(new ResetMessage());
                }

                //	lock (_timeSync)
                //	{
                //		_currState = ConnectionStates.Connecting;
                //	}

                //	if (_prevState == _none)
                //	{
                //		_connectionTimeOut = _reConnectionSettings.TimeOutInterval;
                //		_connectingAttemptCount = _reConnectionSettings.AttemptCount;
                //	}
                //	else
                //		_connectionTimeOut = _reConnectionSettings.Interval;

                break;
            }

            case MessageTypes.Disconnect:
            {
                //lock (_timeSync)
                //	_currState = ConnectionStates.Disconnecting;

                //_connectionTimeOut = _reConnectionSettings.TimeOutInterval;

                lock (_timeSync)
                {
                    _canSendTime = false;

                    if (_heartBeatTimer != null)
                    {
                        _heartBeatTimer.Dispose();
                        _heartBeatTimer = null;
                    }
                }

                break;
            }
            }

            InnerAdapter.SendInMessage(message);
        }
Пример #9
0
        private MarketDataMessage ProcessMarketDataRequest(MarketDataMessage message)
        {
            if (message.IsSubscribe)
            {
                if (!InnerAdapter.IsMarketDataTypeSupported(DataType.OrderLog))
                {
                    return(message);
                }

                var isBuild = message.BuildMode == MarketDataBuildModes.Build && message.BuildFrom == DataType.OrderLog;

                if (message.DataType2 == DataType.MarketDepth)
                {
                    if (isBuild || !InnerAdapter.IsMarketDataTypeSupported(message.ToDataType()))
                    {
                        var secId = GetSecurityId(message.SecurityId);

                        IOrderLogMarketDepthBuilder builder = null;

                        if (InnerAdapter.IsSecurityRequired(DataType.OrderLog))
                        {
                            builder = message.DepthBuilder ?? InnerAdapter.CreateOrderLogMarketDepthBuilder(secId);
                        }

                        _subscriptionIds.Add(message.TransactionId, RefTuple.Create(true, builder, new SyncObject()));

                        message           = message.TypedClone();
                        message.DataType2 = DataType.OrderLog;

                        this.AddInfoLog("OL->MD subscribed {0}/{1}.", secId, message.TransactionId);
                    }
                }
                else if (message.DataType2 == DataType.Ticks)
                {
                    if (isBuild || !InnerAdapter.IsMarketDataTypeSupported(message.ToDataType()))
                    {
                        var secId = GetSecurityId(message.SecurityId);

                        _subscriptionIds.Add(message.TransactionId, RefTuple.Create(false, (IOrderLogMarketDepthBuilder)null, new SyncObject()));

                        message           = message.TypedClone();
                        message.DataType2 = DataType.OrderLog;

                        this.AddInfoLog("OL->TICK subscribed {0}/{1}.", secId, message.TransactionId);
                    }
                }
            }
            else
            {
                RemoveSubscription(message.OriginalTransactionId);
            }

            return(message);
        }
Пример #10
0
        private MarketDataMessage ProcessMarketDataRequest(MarketDataMessage message)
        {
            if (message.IsSubscribe)
            {
                if (message.SecurityId == default || !InnerAdapter.IsMarketDataTypeSupported(DataType.OrderLog))
                {
                    return(message);
                }

                var isBuild = message.BuildMode == MarketDataBuildModes.Build && message.BuildFrom == DataType.OrderLog;

                if (message.DataType2 == DataType.MarketDepth)
                {
                    if (isBuild || !InnerAdapter.IsMarketDataTypeSupported(message.DataType2))
                    {
                        var builder = message.DepthBuilder ?? InnerAdapter.CreateOrderLogMarketDepthBuilder(message.SecurityId);

                        _subscriptionIds.Add(message.TransactionId, new SubscriptionInfo(message.TypedClone())
                        {
                            Builder = builder
                        });

                        message           = message.TypedClone();
                        message.DataType2 = DataType.OrderLog;

                        this.AddInfoLog("OL->MD subscribed {0}/{1}.", message.SecurityId, message.TransactionId);
                    }
                }
                else if (message.DataType2 == DataType.Ticks)
                {
                    if (isBuild || !InnerAdapter.IsMarketDataTypeSupported(message.DataType2))
                    {
                        _subscriptionIds.Add(message.TransactionId, new SubscriptionInfo(message.TypedClone()));

                        message           = message.TypedClone();
                        message.DataType2 = DataType.OrderLog;

                        this.AddInfoLog("OL->TICK subscribed {0}/{1}.", message.SecurityId, message.TransactionId);
                    }
                }
            }
            else
            {
                TryRemoveSubscription(message.OriginalTransactionId, out _);
            }

            return(message);
        }
Пример #11
0
        /// <inheritdoc />
        protected override void OnSendInMessage(Message message)
        {
            switch (message.Type)
            {
            case MessageTypes.Reset:
                _depths.Clear();
                break;

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

                if (mdMsg.DataType == MarketDataTypes.MarketDepth)
                {
                    if (mdMsg.IsSubscribe)
                    {
                        if (mdMsg.MaxDepth != null)
                        {
                            var actualDepth = mdMsg.MaxDepth.Value;

                            var supportedDepth = InnerAdapter.NearestSupportedDepth(actualDepth);

                            if (supportedDepth != actualDepth)
                            {
                                mdMsg          = (MarketDataMessage)mdMsg.Clone();
                                mdMsg.MaxDepth = supportedDepth;

                                _depths.Add(mdMsg.TransactionId, actualDepth);
                            }
                        }
                    }
                    else
                    {
                        _depths.Remove(mdMsg.OriginalTransactionId);
                    }
                }

                break;
            }
            }

            base.OnSendInMessage(message);
        }
Пример #12
0
        /// <inheritdoc />
        public override void SendInMessage(Message message)
        {
            switch (message.Type)
            {
            case MessageTypes.Reset:
                _depths.Clear();
                break;

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

                if (mdMsg.DataType == MarketDataTypes.MarketDepth)
                {
                    if (mdMsg.IsSubscribe)
                    {
                        if (mdMsg.MaxDepth != null)
                        {
                            var actualDepth = mdMsg.MaxDepth.Value;

                            var supportedDepth = InnerAdapter.NearestSupportedDepth(actualDepth);

                            if (supportedDepth != actualDepth)
                            {
                                mdMsg          = (MarketDataMessage)mdMsg.Clone();
                                mdMsg.MaxDepth = supportedDepth;

                                _depths[mdMsg.SecurityId] = actualDepth;
                            }
                        }
                    }
                    else
                    {
                        _depths.Remove(mdMsg.SecurityId);
                    }
                }

                break;
            }
            }

            base.SendInMessage(message);
        }
Пример #13
0
        private void OnHeartbeatTimer()
        {
            lock (_timeSync)
            {
                if (_currState != ConnectionStates.Connected)
                {
                    return;
                }

                if (!_canSendTime)
                {
                    return;
                }

                _canSendTime = false;
            }

            _timeMessage.IsBack = true;
            InnerAdapter.SendInMessage(_timeMessage);
        }
Пример #14
0
        /// <inheritdoc />
        public override void SendInMessage(Message message)
        {
            switch (message.Type)
            {
            case MessageTypes.Reset:
                _biggerTimeFrameCandleCompressors.Clear();
                break;

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

                if (mdMsg.DataType != MarketDataTypes.CandleTimeFrame)
                {
                    break;
                }

                var originalTf = (TimeSpan)mdMsg.Arg;
                var timeFrames = InnerAdapter.GetTimeFrames(mdMsg.SecurityId).ToArray();

                if (timeFrames.Contains(originalTf))
                {
                    break;
                }

                var smaller = timeFrames
                              .FilterSmallerTimeFrames(originalTf)
                              .OrderByDescending()
                              .First();

                _biggerTimeFrameCandleCompressors.Add(mdMsg.TransactionId, new BiggerTimeFrameCandleCompressor((MarketDataMessage)mdMsg.Clone()));

                var clone = (MarketDataMessage)mdMsg.Clone();
                clone.Arg = smaller;
                base.SendInMessage(clone);
                return;
            }
            }

            base.SendInMessage(message);
        }
Пример #15
0
        private void OnHeartbeatTimer()
        {
            lock (_timeSync)
            {
                if (_currState != ConnectionStates.Connected)
                {
                    return;
                }

                if (!_canSendTime)
                {
                    return;
                }

                _canSendTime = false;
            }

            _timeMessage.IsBack        = true;
            _timeMessage.TransactionId = InnerAdapter.TransactionIdGenerator.GetNextId();
            InnerAdapter.SendInMessage(_timeMessage);
        }
Пример #16
0
        /// <summary>
        /// Send message.
        /// </summary>
        /// <param name="message">Message.</param>
        public override void SendInMessage(Message message)
        {
            if (message.LocalTime.IsDefault())
            {
                message.LocalTime = InnerAdapter.CurrentTime.LocalDateTime;
            }

            if (message.Type == MessageTypes.Connect)
            {
                LatencyManager.Reset();
                CommissionManager.Reset();
                RiskManager.Reset();
            }
            else
            {
                LatencyManager.ProcessMessage(message);
                ProcessRisk(message);
            }

            InnerAdapter.SendInMessage(message);
        }
 /// <summary>
 /// Create a copy of <see cref="SubscriptionSecurityAllMessageAdapter"/>.
 /// </summary>
 /// <returns>Copy.</returns>
 public override IMessageChannel Clone()
 {
     return(new SubscriptionSecurityAllMessageAdapter(InnerAdapter.TypedClone()));
 }
			public override IMessageChannel Clone()
			{
				return new TimeAdapter(_parent, (IMessageAdapter)InnerAdapter.Clone());
			}
Пример #19
0
 /// <summary>
 /// Create a copy of <see cref="OrderBookInrementMessageAdapter"/>.
 /// </summary>
 /// <returns>Copy.</returns>
 public override IMessageChannel Clone()
 {
     return(new OrderBookInrementMessageAdapter(InnerAdapter.TypedClone()));
 }
Пример #20
0
        private MarketDataMessage ProcessMarketDataRequest(MarketDataMessage message)
        {
            if (message.IsSubscribe)
            {
                if (!InnerAdapter.IsMarketDataTypeSupported(MarketDataTypes.OrderLog))
                {
                    return(message);
                }

                var isBuild = message.BuildMode == MarketDataBuildModes.Build && message.BuildFrom == MarketDataTypes.OrderLog;

                switch (message.DataType)
                {
                case MarketDataTypes.MarketDepth:
                {
                    if (isBuild || !InnerAdapter.IsMarketDataTypeSupported(message.DataType))
                    {
                        var secId = GetSecurityId(message.SecurityId);

                        IOrderLogMarketDepthBuilder builder = null;

                        if (InnerAdapter.IsSecurityRequired(DataType.OrderLog))
                        {
                            builder = InnerAdapter.CreateOrderLogMarketDepthBuilder(secId);
                        }

                        _subscriptionIds.Add(message.TransactionId, RefTuple.Create(secId, true, builder));

                        message          = (MarketDataMessage)message.Clone();
                        message.DataType = MarketDataTypes.OrderLog;

                        this.AddInfoLog("OL->MD subscribed {0}/{1}.", secId, message.TransactionId);
                    }

                    break;
                }

                case MarketDataTypes.Trades:
                {
                    if (isBuild || !InnerAdapter.IsMarketDataTypeSupported(message.DataType))
                    {
                        var secId = GetSecurityId(message.SecurityId);

                        _subscriptionIds.Add(message.TransactionId, RefTuple.Create(secId, false, (IOrderLogMarketDepthBuilder)null));

                        message          = (MarketDataMessage)message.Clone();
                        message.DataType = MarketDataTypes.OrderLog;

                        this.AddInfoLog("OL->TICK subscribed {0}/{1}.", secId, message.TransactionId);
                    }

                    break;
                }
                }
            }
            else
            {
                var tuple = _subscriptionIds.TryGetAndRemove(message.OriginalTransactionId);

                if (tuple != null)
                {
                    this.AddInfoLog("OL->{0} unsubscribed {1}/{2}.", tuple.Second ? "MD" : "TICK", tuple.First, message.OriginalTransactionId);
                }
            }

            return(message);
        }
Пример #21
0
 /// <summary>
 /// Create a copy of <see cref="EmulationMessageAdapter"/>.
 /// </summary>
 /// <returns>Copy.</returns>
 public override IMessageChannel Clone()
 => new EmulationMessageAdapter(InnerAdapter.TypedClone(), InChannel, _isEmulationOnly, Emulator.SecurityProvider, Emulator.PortfolioProvider, Emulator.ExchangeInfoProvider);
 /// <summary>
 /// Create a copy of <see cref="CandleHolderMessageAdapter"/>.
 /// </summary>
 /// <returns>Copy.</returns>
 public override IMessageChannel Clone()
 {
     return(new CandleHolderMessageAdapter((IMessageAdapter)InnerAdapter.Clone()));
 }
Пример #23
0
 private SecurityId GetSecurityId(SecurityId securityId)
 {
     return(InnerAdapter.IsSecurityRequired(DataType.OrderLog)
                         ? securityId
                         : default);
Пример #24
0
 IOrderLogMarketDepthBuilder IMessageAdapter.CreateOrderLogMarketDepthBuilder(SecurityId securityId)
 {
     return(InnerAdapter.CreateOrderLogMarketDepthBuilder(securityId));
 }
Пример #25
0
 bool IMessageAdapter.IsConnectionAlive()
 {
     return(InnerAdapter.IsConnectionAlive());
 }
Пример #26
0
 OrderCondition IMessageAdapter.CreateOrderCondition()
 {
     return(InnerAdapter.CreateOrderCondition());
 }
Пример #27
0
 void ILogReceiver.AddLog(LogMessage message)
 {
     InnerAdapter.AddLog(message);
 }
Пример #28
0
 void IPersistable.Save(SettingsStorage storage)
 {
     InnerAdapter.Save(storage);
 }
Пример #29
0
 /// <summary>
 /// Create a copy of <see cref="SecurityMappingMessageAdapter"/>.
 /// </summary>
 /// <returns>Copy.</returns>
 public override IMessageChannel Clone()
 {
     return(new SecurityMappingMessageAdapter(InnerAdapter.TypedClone(), Storage));
 }
Пример #30
0
 void IPersistable.Load(SettingsStorage storage)
 {
     InnerAdapter.Load(storage);
 }