private void Save(string strDstDir) { foreach (string futureid in _buffer.Keys) { string fullname = strDstDir + "\\" + futureid + ".day"; var isfile = File.Exists(fullname); bool isRead = true; if (Market == EnumMarket.期货) { FutureDayFile dayfile = new FutureDayFile(); dayfile.Init(fullname); BarSeries daybarlist = new BarSeries(); if (_prgMq.Contains(futureid)) { if (_prgMq.EndTime(futureid).Date == _buffer[futureid][0].TradingDate) { var endtime = _prgMq.EndTime(futureid); endtime = endtime.AddDays(-1); if (endtime > new DateTime()) { isRead = dayfile.Read(daybarlist, new DateTime(), endtime); } } else { isRead = dayfile.Read(daybarlist, new DateTime(), _prgMq.EndTime(futureid)); } if (isRead == false) { _logger.Error("读取文件失败,不准备写入" + fullname + futureid); continue; } daybarlist.AddRange(_buffer[futureid]); dayfile.Write(daybarlist); } else { dayfile.Write(_buffer[futureid]); } } } }
private void Save(string strDstDir, DateTime month) { if (month == default(DateTime)) { return; } foreach (string futureid in _buffer.Keys) { //如果K线根数为0,表示没有K线信息,则直接跳过 if (_buffer[futureid].Count == 0) { continue; } string fullname = strDstDir + "\\" + month.ToString("yyyyMM"); if (!Directory.Exists(fullname)) { Directory.CreateDirectory(fullname); } fullname = fullname + "\\" + futureid + ".min"; try { BarSeries daybarlist = new BarSeries(); if (_prgMq.Contains(futureid)) { //TimeSlice livingtime = fmgr.GetLivingTime(futureid); using (var barfile = new BarFileV1(fullname, EnumMarket.期货)) { var starttime = _prgMq.BeginTime(futureid); var endtime = _prgMq.EndTime(futureid); var tradingdate = _buffer[futureid][0].TradingDate; //如果换月,则需要从当月的1号开始 if (starttime.Month < tradingdate.Month) { starttime = new DateTime(tradingdate.Year, tradingdate.Month, 1); } //如果换月,则不需要读取 if (endtime.Month == tradingdate.Month) { if (_prgMq.EndTime(futureid).Date == _buffer[futureid][0].TradingDate) { endtime = endtime.AddDays(-1); if (endtime >= starttime) { barfile.ReadTradingDays(daybarlist, starttime, endtime); } } else { barfile.ReadTradingDays(daybarlist, _prgMq.BeginTime(futureid), _prgMq.EndTime(futureid)); } } } daybarlist.AddRange(_buffer[futureid]); } else { daybarlist = _buffer[futureid]; } if (File.Exists(fullname)) { File.Delete(fullname); } if (daybarlist.Count > 0) { using (var barfile = new BarFileV1(fullname, EnumMarket.期货, EnumBarType.分钟, 1)) { barfile.Write(daybarlist); } } else { _logger.Error("品种" + futureid + "在" + month + "没有对应的分钟线数据,请查询对应的数据是否有错!"); } } catch (Exception ex) { _logger.Error(fullname + ex.ToString()); throw new Exception("读取文件出错" + fullname); } } _buffer.Clear(); }