示例#1
0
        /// <summary>
        /// Group items by time
        /// </summary>
        /// <param name="nextPoint"></param>
        /// <param name="previousPoint"></param>
        /// <param name="span"></param>
        /// <returns></returns>
        protected T CreateGroup(T nextPoint, T previousPoint, TimeSpan?span)
        {
            if (nextPoint.Ask == null && nextPoint.Bid == null)
            {
                return(nextPoint);
            }

            var nextGroup = nextPoint.Clone() as IPointModel;

            nextGroup.AskSize ??= nextPoint.AskSize ?? 0.0;
            nextGroup.BidSize ??= nextPoint.BidSize ?? 0.0;

            nextGroup.Ask ??= nextPoint.Ask ?? nextPoint.Bid;
            nextGroup.Bid ??= nextPoint.Bid ?? nextPoint.Ask;

            nextGroup.Bar.Open ??= previousPoint?.Last ?? nextGroup.Ask;
            nextGroup.Bar.Close ??= previousPoint?.Last ?? nextGroup.Bid;
            nextGroup.Last ??= nextGroup.Bar.Close;

            nextGroup.TimeFrame = span;
            nextGroup.Time      = ConversionManager.Cut(nextPoint.Time, span);
            nextGroup.Bar.Low ??= Math.Min(nextGroup.Bid.Value, nextGroup.Ask.Value);
            nextGroup.Bar.High ??= Math.Max(nextGroup.Ask.Value, nextGroup.Bid.Value);

            return((T)nextGroup);
        }
示例#2
0
        /// <summary>
        /// Update or add item to the collection depending on its date and time
        /// </summary>
        public virtual void Add(T item, TimeSpan?span)
        {
            var currentTime   = ConversionManager.Cut(item.Time, span);
            var previousTime  = ConversionManager.Cut(item.Time - span.Value, span);
            var currentGroup  = _dateIndexes.TryGetValue(currentTime.Value.Ticks, out int currentIndex) ? this[currentIndex] : default;
            var previousGroup = _dateIndexes.TryGetValue(previousTime.Value.Ticks, out int previousIndex) ? this[previousIndex] : default;

            if (currentGroup != null)
            {
                this[currentIndex] = UpdateGroup(item, currentGroup);
                return;
            }

            base.Add(CreateGroup(item, previousGroup, span));

            _dateIndexes[currentTime.Value.Ticks] = Count - 1;
        }
示例#3
0
        /// <summary>
        /// Update or add item to the collection depending on its date and time
        /// </summary>
        public virtual void Add(T item, TimeSpan span)
        {
            var previous = this.LastOrDefault();

            if (previous != null)
            {
                var nextTime     = ConversionManager.Cut(item.Time, span);
                var previousTime = ConversionManager.Cut(previous.Time, span);

                if (Equals(previousTime, nextTime))
                {
                    this[Count - 1] = item;
                    return;
                }
            }

            base.Add(item);
        }