示例#1
0
        private void SendInHistorySourceMessage(Security security, MarketDataTypes dataType, object arg, Func <DateTimeOffset, IEnumerable <Message> > getMessages)
        {
            var isSubscribe = getMessages != null;

            if (isSubscribe)
            {
                if (_historySourceSubscriptions.ChangeSubscribers(Tuple.Create(security.ToSecurityId(), dataType, arg), true) != 1)
                {
                    return;
                }
            }
            else
            {
                if (_historySourceSubscriptions.ChangeSubscribers(Tuple.Create(security.ToSecurityId(), dataType, arg), false) != 0)
                {
                    return;
                }
            }

            SendInMessage(new HistorySourceMessage
            {
                IsSubscribe = isSubscribe,
                SecurityId  = security.ToSecurityId(),
                DataType    = dataType,
                Arg         = arg,
                GetMessages = getMessages
            });
        }
        /// <summary>
        /// Подписаться на получение рыночных данных по инструменту.
        /// </summary>
        /// <param name="security">Инструмент, по которому необходимо начать получать новую информацию.</param>
        /// <param name="type">Тип рыночных данных.</param>
        public override void SubscribeMarketData(Security security, MarketDataTypes type)
        {
            var tf = MarketEmulator.Settings.UseCandlesTimeFrame;

            if (tf != null)
            {
                var securityId = GetSecurityId(security);
                var key        = Tuple.Create(securityId, tf.Value);

                if (_subscribedCandles.ChangeSubscribers(key, 1) != 1)
                {
                    return;
                }

                MarketDataAdapter.SendInMessage(new MarketDataMessage
                {
                    //SecurityId = securityId,
                    DataType    = MarketDataTypes.CandleTimeFrame,
                    Arg         = tf.Value,
                    IsSubscribe = true,
                }.FillSecurityInfo(this, security));
            }
            else
            {
                base.SubscribeMarketData(security, type);
            }
        }
        void IExternalCandleSource.SubscribeCandles(CandleSeries series, DateTimeOffset from, DateTimeOffset to)
        {
            var securityId = GetSecurityId(series.Security);
            var dataType   = series.CandleType.ToCandleMessageType().ToCandleMarketDataType();

            if (_subscribedCandles.ChangeSubscribers(Tuple.Create(securityId, dataType, series.Arg), 1) != 1)
            {
                return;
            }

            MarketDataAdapter.SendInMessage(new MarketDataMessage
            {
                //SecurityId = securityId,
                DataType    = dataType,
                Arg         = series.Arg,
                IsSubscribe = true,
            }.FillSecurityInfo(this, series.Security));

            _series.Add(series.Security, series);
        }
示例#4
0
 private static bool TryUnSubscribe <T>(CachedSynchronizedDictionary <T, int> subscribers, T subscriber)
 {
     return(subscribers.ChangeSubscribers(subscriber, -1) == 0);
 }