private void OnNewBar(int row, int rowCount, string smartId, SmartComTimeFrames timeFrame, DateTime time, decimal?open, decimal?high, decimal?low, decimal?close, decimal?volume, decimal?openInt)
        {
            this.AddDebugLog("OnNewHistoryTrade row = {0} rowCount = {1} securityId = {2} timeFrame = {3} time = {4} open = {5} high = {6} low = {7} close = {8} volume = {9} openInt = {10}",
                             row, rowCount, smartId, timeFrame, time, open, high, low, close, volume, openInt);

            var infos        = _candleTransactions.TryGetValue(smartId);
            var timeFrameKey = (TimeSpan)timeFrame;

            Tuple <long, List <CandleMessage> > transactionInfo;

            if (infos == null || !infos.TryGetValue(timeFrameKey, out transactionInfo))
            {
                this.AddErrorLog(LocalizedStrings.Str1855Params, smartId, timeFrame);
                return;
            }

            transactionInfo.Item2.Add(new TimeFrameCandleMessage
            {
                SecurityId = new SecurityId {
                    Native = smartId
                },
                OpenPrice             = open ?? 0,
                HighPrice             = high ?? 0,
                LowPrice              = low ?? 0,
                ClosePrice            = close ?? 0,
                TotalVolume           = volume ?? 0,
                OpenTime              = time.ApplyTimeZone(TimeHelper.Moscow) - (TimeSpan)timeFrame,
                CloseTime             = time.ApplyTimeZone(TimeHelper.Moscow),
                OpenInterest          = openInt,
                OriginalTransactionId = transactionInfo.Item1,
            });

            if ((row + 1) < rowCount)
            {
                return;
            }

            row = 0;

            transactionInfo.Item2.OrderBy(c => c.OpenTime).ForEach(m =>
            {
                m.IsFinished = ++row == rowCount;

                if (!m.IsFinished)
                {
                    m.State = CandleStates.Finished;
                }

                SendOutMessage(m);
            });

            infos.Remove(timeFrameKey);

            if (infos.IsEmpty())
            {
                _candleTransactions.Remove(smartId);
            }
        }
示例#2
0
        /// <summary>
        /// Получить тайм-фрейм свечи от сервера SmartCOM.
        /// </summary>
        /// <param name="security">Инструмент, для которого необходимо начать получать исторические свечи.</param>
        /// <param name="timeFrame">Тайм-фрейм.</param>
        /// <param name="from">Временная точка отсчета.</param>
        /// <param name="count">Количество свечек.</param>
        /// <param name="direction">Направление поиска относительно параметра from. Если значение равно <see cref="SmartComHistoryDirections.Forward"/>,
        /// то данные ищутся от from в сторону увеличения времени. Если значение равно <see cref="SmartComHistoryDirections.Backward"/>, то свечи
        /// ищутся до from в сторону уменьшения времени.</param>
        public void RequestCandles(Security security, SmartComTimeFrames timeFrame, DateTimeOffset from, long count, SmartComHistoryDirections direction)
        {
            if (security == null)
            {
                throw new ArgumentNullException(nameof(security));
            }

            if (timeFrame == null)
            {
                throw new ArgumentNullException(nameof(timeFrame));
            }

            if (count <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(count), count, LocalizedStrings.Str1890);
            }

            // http://stocksharp.com/forum/yaf_postst658_provierka-na-vriemia-birzhi-pri-zaghruzkie-istorii.aspx
            //if (from > MarketTime)
            //	throw new ArgumentOutOfRangeException("from", from, "Параметр from не может быть больше текущего времени биржи.");

            //var token = _candleTokens.SafeAdd(new Tuple<Security, SmartTimeFrames>(security, timeFrame), key => new CandleToken(security, timeFrame));

            var transactionId = TransactionIdGenerator.GetNextId();
            var tf            = (TimeSpan)timeFrame;

            var scope = Scope <CandleSeries> .Current;

            _series.Add(transactionId, scope == null ? new CandleSeries(typeof(TimeFrameCandle), security, tf) : scope.Value);

            SendInMessage(new MarketDataMessage
            {
                TransactionId = transactionId,
                //SecurityId = GetSecurityId(security),
                From          = from,
                DataType      = MarketDataTypes.CandleTimeFrame,
                Arg           = tf,
                IsSubscribe   = true,
                Count         = count,
                ExtensionInfo = new Dictionary <object, object>
                {
                    { "Direction", direction },
                }
            }.FillSecurityInfo(this, security));
        }
示例#3
0
        /// <summary>
        /// Получить тайм-фрейм свечи от сервера SmartCOM.
        /// </summary>
        /// <param name="security">Инструмент, для которого необходимо начать получать исторические свечи.</param>
        /// <param name="timeFrame">Тайм-фрейм.</param>
        /// <param name="range">Диапазон времени, для которого нужно получить свечи.</param>
        public void RequestCandles(Security security, SmartComTimeFrames timeFrame, Range <DateTimeOffset> range)
        {
            if (security == null)
            {
                throw new ArgumentNullException(nameof(security));
            }

            if (timeFrame == null)
            {
                throw new ArgumentNullException(nameof(timeFrame));
            }

            if (range == null)
            {
                throw new ArgumentNullException(nameof(range));
            }

            var count = security.GetTimeFrameCount(range, (TimeSpan)timeFrame);

            RequestCandles(security, timeFrame, range.Max, count, SmartComHistoryDirections.Backward);
        }
