/// <summary>
        /// take candle history for period
        /// взять историю свечек за период
        /// </summary>
        public List <Candle> GetCandleDataToSecurity(Security security, TimeFrameBuilder timeFrameBuilder, DateTime startTime, DateTime endTime, DateTime actualTime)
        {
            if (endTime > DateTime.Now - new TimeSpan(0, 0, 1, 0))
            {
                endTime = DateTime.Now - new TimeSpan(0, 0, 1, 0);
            }

            int interval = 500 * (int)timeFrameBuilder.TimeFrameTimeSpan.TotalMinutes;

            List <Candle> candles = new List <Candle>();

            var startTimeStep = startTime;
            var endTimeStep   = startTime;

            while (endTime > endTimeStep)
            {
                endTimeStep = endTimeStep + new TimeSpan(0, 0, interval, 0);

                DateTime realEndTime = endTimeStep;

                if (realEndTime > DateTime.Now - new TimeSpan(0, 0, (int)timeFrameBuilder.TimeFrameTimeSpan.TotalMinutes, 0))
                {
                    realEndTime = DateTime.Now - new TimeSpan(0, 0, (int)timeFrameBuilder.TimeFrameTimeSpan.TotalMinutes, 0);
                }

                List <Candle> stepCandles = _client.GetCandlesForTimes(security.Name, timeFrameBuilder.TimeFrameTimeSpan, startTimeStep, realEndTime);

                if (stepCandles != null)
                {
                    candles.AddRange(stepCandles);
                }


                startTimeStep = endTimeStep + new TimeSpan(0, 0, (int)timeFrameBuilder.TimeFrameTimeSpan.TotalMinutes, 0);

                if (endTime < endTimeStep)
                {
                    break;
                }

                Thread.Sleep(300);
            }

            if (candles.Count == 0)
            {
                return(null);
            }

            return(candles);
        }
Пример #2
0
        /// <summary>
        /// take candle history for period
        /// взять историю свечек за период
        /// </summary>
        public List <Candle> GetCandleDataToSecurity(Security security, TimeFrameBuilder timeFrameBuilder,
                                                     DateTime startTime, DateTime endTime, DateTime actualTime)
        {
            List <Candle> candles = new List <Candle>();

            actualTime = startTime;

            while (actualTime < endTime)
            {
                List <Candle> newCandles = _client.GetCandlesForTimes(security.Name,
                                                                      timeFrameBuilder.TimeFrameTimeSpan,
                                                                      actualTime, endTime);

                if (candles.Count != 0 && newCandles.Count != 0)
                {
                    for (int i = 0; i < newCandles.Count; i++)
                    {
                        if (candles[candles.Count - 1].TimeStart >= newCandles[i].TimeStart)
                        {
                            newCandles.RemoveAt(i);
                            i--;
                        }
                    }
                }

                if (newCandles.Count == 0)
                {
                    return(candles);
                }

                candles.AddRange(newCandles);

                actualTime = candles[candles.Count - 1].TimeStart;
            }

            if (candles.Count == 0)
            {
                return(null);
            }

            return(candles);
        }