Ejemplo n.º 1
0
        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]);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        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();
        }