Пример #1
0
        public void TestSaveLoadUpdatedDataInfo()
        {
            string path = TestCaseManager.GetTestCasePath(GetType(), "path_updateinfo");

            if (Directory.Exists(path))
            {
                Directory.Delete(path, true);
            }

            UpdatedDataInfo updatedDataInfo = new UpdatedDataInfo(path);

            updatedDataInfo.WriteUpdateInfo_Tick(CODE1, 20140120);
            updatedDataInfo.WriteUpdateInfo_Tick(CODE2, 20140520);
            updatedDataInfo.WriteUpdateInfo_KLine(CODE1, KLinePeriod.KLinePeriod_1Minute, 20140121);
            updatedDataInfo.WriteUpdateInfo_KLine(CODE1, KLinePeriod.KLinePeriod_5Minute, 20140122);
            updatedDataInfo.WriteUpdateInfo_KLine(CODE1, KLinePeriod.KLinePeriod_15Minute, 20140123);
            updatedDataInfo.WriteUpdateInfo_KLine(CODE1, KLinePeriod.KLinePeriod_1Day, 20140124);
            updatedDataInfo.WriteUpdateInfo_KLine(CODE2, KLinePeriod.KLinePeriod_1Minute, 20140525);
            updatedDataInfo.Save();

            UpdatedDataInfo updatedDataInfo2 = new UpdatedDataInfo(path);

            Assert.AreEqual(20140120, updatedDataInfo2.GetLastUpdatedTickData(CODE1));
            Assert.AreEqual(20140520, updatedDataInfo2.GetLastUpdatedTickData(CODE2));

            Assert.AreEqual(20140121, updatedDataInfo2.GetLastUpdatedKLineData(CODE1, KLinePeriod.KLinePeriod_1Minute));
            Assert.AreEqual(20140122, updatedDataInfo2.GetLastUpdatedKLineData(CODE1, KLinePeriod.KLinePeriod_5Minute));
            Assert.AreEqual(20140123, updatedDataInfo2.GetLastUpdatedKLineData(CODE1, KLinePeriod.KLinePeriod_15Minute));
            Assert.AreEqual(20140124, updatedDataInfo2.GetLastUpdatedKLineData(CODE1, KLinePeriod.KLinePeriod_1Day));
            Assert.AreEqual(20140525, updatedDataInfo2.GetLastUpdatedKLineData(CODE2, KLinePeriod.KLinePeriod_1Minute));

            Directory.Delete(path, true);
        }
Пример #2
0
        public string Proceed()
        {
            if (tradingDays == null || tradingDays.Count == 0)
            {
                return("");
            }
            int lastTradingDay = 0;

            for (int i = 0; i < tradingDays.Count; i++)
            {
                int tradingDay = tradingDays[i];
                if (tickDataStore.Exist(code, tradingDay))
                {
                    if (overwrite)
                    {
                        TickData wtickData = (TickData)historyData.GetTickData(code, tradingDay);
                        tickDataStore.Save(code, tradingDay, wtickData);
                        continue;
                    }
                    lastTradingDay = tradingDay;
                    continue;
                }
                TickData tickData = (TickData)historyData.GetTickData(code, tradingDay);
                if (tickData != null)
                {
                    tickDataStore.Save(code, tradingDay, tickData);
                    lastTradingDay = tradingDay;
                }
            }
            if (tradingDays.Count > 0 && updatedDataInfo != null)
            {
                updatedDataInfo.WriteUpdateInfo_Tick(code, lastTradingDay);
                updateInfoStore.Save(updatedDataInfo);
            }
            return(StepDesc + "完成");
        }
Пример #3
0
        private List <int> GetAllNotUpdateTickData(CodeInfo codeInfo, CacheUtils_TradingDay allTradingDayCache, List <int> storedDays, bool isFillUp)
        {
            if (isFillUp)
            {
                HashSet <int> set = new HashSet <int>(storedDays);
                IList <int>   codeAllTradingDays   = GetCodeTradingDays(codeInfo, allTradingDayCache);
                List <int>    allNotUpdateTickData = new List <int>(set.Count);
                for (int i = 0; i < codeAllTradingDays.Count; i++)
                {
                    int day = codeAllTradingDays[i];
                    if (!set.Contains(day))
                    {
                        allNotUpdateTickData.Add(day);
                    }
                }
                return(allNotUpdateTickData);
            }
            else
            {
                /*
                 * 如果已更新数据记录中保存了该合约的最后更新日期,则直接按该信息更新后面的数据
                 * 否则扫描整个目录来获取待更新信息
                 */
                int lastUpdatedDate = updatedDataInfo.GetLastUpdatedTickData(codeInfo.Code);
                int startIndex;
                if (lastUpdatedDate >= 0)
                {
                    int lastSavedUpdateTickIndex = allTradingDayCache.GetTradingDayIndex(lastUpdatedDate);
                    startIndex = lastSavedUpdateTickIndex + 1;
                }
                else
                {
                    if (storedDays.Count == 0)
                    {
                        startIndex = allTradingDayCache.GetTradingDayIndex(codeInfo.Start, false);
                    }
                    else
                    {
                        storedDays.Sort();
                        int lastUpdateIndex = allTradingDayCache.GetTradingDayIndex(storedDays[storedDays.Count - 1]);
                        if (lastUpdateIndex < 0)
                        {
                            //TODO 不应该出现这种情况,TODO 写日志
                        }
                        startIndex = lastUpdateIndex + 1;
                    }

                    //保存更新信息
                    int lastUpdateTickIndex = startIndex - 1;
                    if (lastUpdateTickIndex >= 0 && lastUpdateTickIndex < allTradingDayCache.GetAllTradingDays().Count)
                    {
                        updatedDataInfo.WriteUpdateInfo_Tick(codeInfo.Code, allTradingDayCache.GetAllTradingDays()[lastUpdateTickIndex]);
                    }
                }
                if (startIndex < 0 || startIndex >= allTradingDayCache.GetAllTradingDays().Count)
                {
                    return(null);
                }

                int endIndex = GetEndIndex(codeInfo, allTradingDayCache);
                if (endIndex < startIndex)
                {
                    return(null);
                }

                int len = endIndex - startIndex + 1;
                if (len <= 0)
                {
                    return(null);
                }
                return(allTradingDayCache.GetAllTradingDays().GetRange(startIndex, len));
            }
        }