Beispiel #1
0
 public KLineInfo(KLineInfo prevK, DateTime start)
 {
     //if (TickCount == 0) //因為有可能一分內都沒有tick,所以建構這一分鐘K線的時候,先以上一分的Close作為基礎的開高低收四個價位
     //{
     //    Open = prevK.Close;
     //    Close = prevK.Close;
     //    High = prevK.Close;
     //    Low = prevK.Close;
     //}
     this.StartTime = new DateTime(start.Year, start.Month, start.Day, start.Hour, start.Minute, 0);
     this.EndTime   = start.AddMinutes(1).AddTicks(-1);
     //this.PrevSkKLine = prevTwK;
     this.PrevKLine = prevK;
     TickCount      = 0;
 }
Beispiel #2
0
        public void AddSkKLine(TwKLineData skKLine)
        {
            DateTime dt = skKLine.KDate;

            dt = dt.AddHours(skKLine.KTime.Value.Hour).AddMinutes(skKLine.KTime.Value.Minute);//.AddSeconds(skKLine.KTime.Value.Second);
            KLineInfo kline = this.KLineSeries.Where(x => x.StartTime == dt).FirstOrDefault();

            if (kline != null)
            {
                kline.AddTwKLine(skKLine);
                this.TwKLineCount += 1;
            }
            else
            {
                //TODO:如果沒找到,需要做什麼處理嗎?
            }
        }
Beispiel #3
0
        public void AddTwTick(TickInfo skTick)
        {
            if (this._lastKLine == null) //系統內還沒有任何K線的情況,這種情況有兩種,第一種,系統開盤後才打開,第二種,系統開盤前打開
            {
                //開市時間為0845
                DateTime tmpTime = this._marketOpenTime;
                while (skTick.TickTime >= tmpTime)
                {
                    KLineInfo kline = new KLineInfo(tmpTime);
                    this.KLineSeries.Add(kline);
                    this._lastKLine  = kline;
                    tmpTime          = tmpTime.AddMinutes(1);
                    this.KLineCount += 1;
                }

                this._lastKLine.AddTick(new Tick
                {
                    Close    = skTick.Close,
                    Qty      = skTick.Qty,
                    TickTime = skTick.TickTime
                });
            }
            else
            {
                if (skTick.TickTime > this._lastKLine.EndTime)
                {
                    KLineInfo lastK = new KLineInfo(skTick.TickTime);
                    lastK.AddTick(new Tick
                    {
                        Close    = skTick.Close,
                        Qty      = skTick.Qty,
                        TickTime = skTick.TickTime
                    });

                    this.KLineSeries.Add(lastK);
                    this._lastKLine  = lastK;
                    this.KLineCount += 1;
                }
                else if (skTick.TickTime >= this._lastKLine.StartTime && skTick.TickTime <= this._lastKLine.EndTime)
                {
                    this._lastKLine.AddTick(new Tick
                    {
                        Close    = skTick.Close,
                        Qty      = skTick.Qty,
                        TickTime = skTick.TickTime
                    });
                }
                else //這個tick屬於過去的K線
                {
                    var historyKLine = this.KLineSeries.Where(x => skTick.TickTime >= x.StartTime && skTick.TickTime <= x.EndTime).FirstOrDefault();
                    if (historyKLine != null)
                    {
                        historyKLine.AddTick(new Tick
                        {
                            Close    = skTick.Close,
                            Qty      = skTick.Qty,
                            TickTime = skTick.TickTime
                        });
                    }
                }
            }
        }