예제 #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
        private void AddSteps_TickData(List <IStep> steps)
        {
            ITickDataStore tickDataStore = dataStore.CreateTickDataStore();

            List <CodeInfo> allInstruments = historyData.GetInstruments();
            List <int>      allTradingDays = historyData.GetTradingDays();

            CacheUtils_TradingDay tradingDayCache = new CacheUtils_TradingDay(allTradingDays);

            for (int i = 0; i < allInstruments.Count; i++)
            //for (int i = 0; i < 10; i++)
            {
                CodeInfo instrument = allInstruments[i];

                //if (!(instrument.Exchange == "SQ" && instrument.Code.EndsWith("0000")))
                //    continue;

                int lastTradingDay = instrument.End;
                if (lastTradingDay <= 0)
                {
                    lastTradingDay = tradingDayCache.LastTradingDay;
                }
                int lastUpdatedDate = updatedDataInfo.GetLastUpdatedTickData(instrument.Code);
                if (lastUpdatedDate < instrument.Start)
                {
                    lastUpdatedDate = tradingDayCache.GetPrevTradingDay(instrument.Start);
                }

                List <int> allDays;
                if (!isFillUp)
                {
                    if (lastUpdatedDate >= lastTradingDay)
                    {
                        continue;
                    }
                    int startDate = tradingDayCache.GetNextTradingDay(lastUpdatedDate);
                    //如果不填充数据,直接根据最新交易日期和最后更新日期
                    int endDate = instrument.End;
                    if (endDate <= 0)
                    {
                        endDate = allTradingDays[allTradingDays.Count - 1];
                    }

                    //20171015 ww 在不全面更新数据情况下,如果最新的交易日比合约截止时间更新,则不再更新该合约数据
                    int firstNewTradingDay = newTradingDays.Count == 0 ? allTradingDays[allTradingDays.Count - 1] : newTradingDays[0];
                    if (firstNewTradingDay > endDate)
                    {
                        continue;
                    }

                    IList <int> tradingDays = tradingDayCache.GetTradingDays(lastUpdatedDate, endDate);
                    if (tradingDays == null || tradingDays.Count == 0)
                    {
                        continue;
                    }
                    allDays = new List <int>();
                    allDays.AddRange(tradingDays);
                    //allTradingDays
                }
                else
                {
                    //如果填充所有数据
                    List <int> storedAllDays = tickDataStore.GetAllDays(instrument.Code);
                    allDays = GetAllNotUpdateTickData(instrument, tradingDayCache, storedAllDays, isFillUp);
                    if (allDays == null)
                    {
                        continue;
                    }
                }

                AddSteps_TickData_Instrument(steps, instrument.Code, allDays);
            }
        }