/// <summary> /// 检验K线数据正确性 /// </summary> /// <param name="expectedResult">期望的结果</param> /// <param name="klineData">K线数据</param> public static void AssertEqual_KLineData(String expectedResult, IKLineData klineData) { string[] periodArr = expectedResult.Split('\r'); Assert.AreEqual(periodArr.Length, klineData.Length); for (int i = 0; i < klineData.Length; i++) { klineData.BarPos = i; string periodStr = periodArr[i].Trim(); Assert.AreEqual(periodStr, klineData.ToString()); } }
public static void AssertKLineDataResult(IKLineData klineData, String txt) { string[] periodArr = txt.Split('\r'); Assert.AreEqual(periodArr.Length, klineData.Length); for (int i = 0; i < klineData.Length; i++) { klineData.BarPos = i; string periodStr = periodArr[i].Trim(); Assert.AreEqual(periodStr, klineData.ToString()); } }
public static void Save(string path, IKLineData data) { string[] contents = new string[data.Length]; for (int i = 0; i < contents.Length; i++) { data.BarPos = i; contents[i] = data.ToString(); } FileUtils.EnsureParentDirExist(path); File.WriteAllLines(path, contents); }
public void TestKLineDataLoad() { string[] lines = TestCaseManager.LoadTestCaseFile(GetType(), "CsvUtils_KLineData").Split('\r'); IKLineData klineData = CsvUtils_KLineData.LoadByLines(lines); Assert.AreEqual(lines.Length, klineData.Length); for (int i = 0; i < klineData.Length; i++) { klineData.BarPos = i; Assert.AreEqual(lines[i].Trim(), klineData.ToString()); } }
public void TestKLineData_GetRange() { KLineData data = GetKLineData_1Min(); IKLineData data_sub = data.GetRange(100, 200); for (int i = 100; i <= 200; i++) { data.BarPos = i; data_sub.BarPos = i - 100; Assert.AreEqual(data.ToString(), data_sub.ToString()); } }
public void TestKLineData_Sub() { KLineData data = GetKLineData_1Min(); IKLineData data_sub = data.Sub(100, 200); for (int i = 100; i <= 200; i++) { data.BarPos = i; data_sub.BarPos = i - 100; Assert.AreEqual(data.ToString(), data_sub.ToString()); } Assert.AreEqual(101, data_sub.Length); }
public void TestToString() { string res = TestCaseManager.LoadTestCaseFile(GetType(), "KLineData_M01_1Minute"); string[] lines = res.Split('\r'); IKLineData klineData = CsvUtils_KLineData.LoadByLines(lines); for (int i = 0; i < lines.Length; i++) { klineData.BarPos = i; Assert.AreEqual(lines[i].Trim(), klineData.ToString()); } }
public void TestRealDataReader_GetData() { DataReaderFactory fac = ResourceLoader.GetDefaultDataReaderFactory(); IRealTimeDataReader reader = new RealTimeDataReader(fac, "m05", 20100104.093002); ITickData tickData = reader.GetTickData(); Console.WriteLine(tickData); Assert.AreEqual("20100104.093002,3127,2,44492,0,3127,25,3128,173,0", tickData.ToString()); IKLineData klineData = reader.GetKLineData(KLinePeriod.KLinePeriod_15Minute); Console.WriteLine(klineData); Assert.AreEqual("20100104.093,3127,3127,3127,3127,40,0,523048", klineData.ToString()); ITimeLineData timeLineData = reader.GetTimeLineData(); Console.WriteLine(timeLineData); Assert.AreEqual("20100104.093,3127,11,0.35,40,524676", timeLineData.ToString()); }
public void TestKLineMerge() { KLineData data = GetKLineData_1Min(); IKLineData d1 = data.GetRange(0, 99); IKLineData d2 = data.GetRange(100, 199); IKLineData d3 = data.GetRange(200, 299); IKLineData d4 = data.GetRange(300, data.Length - 1); List <IKLineData> dataList = new List <IKLineData>(); dataList.Add(d1); dataList.Add(d2); dataList.Add(d3); dataList.Add(d4); IKLineData dataResult = KLineData.Merge(dataList); Assert.AreEqual(dataResult.Length, data.Length); for (int i = 0; i < data.Length; i++) { data.BarPos = i; dataResult.BarPos = i; Assert.AreEqual(dataResult.ToString(), data.ToString()); } }
public void TestNavigate_Code_Day() { string code = "rb1805"; double time = 20171226.2100; IDataNavigate_Code nav = DataCenter.Default.DataNavigateFactory.CreateDataNavigate_Code(code, time, 100, 0); IKLineData klineData = nav.GetKLineData(KLinePeriod.KLinePeriod_1Day); //for (int i = 0; i < klineData.Length; i++) //{ // Console.WriteLine(klineData.GetBar(i)); //} time = 20171002.09; nav.NavigateTo(time); klineData = nav.GetKLineData(KLinePeriod.KLinePeriod_1Minute); Console.WriteLine(klineData); Assert.AreEqual("20170929.1459,3524,3540,3522,3538,7648,0,487716", klineData.ToString()); //for (int i = 0; i < klineData.Length; i++) //{ // Console.WriteLine(klineData.GetBar(i)); //} }
public string ToString(int index) { return(klineData.ToString(index)); }