コード例 #1
0
 /// <summary>
 /// >=1 means added
 /// 0 means last element updated
 /// -1 means nothing changed
 /// </summary>
 /// <param name="t"></param>
 /// <param name="o"></param>
 /// <param name="h"></param>
 /// <param name="l"></param>
 /// <param name="c"></param>
 /// <param name="v"></param>
 /// <param name="isTriggerDataAdded"></param>
 /// <returns></returns>
 public int AddUpdate(long t, double o, double h, double l, double c, double v, bool isTriggerDataAdded = false)
 {
     if (this.Count == 0 || t > this.LastTime)
     {
         Open.Add(o);
         High.Add(h);
         Low.Add(l);
         Close.Add(c);
         Volume.Add(v);
         Time.Add(t);
         if (isTriggerDataAdded)
         {
             OnDataAddedOrUpdated?.Invoke(this, this, 1);
         }
         return(1);
     }
     else if (t == this.LastTime)
     {
         Open[this.Count - 1]   = o;
         High[this.Count - 1]   = h;
         Low[this.Count - 1]    = l;
         Close[this.Count - 1]  = c;
         Volume[this.Count - 1] = v;
         if (isTriggerDataAdded)
         {
             OnDataAddedOrUpdated?.Invoke(this, this, 0);
         }
         return(0);
     }
     return(-1);
 }
コード例 #2
0
        public int AddUpdate(string symbol, int interval, long t, double o, double h, double l, double c, double v, bool isTriggerDataAdded = false)
        {
            if (this.Symbol != symbol || this.Interval < interval || this.Interval % interval != 0)
            {
                return(0);
            }

            var time = t / this.Interval * this.Interval;

            if (this.Count == 0 || time > this.LastTime)
            {
                Open.Add(o);
                High.Add(h);
                Low.Add(l);
                Close.Add(c);
                Volume.Add(v);
                Time.Add(time);
                if (isTriggerDataAdded)
                {
                    OnDataAddedOrUpdated?.Invoke(this, this, 1);
                }
                return(1);
            }
            else if (time == this.LastTime)
            {
                High[this.Count - 1]  = Math.Max(h, High[this.Count - 1]);
                Low[this.Count - 1]   = Math.Min(Low[this.Count - 1], l);
                Close[this.Count - 1] = c;
                if (interval == this.Interval)
                {
                    Volume[this.Count - 1] = v;
                }
                else
                {
                    Volume[this.Count - 1] += v;
                }
                if (isTriggerDataAdded)
                {
                    OnDataAddedOrUpdated?.Invoke(this, this, 0);
                }
                return(0);
            }
            return(-1);
        }
コード例 #3
0
        public int Append(IQuoteCapture q, bool isTriggerDataUpdated = false)
        {
            if (q == null || q.Count <= 0 || q.LastTime <= this.LastTime || this.Symbol != q.Symbol)
            {
                return(0);
            }

            //search backward for the quotes. the found time should be >= lastTime
            int indexStartSearch = -1;

            for (int i = q.Count - 1; i >= 0; i--)
            {
                if (q.Time[i] < this.LastTime)               //for basic quote we include price at previous interval for calculation
                {
                    break;
                }

                indexStartSearch = i;
            }
            if (indexStartSearch == -1)
            {
                return(0);
            }

            ////////////////////////////////////////////////////////////////////////////
            var isDataChanged   = false;
            var numAddedElement = 0;

            int sindex  = indexStartSearch;                                               // interval区间的开始索引
            var eindex  = -1;
            var endTime = q.Time[sindex] / this.Interval * this.Interval + this.Interval; //use the first time as the data bar time

            for (int i = indexStartSearch; i <= q.Count - 1; i++)
            {
                if (q.Time[i] >= endTime)
                {
                    eindex = i - 1;        // interval区间的结束索引
                    var num = this.AddItemByQuoteCapture(q, sindex, eindex);
                    if (num >= 0)
                    {
                        numAddedElement += num;
                        isDataChanged    = true;
                    }
                    sindex  = i;
                    endTime = q.Time[sindex] / this.Interval * this.Interval + this.Interval;
                }
            }

            //add last element
            if (sindex > eindex)
            {
                var num = this.AddItemByQuoteCapture(q, sindex, q.Count - 1);
                if (num >= 0)
                {
                    numAddedElement += num;
                    isDataChanged    = true;
                }
            }

            if (isTriggerDataUpdated && isDataChanged)
            {
                OnDataAddedOrUpdated?.Invoke(this, this, numAddedElement);
            }

            return(isDataChanged ? numAddedElement : -1);  //-1 means nothing changed, 0 means updated, >=1 means added
        }