コード例 #1
0
        public void TestKLineDataIndex_DoIndex_Normal()
        {
            KLineData  data_ = ResourceLoader.GetKLineData_1Min();
            IKLineData data  = data_.GetRange(0, 449);

            MockDataProvider provider = new MockDataProvider();

            provider.DataPathDir = "testindex";
            String targetPath = provider.GetDataPath() + "\\testindex.kline";

            KLineDataStore store = new KLineDataStore(targetPath);

            store.Save(data);

            KLineDataIndexer indexer = new KLineDataIndexer(targetPath);

            indexer.DoIndex();

            KLineDataIndexResult result = indexer.GetIndexResult();

            Assert.AreEqual(2, result.DateList.Count);
            Assert.AreEqual(20131202, result.DateList[0]);
            Assert.AreEqual(20131203, result.DateList[1]);

            data = data_.GetRange(450, data_.Length - 1);
            store.Append(data);
            indexer.DoIndex();
            result = indexer.GetIndexResult();
            Assert.AreEqual(10, result.DateList.Count);

            Directory.Delete(provider.GetDataPath(), true);
        }
コード例 #2
0
        private void DoUpdate(String code, DataReaderFactory tmpFac, IKLineData data, KLinePeriod period)
        {
            //TODO 检查已有文件的时间
            IKLineData     data_Target = DataTransfer_KLine2KLine.Transfer(data, period);
            String         path        = utils.GetKLineDataPath(code, period);
            KLineDataStore store       = new KLineDataStore(path);

            store.Append(data_Target);
        }
コード例 #3
0
        public IKLineData UpdateByKLine(String code, DataReaderFactory dataReaderFactory, KLinePeriod period, IKLineData originalData)
        {
            IKLineData     data_Target = DataTransfer_KLine2KLine.Transfer(originalData, period);
            String         path        = utils.GetKLineDataPath(code, period);
            KLineDataStore store       = new KLineDataStore(path);

            store.Append(data_Target);
            return(data_Target);
        }
コード例 #4
0
        private void UpdateBy1Minute(String code, DataReaderFactory dataReaderFactory, KLinePeriod period)
        {
            int            lastDate    = dataReaderFactory.KLineDataReader.GetLastDate(code, period);
            IKLineData     data        = dataReaderFactory.KLineDataReader.GetData(code, lastDate + 1, int.MaxValue, period);
            IKLineData     data_Target = DataTransfer_KLine2KLine.Transfer(data, period);
            String         path        = utils.GetKLineDataPath(code, period);
            KLineDataStore store       = new KLineDataStore(path);

            store.Append(data_Target);
        }
コード例 #5
0
        public IKLineData UpdateByTick(string code, DataReaderFactory dataReaderFactory, KLinePeriod period, List <int> dates)
        {
            String         path  = utils.GetKLineDataPath(code, period);
            KLineDataStore store = new KLineDataStore(path);

            IKLineData data = GetKLineDataByTick(code, dataReaderFactory, period, dates);

            store.Append(data);
            return(data);
        }
コード例 #6
0
        public int GetUpdateFirstTime(String code, DataReaderFactory dataReaderFactory, KLinePeriod period)
        {
            String path = utils.GetKLineDataPath(code, period);

            if (!File.Exists(path))
            {
                return(-1);
            }
            KLineDataStore store = new KLineDataStore(path);
            double         time  = store.GetFirstTime();

            return((int)time);
        }
コード例 #7
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);
        }
コード例 #8
0
        public void TestKLineDataIndex_DoIndex_HasNight()
        {
            KLineData klineData = ResourceLoader.GetKLineData(Resources.KLineData_M05_20130101_20151231_1Minute);

            String         targetPath = GetTestOutputPath() + "M05_20130101_20151231_1Minute.kline";
            KLineDataStore store      = new KLineDataStore(targetPath);

            store.Save(klineData);

            KLineDataIndexer indexer = new KLineDataIndexer(targetPath);

            indexer.DoIndex();

            string indexPath = targetPath + ".index";

            string[] indexLines = File.ReadAllLines(indexPath);
            string[] lines      = Resources.KLineData_M05_20130101_20151231_1Minute_Index.Split('\r');
            Assert.AreEqual(lines.Length, indexLines.Length);
            for (int i = 0; i < lines.Length; i++)
            {
                Assert.AreEqual(lines[i].Trim(), indexLines[i].Trim());
            }
            Directory.Delete(GetTestOutputPath(), true);
        }