예제 #1
0
        public CandleChart GetCandles(DateTime startTime, int timeInterval)
        {
            //Create a list of CandleSticks
            List <CandleStick> candles = new List <CandleStick>();

            DateTime currentTime = startTime;
            DateTime endInterval = startTime.AddMinutes(timeInterval);

            TimeSpan span         = DateTime.Now.Subtract(startTime);
            int      maxIntervals = Convert.ToInt32(Math.Ceiling(((decimal)span.Minutes / (decimal)timeInterval)));

            int currentIndex = 0;
            //int lastIndex = 0;
            int currentDataCount = CurrentData.Count;

            //Generate the data for each candle stick
            for (int i = 0; i < maxIntervals;)
            {
                if (currentIndex >= currentDataCount)
                {
                    break;
                }
                List <CandleStickDataPoint> candleStickDataPoints = new List <CandleStickDataPoint>();
                for (int ii = currentIndex; ii < currentDataCount; ii++)
                {
                    CurrentData data = CurrentData.ElementAt <CurrentData>(ii);
                    if (data != null)
                    {
                        if (data.LastUpdate >= startTime && data.LastUpdate < endInterval)
                        {
                            candleStickDataPoints.Add(new CandleStickDataPoint()
                            {
                                Price = data.Price, Time = data.LastUpdate
                            });
                        }

                        if (data.LastUpdate >= endInterval)
                        {
                            break;
                        }
                    }
                    currentIndex++;
                }
                if (candleStickDataPoints != null && candleStickDataPoints.Count > 0)
                {
                    candles.Add(new CandleStick(candleStickDataPoints)
                    {
                        Index = i
                    });
                    i++;
                }
            }
            return(new CandleChart(candles, this.Instrument));
        }