Example #1
0
        public void TestMethod1()
        {
            var exampleDay_600036 = ExampleStockKLineDay_600036();//2年:522
            var exampleDay_000400 = ExampleStockKLineDay_000400();//1年:261
            List<string> stockCodes = ExampleStockCodes();

            var repository = new StockKLineDataRepository();

            #region 日K线

            foreach(var it in exampleDay_600036)
            {
                if (!repository.Exists("600036", KLineType.Day, it.Time))
                    repository.Add("600036", KLineType.Day, it);
            }

            foreach (var it in exampleDay_000400)
            {
                if (!repository.Exists("000400", KLineType.Day, it.Time))
                    repository.Add("000400", KLineType.Day, it);
            }

            var dataDay_600036_20140111 = repository.GetData("600036", KLineType.Day, new DateTime(2014, 1, 11));//周末没有数据
            Assert.IsNull(dataDay_600036_20140111);
            var dataDay_600036_20141013 = repository.GetData("600036", KLineType.Day, new DateTime(2014, 10, 13));
            Assert.IsNotNull(dataDay_600036_20141013);
            Assert.IsTrue(dataDay_600036_20141013.Time == new DateTime(2014, 10, 13));

            var dataDay_000400_20151011 = repository.GetData("000400", KLineType.Day, new DateTime(2015, 10, 11));//周末没有数据
            Assert.IsNull(dataDay_000400_20151011);
            var dataDay_000400_20151012 = repository.GetData("000400", KLineType.Day, new DateTime(2015, 10, 12));
            Assert.IsNotNull(dataDay_000400_20151012);
            Assert.IsTrue(dataDay_000400_20151012.Time == new DateTime(2015, 10, 12));

            var dataDay_600036_20140101_20151231 = repository.GetData("600036", KLineType.Day, new DateTime(2014, 1, 1), new DateTime(2015, 12, 31)).ToList();
            Assert.IsNotNull(dataDay_600036_20140101_20151231);
            Assert.IsTrue(dataDay_600036_20140101_20151231.Count == exampleDay_600036.Count());
            Assert.IsTrue(dataDay_600036_20140101_20151231[4].Time == new DateTime(2014, 1, 7));

            var dataDay_000400_20150101_20151231 = repository.GetData("000400", KLineType.Day, new DateTime(2015, 1, 1), new DateTime(2015, 12, 31)).ToList();
            Assert.IsNotNull(dataDay_000400_20150101_20151231);
            Assert.IsTrue(dataDay_000400_20150101_20151231.Count == exampleDay_000400.Count());
            Assert.IsTrue(dataDay_000400_20150101_20151231[6].Time == new DateTime(2015, 1, 9));

            var latestDay = repository.GetLatest(stockCodes, KLineType.Day).ToList();
            Assert.IsNotNull(latestDay);
            Assert.IsTrue(latestDay.Count == 2);
            Assert.IsTrue(latestDay[0].Time == new DateTime(2015, 12, 31));
            Assert.IsTrue(latestDay[1].Time == new DateTime(2015, 12, 31));

            #endregion
        }
Example #2
0
        public void TestMethod2()
        {
            var exampleMin1_600036 = ExampleStockKLineMin1_600036();//1年:70992
            List<string> stockCodes = ExampleStockCodes();

            var repository = new StockKLineDataRepository();

            #region 1分钟线

            if (!FolderExists("600036", KLineType.Min1))
            {
                foreach (var it in exampleMin1_600036)
                {
                    //if (!repository.Exists("600036", KLineType.Min1, it.Time))//加上判断之后,效率太低了
                    repository.Add("600036", KLineType.Min1, it);
                }
            }

            Assert.IsFalse(repository.Exists("600036", KLineType.Min1, new DateTime(2015, 1, 11, 10, 30, 00)));
            var dataMin1_600036_201501111030 = repository.GetData("600036", KLineType.Min1, new DateTime(2015, 1, 11, 10, 30, 00));//周末没有数据
            Assert.IsNull(dataMin1_600036_201501111030);

            Assert.IsTrue(repository.Exists("600036", KLineType.Min1, new DateTime(2015, 10, 13, 10, 30, 00)));
            var dataMin1_600036_201510131030 = repository.GetData("600036", KLineType.Min1, new DateTime(2015, 10, 13, 10, 30, 00));
            Assert.IsNotNull(dataMin1_600036_201510131030);
            Assert.IsTrue(dataMin1_600036_201510131030.Time == new DateTime(2015, 10, 13, 10, 30, 00));

            var dataMin1_600036_20150101_20151231 = repository.GetData("600036", KLineType.Min1, new DateTime(2015, 1, 1, 9, 0, 0), new DateTime(2015, 12, 31, 15, 0, 0)).ToList();
            Assert.IsNotNull(dataMin1_600036_20150101_20151231);
            Assert.IsTrue(dataMin1_600036_20150101_20151231.Count == exampleMin1_600036.Count());
            Assert.IsTrue(dataMin1_600036_20150101_20151231[10].Time == new DateTime(2015, 1, 1, 9, 10, 0));

            var latestMin1 = repository.GetLatest(stockCodes, KLineType.Min1).ToList();
            Assert.IsNotNull(latestMin1);
            Assert.IsTrue(latestMin1.Count == 1);
            Assert.IsTrue(latestMin1[0].Time == new DateTime(2015, 12, 31, 15, 0, 0));

            #endregion
        }
