static void GenerateKLines() { string[] instrumentIDs = new string[] { //"IC1705","IF1705","IH1705","T1706","TF1706","CF709","FG709", //"JR711","MA709","OI709","RI709","RM709","RS707","SF802", "SM709", //"SR709","TA709","WH709","ZC709","a1709","b1709","bb1705","c1709", //"cs1709","fb1709","i1709","j1709","jd1709","jm1709","l1709","m1709", //"p1709","pp1709","v1709","y1709","ag1706","al1706","au1706","bu1709","cu1706","fu1709", //"hc1710","ni1709","pb1706","rb1710","ru1709","sn1709","wr1710","zn1706" }; foreach (string instrumentID in instrumentIDs) { //var table3 = DBFunctions.GetOrCreateTable<Bar2>(client, "CTPDB", instrumentID + "_1min"); //var barList = table3.Find(new FilterDefinitionBuilder<Bar2>().Empty, null).ToList(); Console.WriteLine(instrumentID); BarSeries bars = new BarSeries(); bars.Interval = 1; bars.IntervalType = IntervalType.Min; bars.InstrumentInfo = new InstrumentInfo { InstrumentID = instrumentID, PriceTick = 0, ProductID = "", VolumeMultiple = 0 }; var table = DBFunctions.GetOrCreateTable <Tick2>(client, "CTPDB", "Tick"); FilterDefinitionBuilder <Tick2> fdb = new FilterDefinitionBuilder <Tick2>(); sw.Restart(); var tickList = table.Find(Builders <Tick2> .Filter.Eq("InstrumentID", instrumentID)).ToList(); sw.Stop(); Console.WriteLine(sw.ElapsedMilliseconds.ToString()); tickList = tickList.OrderBy(t => DateTime.ParseExact(t.UpdateTime, "yyyyMMdd HH:mm:ss", null)).ToList(); foreach (var tick in tickList) { bars.OnRtnTick(tick); } var table2 = DBFunctions.GetOrCreateTable <Bar>(client, "CTPDB", instrumentID + "_1min"); if (bars.Count > 0) { table2.InsertMany(bars.ToArray()); } } }