public void TestKLineDataStore_LoadByDate() { string path = TestCaseManager.GetTestCasePath(GetType(), "output_20100107_20100120"); IKLineData data = MockDataLoader.GetKLineData("m1005", 20100107, 20100120, KLinePeriod.KLinePeriod_1Minute); KLineDataStore_File_Single store = new KLineDataStore_File_Single(path); store.Save(data); KLineDataStore_File_Single store2 = new KLineDataStore_File_Single(path); IKLineData data2 = store2.Load(20100107, 20120111); AssertUtils.PrintKLineData(data2); File.Delete(path); }
public void TestKLineDataStore_SaveLoad() { IKLineData klineData = MockDataLoader.GetKLineData("m1005", 20100107, 20100120, KLinePeriod.KLinePeriod_1Minute); String path = TestCaseManager.GetTestCasePath(GetType(), "output_20100107_20100120"); KLineDataStore_File_Single store = new KLineDataStore_File_Single(path); store.Save(klineData); KLineDataStore_File_Single store2 = new KLineDataStore_File_Single(path); KLineData klineData2 = store.LoadAll(); AssertUtils.AssertEqual_KLineData(klineData, klineData2); File.Delete(path); }
public void TestKLineDataStore_Append() { IKLineData klineData = MockDataLoader.GetKLineData("m1005", 20100107, 20100114, KLinePeriod.KLinePeriod_1Minute); IKLineData klineData2 = MockDataLoader.GetKLineData("m1005", 20100115, 20100120, KLinePeriod.KLinePeriod_1Minute); List <IKLineData> ks = new List <IKLineData>(); ks.Add(klineData); ks.Add(klineData2); IKLineData klineData_Merge = KLineData.Merge(ks); String path = TestCaseManager.GetTestCasePath(GetType(), "output_append"); KLineDataStore_File_Single store = new KLineDataStore_File_Single(path); store.Save(klineData); store.Append(klineData2); IKLineData klineData_Merge2 = store.LoadAll(); AssertUtils.AssertEqual_KLineData(klineData_Merge, klineData_Merge2); File.Delete(path); }
public void DoIndex() { if (!File.Exists(path)) { return; } String indexPath = path + ".index"; KLineDataStore_File_Single store = new KLineDataStore_File_Single(path); IKLineData klineData = store.LoadAll(); List <SplitterResult> results = DaySplitter.Split(klineData); List <String> indeies = new List <string>(results.Count); for (int i = 0; i < results.Count; i++) { indeies.Add(results[i].ToString()); } File.WriteAllLines(indexPath, indeies.ToArray()); //FileStream file = new FileStream(path, FileMode.Open); //try //{ //indeies.Add(((int)time).ToString() + "," + currentIndex); //File.WriteAllLines(indexPath, indeies.ToArray()); //double lastTime = GetTimeByIndex(file, 0); //double time = GetTimeByIndex(file, 1); ////KLinePeriod period = KLineData.GetPeriod(lastTime, time); ////算法 //int len = GetLength(file); //int currentIndex = 0; //bool hasNight = false; //for (int index = 1; index < len; index++) //{ // time = GetTimeByIndex(file, index); // int date = (int)time; // int lastDate = (int)lastTime; // //夜盘开始,则一定是新的一天开始 // if (IsNightStart(time, lastTime)) // { // indeies.Add(((int)lastTime).ToString() + "," + currentIndex.ToString()); // currentIndex = index; // hasNight = true; // } // else if (hasNight) // { // //对于夜盘来说,如果到了第二天,则说明夜盘结束了,此时不算新的一天开始 // if (date != lastDate) // hasNight = false; // } // //只要过了夜都算第二天的 // else if (date != lastDate) // { // indeies.Add(((int)lastTime).ToString() + "," + currentIndex.ToString()); // currentIndex = index; // } // lastTime = time; //} //} //finally //{ // //file.Close(); //} }