コード例 #1
0
ファイル: BarGenerator.cs プロジェクト: yuxi214/MobileQuant
        internal void addTick(Tick tick)
        {
            //
            long minute = tick.UpdateTime.Hour * 100 + tick.UpdateTime.Minute;

            if (!mMinute.Equals(minute))
            {
                OnBarData?.Invoke(mBar);
                mBar = null;
            }
            //
            if (mBar == null)
            {
                mBar = new Min1Bar();
                mBar.InstrumentID = mInstrumentID;
                mBar.OpenTime     = tick.UpdateTime;
                mBar.OpenPrice    = tick.LastPrice;
                mBar.HighPrice    = tick.LastPrice;
                mBar.LowPrice     = tick.LastPrice;
                mBar.ClosePrice   = tick.LastPrice;
            }
            else
            {
                mBar.HighPrice  = mBar.HighPrice < tick.LastPrice ? tick.LastPrice:mBar.HighPrice;
                mBar.LowPrice   = mBar.LowPrice > tick.LastPrice ? tick.LastPrice : mBar.LowPrice;
                mBar.ClosePrice = tick.LastPrice;
            }
            mBar.Volume       = tick.Volume;
            mBar.OpenInterest = tick.OpenInterest;
            mBar.Ticks.Add(tick);
        }
コード例 #2
0
ファイル: BarGenerator.cs プロジェクト: yuxi214/MobileQuant
        internal void addTick(Tick tick)
        {
            if (!tick.InstrumentId.Equals(mInstrumentID))
            {
                return;
            }
            //判断是否需要生成新bar
            if (mBar != null)
            {
                DateTime barTime      = mTickList[0].UpdateTime;
                DateTime tickTime     = tick.UpdateTime;
                int      barQuotient  = (barTime.Day * 1440 + barTime.Hour * 60 + barTime.Minute) / ((int)mSizeType);
                int      tickQuotient = (tickTime.Day * 1440 + tickTime.Hour * 60 + barTime.Minute) / ((int)mSizeType);
                if (!barQuotient.Equals(tickQuotient))
                {
                    OnBarData?.Invoke(mBar, mTickList);
                    mBar      = null;
                    mTickList = null;
                }
            }

            //更新bar数据
            if (mBar == null)
            {
                mBar              = new Bar();
                mTickList         = new List <Tick>();
                mBar.InstrumentId = mInstrumentID;
                mBar.OpenPrice    = tick.LastPrice;
                mBar.HighPrice    = tick.LastPrice;
                mBar.LowPrice     = tick.LastPrice;
                mBar.ClosePrice   = tick.LastPrice;
                mBar.Volume       = tick.Volume;
                mBar.OpenInterest = tick.OpenInterest;
                mBar.BeginTime    = tick.UpdateTime;
                mBar.SizeType     = mSizeType;
            }
            else
            {
                mBar.HighPrice  = mBar.HighPrice < tick.LastPrice ? tick.LastPrice : mBar.HighPrice;
                mBar.LowPrice   = mBar.LowPrice > tick.LastPrice ? tick.LastPrice : mBar.LowPrice;
                mBar.ClosePrice = tick.LastPrice;
            }
            mBar.Volume       = tick.Volume;
            mBar.OpenInterest = tick.OpenInterest;
            mTickList.Add(tick);
        }