コード例 #1
0
        public IKLineData GetKLineDataByTick(string code, DataReaderFactory dataReaderFactory, KLinePeriod period, IList <int> dates)
        {
            IKLineData        lastKLineData = null;
            float             lastPrice     = -1;
            List <IKLineData> klineDataList = new List <IKLineData>();

            for (int i = 0; i < dates.Count; i++)
            {
                int             openDate  = dates[i];
                TickData        tickdata  = dataReaderFactory.TickDataReader.GetTickData(code, openDate);
                List <double[]> openTimes = dataProvider.GetOpenTime(code, openDate);
                KLineData       klineData;
                if (tickdata != null)
                {
                    klineData = DataTransfer_Tick2KLine.Transfer(tickdata, period, openTimes, lastPrice);
                    klineDataList.Add(klineData);
                    lastPrice = klineData.arr_end[klineData.Length - 1];
                }
                else
                {
                    klineData = GetEmptyDayKLineData(code, openDate, openTimes, dataReaderFactory.OpenDateReader, lastKLineData);
                    klineDataList.Add(klineData);
                }
                lastKLineData = klineData;
            }
            if (klineDataList.Count == 0)
            {
                return(null);
            }
            IKLineData data = KLineData.Merge(klineDataList);

            return(data);
        }
コード例 #2
0
        private IKLineData UpdateByTick(string code, DataReaderFactory dataReaderFactory, KLinePeriod period)
        {
            String         path      = utils.GetKLineDataPath(code, period);
            KLineDataStore store     = new KLineDataStore(path);
            int            lastDate  = (int)store.GetLastTime();
            List <int>     openDates = dataProvider.GetOpenDates();
            int            lastIndex;

            if (lastDate < 0)
            {
                lastIndex = -1;
            }
            else
            {
                lastIndex = openDates.IndexOf(lastDate);
            }

            float             lastPrice     = -1;
            List <IKLineData> klineDataList = new List <IKLineData>();

            for (int i = lastIndex + 1; i < openDates.Count; i++)
            {
                int      openDate = openDates[i];
                TickData tickdata = dataReaderFactory.TickDataReader.GetTickData(code, openDate);
                if (tickdata != null)
                {
                    List <double[]> openTimes = dataProvider.GetOpenTime(code, openDate);
                    KLineData       klineData = DataTransfer_Tick2KLine.Transfer(tickdata, period, openTimes, lastPrice);
                    klineDataList.Add(klineData);
                    lastPrice = klineData.arr_end[klineData.Length - 1];
                }
            }
            if (klineDataList.Count == 0)
            {
                return(null);
            }
            IKLineData data = KLineData.Merge(klineDataList);

            store.Append(data);
            return(data);
        }