示例#1
0
        private bool ConvertFile(string strFile, string futureid, DateTime day)
        {
            try
            {
                if (_prgMq.EndTime(futureid) > day)
                {
                    return(true);
                }

                var tickfile = DataFileFactory.CreateTickFile(Market);
                tickfile.Init(Market, strFile, futureid, "");
                var lasttick = tickfile.AgoTick(0);
                if (lasttick == null)
                {
                    _logger.Error("获取构造日k线的tick失败 : " + strFile);
                    return(false);
                }

                if (!_buffer.ContainsKey(futureid))
                {
                    _buffer.Add(futureid, new BarSeries());
                }

                if (!_bufferFuture.ContainsKey(futureid))
                {
                    _bufferFuture.Add(futureid, new BarSeries());
                }

                //构建一根日K线,
                //如果Tick的成交量和成交额=0 (成交稀疏为0)(高开低=0)
                //B 日线的高=开=低=收= Tick的最新价
                //C 日线的量=0 成交额=0
                var bar = new Bar
                {
                    BeginTime = day,
                    EndTime   = day,
                    Close     = lasttick.LastPrice,
                    High      = Math.Abs(lasttick.HighPrice) < 0.00001 ? lasttick.LastPrice : lasttick.HighPrice,
                    Low       = Math.Abs(lasttick.LowPrice) < 0.00001 ? lasttick.LastPrice : lasttick.LowPrice,
                    Open      = Math.Abs(lasttick.OpenPrice) < 0.00001 ? lasttick.LastPrice : lasttick.OpenPrice,

                    PreClose = Math.Abs(lasttick.PreSettlementPrice) > 0.00001
                        ? lasttick.PreSettlementPrice
                        : lasttick.PreClosePrice,
                    Volume       = lasttick.Volume,
                    Turnover     = lasttick.Turnover,
                    OpenInterest = lasttick.OpenInterest,
                    TradingDate  = lasttick.TradingDay
                };

                _buffer[futureid].Insert(0, bar);
                _bufferFuture[futureid].Insert(0, bar);

                // 更新
                if (_beginlist.ContainsKey(futureid))
                {
                    if (_beginlist[futureid] > day)
                    {
                        _beginlist[futureid] = day;
                    }
                }
                else
                {
                    _beginlist.Add(futureid, day);
                }

                if (_endlist.ContainsKey(futureid))
                {
                    if (_endlist[futureid] < day)
                    {
                        _endlist[futureid] = day;
                    }
                }
                else
                {
                    _endlist.Add(futureid, day);
                }

                return(false);
            }
            catch (Exception ex)
            {
                _logger.Error(ex.ToString());
                return(false);
            }
        }
示例#2
0
        private bool ConvertFile(string strFile, string futureid, DateTime day)
        {
            //由于夜盘的存在,最后一天需要重复转一次
            if (_prgMq.EndTime(futureid) > day)
            {
                return(true);
            }

            // FutureTickFile tickfile = new FutureTickFile();
            var tickfile = DataFileFactory.CreateTickFile(EnumMarket.期货);

            tickfile.Init(EnumMarket.期货, strFile, futureid, "");
            List <Tick> ticklist = new List <Tick>();

            if (!tickfile.Read(ticklist, 0, int.MaxValue))
            {
                _logger.Error("读取文件失败(" + strFile + ")");

                return(false);
            }

            if (!_buffer.ContainsKey(futureid))
            {
                _buffer.Add(futureid, new BarSeries());
            }

            //为了避免交易时间段的变化,每天都需要新建一个barproviderinfo
            //if (!tslist.ContainsKey(futureid))
            //{
            //    tslist.Add(futureid, BaseBarHelper.CreateBars(fmgr, futureid, 0, 1, EnumBarType.分钟, day));
            //}
            #region 如果夜盘没有tick,不补齐夜盘分钟线
            bool isFillNight = true;
            var  nightTicks  = from d in ticklist where d.DateTime.Hour > 20 || d.DateTime.Hour < 3 select d;
            if (!nightTicks.Any())
            {
                isFillNight = false;
            }
            #endregion

            var barproviderinfo = BaseBarHelper.CreateBars(_fmgr, futureid, 0, 1, EnumBarType.分钟, day, isFillNight);

            //if (tslist.ContainsKey(futureid) && tslist[futureid] != null)
            if (barproviderinfo != null)
            {
                BarProvider provider = new BarProvider(day, barproviderinfo)
                {
                    AllBlankBar = AllBlankBar
                };

                #region

                foreach (Tick tick in ticklist)
                {
                    provider.AddTick(tick);//如果白盘没有tick,不需要过滤,因为不会加工
                }
                if (provider.Bars != null && provider.Bars.Count > 0)
                {
                    //根据bar.volume来过滤夜盘的bar,不够严谨
                    // var bars = CheckIfNoNight(provider.Bars); //对于整个21:00-2:00夜盘bvolume为0的bar过滤掉
                    _buffer[futureid].InsertRange(0, provider.Bars);

                    // 更新
                    if (_beginlist.ContainsKey(futureid))
                    {
                        if (_beginlist[futureid] > day)
                        {
                            _beginlist[futureid] = day;
                        }
                    }
                    else
                    {
                        _beginlist.Add(futureid, day);
                    }

                    if (_endlist.ContainsKey(futureid))
                    {
                        if (_endlist[futureid] < day)
                        {
                            _endlist[futureid] = day;
                        }
                    }
                    else
                    {
                        _endlist.Add(futureid, day);
                    }
                }

                #endregion
            }
            else
            {
                _logger.Error("期货转化分钟线时发现合约[" + futureid + "]在Future.XML中不存在,导致BarProvider为空");
            }

            return(false);
        }