示例#4
0
		/// <summary>
		/// Получить тайм-фрейм свечи от сервера SmartCOM.
		/// </summary>
		/// <param name="security">Инструмент, для которого необходимо начать получать исторические свечи.</param>
		/// <param name="timeFrame">Тайм-фрейм.</param>
		/// <param name="from">Временная точка отсчета.</param>
		/// <param name="count">Количество свечек.</param>
		/// <param name="direction">Направление поиска относительно параметра from. Если значение равно <see cref="SmartComHistoryDirections.Forward"/>,
		/// то данные ищутся от from в сторону увеличения времени. Если значение равно <see cref="SmartComHistoryDirections.Backward"/>, то свечи
		/// ищутся до from в сторону уменьшения времени.</param>
		public void RequestCandles(Security security, SmartComTimeFrames timeFrame, DateTimeOffset from, long count, SmartComHistoryDirections direction)
		{
			if (security == null)
				throw new ArgumentNullException("security");

			if (timeFrame == null)
				throw new ArgumentNullException("timeFrame");

			if (count <= 0)
				throw new ArgumentOutOfRangeException("count", count, LocalizedStrings.Str1890);

			// http://stocksharp.com/forum/yaf_postst658_provierka-na-vriemia-birzhi-pri-zaghruzkie-istorii.aspx
			//if (from > MarketTime)
			//	throw new ArgumentOutOfRangeException("from", from, "Параметр from не может быть больше текущего времени биржи.");

			//var token = _candleTokens.SafeAdd(new Tuple<Security, SmartTimeFrames>(security, timeFrame), key => new CandleToken(security, timeFrame));

			var transactionId = TransactionIdGenerator.GetNextId();
			var tf = (TimeSpan)timeFrame;

			var scope = Scope<CandleSeries>.Current;
			_series.Add(transactionId, scope == null ? new CandleSeries(typeof(TimeFrameCandle), security, tf) : scope.Value);

			SendInMessage(new MarketDataMessage
			{
				TransactionId = transactionId,
				//SecurityId = GetSecurityId(security),
				From = from,
				DataType = MarketDataTypes.CandleTimeFrame,
				Arg = tf,
				IsSubscribe = true,
				Count = count,
				ExtensionInfo = new Dictionary<object, object>
				{
					{ "Direction", direction },
				}
			}.FillSecurityInfo(this, security));
		}
示例#5
0
		/// <summary>
		/// Получить тайм-фрейм свечи от сервера SmartCOM.
		/// </summary>
		/// <param name="security">Инструмент, для которого необходимо начать получать исторические свечи.</param>
		/// <param name="timeFrame">Тайм-фрейм.</param>
		/// <param name="range">Диапазон времени, для которого нужно получить свечи.</param>
		public void RequestCandles(Security security, SmartComTimeFrames timeFrame, Range<DateTimeOffset> range)
		{
			if (security == null)
				throw new ArgumentNullException("security");

			if (timeFrame == null)
				throw new ArgumentNullException("timeFrame");

			if (range == null)
				throw new ArgumentNullException("range");

			var count = security.GetTimeFrameCount(range, (TimeSpan)timeFrame);
			RequestCandles(security, timeFrame, range.Max, count, SmartComHistoryDirections.Backward);
		}
示例#6
0
 /// <summary>
 /// Получить временные диапазоны, для которых у данного источника для передаваемой серии свечек есть данные.
 /// </summary>
 /// <param name="series">Серия свечек.</param>
 /// <returns>Временные диапазоны.</returns>
 IEnumerable <Range <DateTimeOffset> > IExternalCandleSource.GetSupportedRanges(CandleSeries series)
 {
     if (series.CandleType == typeof(TimeFrameCandle) && series.Arg is TimeSpan && SmartComTimeFrames.CanConvert((TimeSpan)series.Arg))
     {
         yield return(new Range <DateTimeOffset>(DateTimeOffset.MinValue, CurrentTime));
     }
 }
		private void OnNewBar(int row, int rowCount, string smartId, SmartComTimeFrames timeFrame, DateTime time, decimal open, decimal high, decimal low, decimal close, decimal volume, decimal openInt)
		{
			this.AddDebugLog("OnNewHistoryTrade row = {0} rowCount = {1} securityId = {2} timeFrame = {3} time = {4} open = {5} high = {6} low = {7} close = {8} volume = {9} openInt = {10}",
				row, rowCount, smartId, timeFrame, time, open, high, low, close, volume, openInt);

			var infos = _candleTransactions.TryGetValue(smartId);
			var timeFrameKey = (TimeSpan)timeFrame;

			Tuple<long, List<CandleMessage>> transactionInfo;
			if (infos == null || !infos.TryGetValue(timeFrameKey, out transactionInfo))
			{
				this.AddErrorLog(LocalizedStrings.Str1855Params, smartId, timeFrame);
				return;
			}

			transactionInfo.Item2.Add(new TimeFrameCandleMessage
			{
				SecurityId = new SecurityId { Native = smartId },
				OpenPrice = open,
				HighPrice = high,
				LowPrice = low,
				ClosePrice = close,
				TotalVolume = volume,
				OpenTime = time.ApplyTimeZone(TimeHelper.Moscow) - (TimeSpan)timeFrame,
				CloseTime = time.ApplyTimeZone(TimeHelper.Moscow),
				OpenInterest = openInt,
				OriginalTransactionId = transactionInfo.Item1,
				IsFinished = row == (rowCount - 1),
			});

			if ((row + 1) < rowCount)
				return;

			transactionInfo.Item2.OrderBy(c => c.OpenTime).ForEach(SendOutMessage);

			infos.Remove(timeFrameKey);

			if (infos.IsEmpty())
				_candleTransactions.Remove(smartId);
		}