//[TestMethod] public void TestReadCsvLeve2() { FileInfo fi = new FileInfo(@"F:\BaiduYunDownload\20141225\20141225.csv"); FileInfo fo = new FileInfo(@"F:\BaiduYunDownload\20141225\20141225.pd0"); PbTickSerializer pts = new PbTickSerializer(); using (Stream stream = File.Open(@"F:\BaiduYunDownload\20141225\20141225.pd0", FileMode.Create)) { using (StreamReader file = new StreamReader(fi.OpenRead())) { int i = 0; string str = file.ReadLine(); do { ++i; str = file.ReadLine(); if (str == null) break; string[] arr = str.Split(','); PbTick tick = new PbTick(); pts.Codec.SetSymbol(tick, arr[0]); tick.Config = new ConfigInfo().Default(); if (arr[0].StartsWith("TF")) { tick.Config.SetTickSize(0.002); tick.Config.ContractMultiplier = 10000; } else { tick.Config.SetTickSize(0.2); tick.Config.ContractMultiplier = 300; } tick.Config.Time_ssf_Diff = 5; pts.Codec.Config = tick.Config; //if(i == 1) //{ // tick.Split = new StockSplitInfo(); // tick.Split.StockDividend = 10; //} //if(i == 2) //{ // tick.Split = new StockSplitInfo(); // tick.Split.CashDividend = 10; //} tick.ActionDay = int.Parse(arr[5]); int time = int.Parse(arr[6]); tick.Time_HHmm = time / 100000; tick.Time_____ssf__ = time % 100000 / 100; tick.Time________ff = time % 100; pts.Codec.SetLastPrice(tick, double.Parse(arr[8])); pts.Codec.SetHigh(tick, double.Parse(arr[9])); pts.Codec.SetLow(tick, double.Parse(arr[10])); pts.Codec.SetVolume(tick, int.Parse(arr[11])); pts.Codec.SetTurnover(tick, int.Parse(arr[12])); pts.Codec.SetOpenInterest(tick, int.Parse(arr[16])); pts.Codec.SetAskPrice(tick, 1, double.Parse(arr[17])); pts.Codec.SetAskPrice(tick, 2, double.Parse(arr[18])); pts.Codec.SetAskPrice(tick, 3, double.Parse(arr[19])); pts.Codec.SetAskPrice(tick, 4, double.Parse(arr[20])); pts.Codec.SetAskPrice(tick, 5, double.Parse(arr[21])); pts.Codec.SetAskSize(tick, 1, int.Parse(arr[22])); pts.Codec.SetAskSize(tick, 2, int.Parse(arr[23])); pts.Codec.SetAskSize(tick, 3, int.Parse(arr[24])); pts.Codec.SetAskSize(tick, 4, int.Parse(arr[25])); pts.Codec.SetAskSize(tick, 5, int.Parse(arr[26])); pts.Codec.SetBidPrice(tick, 1, double.Parse(arr[27])); pts.Codec.SetBidPrice(tick, 2, double.Parse(arr[28])); pts.Codec.SetBidPrice(tick, 3, double.Parse(arr[29])); pts.Codec.SetBidPrice(tick, 4, double.Parse(arr[30])); pts.Codec.SetBidPrice(tick, 5, double.Parse(arr[31])); pts.Codec.SetBidSize(tick, 1, int.Parse(arr[32])); pts.Codec.SetBidSize(tick, 2, int.Parse(arr[33])); pts.Codec.SetBidSize(tick, 3, int.Parse(arr[34])); pts.Codec.SetBidSize(tick, 4, int.Parse(arr[35])); pts.Codec.SetBidSize(tick, 5, int.Parse(arr[36])); pts.Write(tick, new Stream[] { stream }); } while (str != null); file.Close(); } } }
//[TestMethod] //public void TestDataFile() //{ // //var stream = new MemoryStream(File.ReadAllBytes("test.data")); // //var serializer = new PbTickSerializer(); // //PbTick raw; // //var tick = serializer.Read(stream, out raw); // //Assert.AreNotEqual(null, tick); //} //[TestMethod] public void TestReadCsvLeve1() { FileInfo fi = new FileInfo(@"F:\BaiduYunDownload\IF1406\IF1406.csv"); FileInfo fo = new FileInfo(@"F:\BaiduYunDownload\IF1406\IF1406.pd0"); PbTickSerializer pts = new PbTickSerializer(); pts.Codec.Config.SetTickSize(0.2); pts.Codec.TickSize = pts.Codec.Config.GetTickSize(); pts.Codec.Config.Time_ssf_Diff = 5; using (Stream stream = File.Open(@"F:\BaiduYunDownload\IF1406\IF1406.pd0", FileMode.Create)) { using (StreamReader file = new StreamReader(fi.OpenRead())) { int i = 0; string str = file.ReadLine(); do { ++i; str = file.ReadLine(); if (str == null) break; string[] arr = str.Split(','); DateTime dt = DateTime.Parse(arr[0]).AddMilliseconds(int.Parse(arr[1])); string symbol = arr[2]; double price = double.Parse(arr[3]); int vol = int.Parse(arr[4]); int openint = int.Parse(arr[5]); double bid = double.Parse(arr[6]); int bidSize = int.Parse(arr[7]); double ask = double.Parse(arr[8]); int askSize = int.Parse(arr[9]); PbTick tick = new PbTick(); tick.Config = pts.Codec.Config; pts.Codec.SetLastPrice(tick, price); pts.Codec.SetVolume(tick, vol); pts.Codec.SetSymbol(tick, symbol); pts.Codec.SetActionDay(tick, dt.Date); pts.Codec.SetUpdateTime(tick, dt - dt.Date); pts.Codec.SetBidPrice(tick, 1, bid); pts.Codec.SetBidSize(tick, 1, bidSize); pts.Codec.SetAskPrice(tick, 1, ask); pts.Codec.SetAskSize(tick, 1, askSize); pts.Write(tick, new Stream[] { stream }); //if (i == 1000000) // break; } while (str != null); file.Close(); } } Console.WriteLine("结束了"); }