public virtual ResizeableArray <CandleStickData> DownloadCandleStickData(TickerInputInfo info)
        {
            CachedCandleStickData savedData = new CachedCandleStickData()
            {
                Exchange = info.Exchange, TickerName = info.TickerName, IntervalMin = info.KlineIntervalMin, StartDate = info.StartDate, EndDate = info.EndDate, BaseCurrency = info.Ticker.BaseCurrency, MarketCurrency = info.Ticker.MarketCurrency
            };
            CachedCandleStickData cachedData = CachedCandleStickData.FromFile(CachedCandleStickData.Directory + "\\" + ((ISupportSerialization)savedData).FileName);

            info.CheckUpdateTime();
            if (cachedData != null)
            {
                if (info.StartDate != DateTime.MinValue && info.StartDate == cachedData.Items[0].Time.Date && info.EndDate == cachedData.Items.Last().Time.Date)
                {
                    return(cachedData.Items);
                }
            }

            DateTime start                        = info.StartDate;
            int      intervalInSeconds            = info.KlineIntervalMin * 60;
            ResizeableArray <CandleStickData> res = new ResizeableArray <CandleStickData>();
            int  deltaCount                       = 500;
            long minCount         = (long)(SettingsStore.Default.SimulationSettings.KLineHistoryIntervalDays) * 24 * 60;
            long candleStickCount = minCount / info.KlineIntervalMin;
            long pageCount        = candleStickCount / deltaCount;
            int  pageIndex        = 0;

            DownloadProgress = 0.0;
            DownloadText     = "Donwloading CandleStick Data for " + info.Exchange + ":" + info.TickerName;

            if (!info.Ticker.Exchange.SupportCandleSticksRange)
            {
                ResizeableArray <CandleStickData> data = info.Ticker.GetCandleStickData(info.KlineIntervalMin, start, intervalInSeconds * deltaCount);
                if (data == null)
                {
                    return(null);
                }
                DownloadProgress = 100;
                var args = RaiseDownloadProgressChanged();
                if (args.Cancel)
                {
                    return(null);
                }

                cachedData       = savedData;
                cachedData.Items = data;
                cachedData.Save();
                return(data);
            }

            while (start.Date < info.EndDate.Date)
            {
                ResizeableArray <CandleStickData> data = info.Ticker.GetCandleStickData(info.KlineIntervalMin, start, intervalInSeconds * deltaCount);
                if (data == null || data.Count == 0)
                {
                    start = start.AddSeconds(intervalInSeconds * deltaCount);
                    continue;
                }
                res.AddRange(data);
                pageIndex++;
                DownloadProgress = pageIndex * 100 / pageCount;
                RaiseDownloadProgressChanged();
                Thread.Sleep(300);
                start = start.AddSeconds(intervalInSeconds * deltaCount);
            }
            cachedData       = savedData;
            cachedData.Items = res;
            cachedData.Save();
            return(res);
        }
        protected virtual ResizeableArray <CandleStickData> DownloadCandleStickData(TickerInputInfo info)
        {
            CachedCandleStickData savedData = new CachedCandleStickData()
            {
                Exchange = info.Exchange, TickerName = info.TickerName, IntervalMin = info.KlineIntervalMin
            };
            CachedCandleStickData cachedData = CachedCandleStickData.FromFile(CachedCandleStickData.Directory + "\\" + ((ISupportSerialization)savedData).FileName);

            if (cachedData != null)
            {
                // outdated
                if (SettingsStore.Default.SimulationSettings.StartTime.Date == cachedData.Items[0].Time.Date)
                {
                    return(cachedData.Items);
                }
            }

            DateTime start             = DateTime.UtcNow.Date;
            int      intervalInSeconds = info.KlineIntervalMin * 60;

            //int candleStickCount = 10000;
            start = start.AddDays(-SettingsStore.Default.SimulationSettings.KLineHistoryIntervalDays);// .AddSeconds(-intervalInSeconds * candleStickCount);
            ResizeableArray <CandleStickData> res = new ResizeableArray <CandleStickData>();
            //List<ResizeableArray<CandleStickData>> splitData = new List<ResizeableArray<CandleStickData>>();
            int  deltaCount       = 500;
            long minCount         = (long)(SettingsStore.Default.SimulationSettings.KLineHistoryIntervalDays) * 24 * 60;
            long candleStickCount = minCount / info.KlineIntervalMin;
            long pageCount        = candleStickCount / deltaCount;
            int  pageIndex        = 0;

            DownloadProgress = 0.0;

            if (!info.Ticker.Exchange.SupportCandleSticksRange)
            {
                ResizeableArray <CandleStickData> data = info.Ticker.GetCandleStickData(info.KlineIntervalMin, start, intervalInSeconds * deltaCount);
                if (data == null)
                {
                    return(null);
                }
                DownloadProgress = 100;
                RaiseDownloadProgressChanged();

                cachedData       = savedData;
                cachedData.Items = data;
                cachedData.Save();
                return(data);
            }

            //for(int i = 0; i < candleStickCount / deltaCount; i++) {
            while (start.Date < DateTime.Now.Date)
            {
                ResizeableArray <CandleStickData> data = info.Ticker.GetCandleStickData(info.KlineIntervalMin, start, intervalInSeconds * deltaCount);
                if (data == null || data.Count == 0)
                {
                    start = start.AddSeconds(intervalInSeconds * deltaCount);
                    continue;
                }
                res.AddRange(data);
                pageIndex++;
                DownloadProgress = pageIndex * 100 / pageCount;
                RaiseDownloadProgressChanged();
                Thread.Sleep(300);
                start = start.AddSeconds(intervalInSeconds * deltaCount);
            }
            cachedData       = savedData;
            cachedData.Items = res;
            cachedData.Save();
            return(res);
        }