public BarProvider(DateTime tradingday, BarProviderInfo prdinfo, BarSeries barlist) { TradingDay = tradingday; _prdinfo = prdinfo; _lstslice = CreateDateTimeSlice(tradingday, _prdinfo.Lstslice); if (barlist != null && barlist.Count > 0) { #region _bars.AddRange(barlist); int i = 0; for (; i < _lstslice.Count; ++i) { if (barlist.Last.EndTime < _lstslice[i].BeginTime) { _posBar = i - 1; _posTime = i; break; } else if (barlist.Last.EndTime == _lstslice[i].BeginTime) { if (barlist.Last.BeginTime < _lstslice[i].BeginTime) { _posBar = i - 1; _posTime = i; break; } else if (barlist.Last.BeginTime == _lstslice[i].BeginTime) { _posBar = i; _posTime = i; break; } } else if (barlist.Last.EndTime < _lstslice[i].EndTime) { _posBar = i; _posTime = i; break; } } if (i == _lstslice.Count) { _posTime = _lstslice.Count; _posBar = i; } #endregion } }
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 SaveFuture(string strDstDir, DateTime month) { if (month == default(DateTime)) { return; } foreach (string futureid in _bufferFuture.Keys) { //如果K线根数为0,表示没有K线信息,则直接跳过 if (_bufferFuture[futureid].Count == 0) { continue; } string fullname = strDstDir + "\\" + month.ToString("yyyyMM"); if (!Directory.Exists(fullname)) { Directory.CreateDirectory(fullname); } fullname = fullname + "\\" + futureid + ".day"; if (Market == EnumMarket.期货) { FutureDayFile dayfile = new FutureDayFile(); dayfile.Init(fullname); BarSeries daybarlist = new BarSeries(); if (_prgMq.Contains(futureid)) { var starttime = _prgMq.BeginTime(futureid); var endtime = _prgMq.EndTime(futureid); var tradingdate = _bufferFuture[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 == _bufferFuture[futureid][0].TradingDate) { endtime = endtime.AddDays(-1); if (endtime >= starttime) { dayfile.Read(daybarlist, starttime, endtime); } else { _logger.Error(starttime + "没有读取到日线数据" + endtime + fullname); } } else { dayfile.Read(daybarlist, _prgMq.BeginTime(futureid), _prgMq.EndTime(futureid)); } } daybarlist.AddRange(_bufferFuture[futureid]); } else { daybarlist = _bufferFuture[futureid]; } if (File.Exists(fullname)) { File.Delete(fullname); } if (daybarlist.Count > 0) { dayfile.Write(daybarlist); } else { _logger.Error("品种" + futureid + "在" + month + "没有对应的分钟线数据,请查询对应的数据是否有错!"); } } } _bufferFuture.Clear(); }
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(); }