Example #3
0
        public void TestMethod3()
        {
            var exampleMin5_600036 = ExampleStockKLineMin5_600036();//1年:14616
            var exampleMin5_000400 = ExampleStockKLineMin5_000400();//1年:14616
            List<string> stockCodes = ExampleStockCodes();

            var repository = new StockKLineDataRepository();

            #region 5分钟K线

            if (!FolderExists("600036", KLineType.Min5))
            {
                foreach (var it in exampleMin5_600036)
                {
                    //if (!repository.Exists("600036", KLineType.Min5, it.Time))
                        repository.Add("600036", KLineType.Min5, it);
                }
            }

            if (!FolderExists("000400", KLineType.Min5))
            {
                foreach (var it in exampleMin5_000400)
                {
                    //if (!repository.Exists("000400", KLineType.Min5, it.Time))
                        repository.Add("000400", KLineType.Min5, it);
                }
            }

            Assert.IsFalse(repository.Exists("600036", KLineType.Min5, new DateTime(2015, 1, 11, 10, 55, 0)));
            var dataMin5_600036_201501111055 = repository.GetData("600036", KLineType.Min5, new DateTime(2015, 1, 11, 10, 55, 0));//周末没有数据
            Assert.IsNull(dataMin5_600036_201501111055);

            Assert.IsTrue(repository.Exists("600036", KLineType.Min5, new DateTime(2015, 10, 13, 10, 55, 0)));
            var dataMin5_600036_201510131055 = repository.GetData("600036", KLineType.Min5, new DateTime(2015, 10, 13, 10, 55, 0));
            Assert.IsNotNull(dataMin5_600036_201510131055);
            Assert.IsTrue(dataMin5_600036_201510131055.Time == new DateTime(2015, 10, 13, 10, 55, 0));

            var dataMin5_000400_201510111335 = repository.GetData("000400", KLineType.Min5, new DateTime(2015, 10, 11, 13, 35, 0));//周末没有数据
            Assert.IsNull(dataMin5_000400_201510111335);
            var dataMin5_000400_201510121335 = repository.GetData("000400", KLineType.Min5, new DateTime(2015, 10, 12, 13, 35, 0));
            Assert.IsNotNull(dataMin5_000400_201510121335);
            Assert.IsTrue(dataMin5_000400_201510121335.Time == new DateTime(2015, 10, 12, 13, 35, 0));

            var dataMin5_600036_20150101_20151231 = repository.GetData("600036", KLineType.Min5, new DateTime(2015, 1, 1, 9, 0, 0), new DateTime(2015, 12, 31, 15, 0, 0)).ToList();
            Assert.IsNotNull(dataMin5_600036_20150101_20151231);
            Assert.IsTrue(dataMin5_600036_20150101_20151231.Count == exampleMin5_600036.Count());
            Assert.IsTrue(dataMin5_600036_20150101_20151231[1].Time == new DateTime(2015, 1, 1, 9, 5, 0));

            var dataMin5_000400_20150101_20151231 = repository.GetData("000400", KLineType.Min5, new DateTime(2015, 1, 1, 9, 0, 0), new DateTime(2015, 12, 31, 15, 0, 0)).ToList();
            Assert.IsNotNull(dataMin5_000400_20150101_20151231);
            Assert.IsTrue(dataMin5_000400_20150101_20151231.Count == exampleMin5_000400.Count());
            Assert.IsTrue(dataMin5_000400_20150101_20151231[2].Time == new DateTime(2015, 1, 1, 9, 10, 0));

            var latestMin5 = repository.GetLatest(stockCodes, KLineType.Min5).ToList();
            Assert.IsNotNull(latestMin5);
            Assert.IsTrue(latestMin5.Count == 2);
            Assert.IsTrue(latestMin5[0].Time == new DateTime(2015, 12, 31, 15, 0, 0));
            Assert.IsTrue(latestMin5[1].Time == new DateTime(2015, 12, 31, 15, 0, 0));

            #endregion
        }