Exemple #1
0
        /// <summary>
        /// Validate if the time series is valid (i.e. is there any overlapping between ticks?)
        /// </summary>
        /// <param name="errorTick">Tick that is overlapped by another</param>
        /// <returns>Returns if the time series is valid</returns>
        private bool IsTimeSeriesValid(out TTick errorTick)
        {
            var periodInstance = Period.CreateInstance();

            errorTick = default(TTick);

            for (int i = 0; i < Ticks.Count() - 1; i++)
            {
                var candleEndTime = periodInstance.NextTimestamp(Ticks.ElementAt(i).DateTime);
                if (candleEndTime > Ticks.ElementAt(i + 1).DateTime)
                {
                    errorTick = Ticks.ElementAt(i);
                    return(false);
                }
            }
            return(true);
        }
Exemple #2
0
        public void Add(TTick item)
        {
            var periodInstance = Period.CreateInstance();

            if (Ticks.Any())
            {
                var tickEndTime = periodInstance.NextTimestamp(Ticks.Last().DateTime);
                if (item.DateTime < tickEndTime)
                {
                    throw new InvalidTimeFrameException(item.DateTime);
                }

                if (_maxTickCount.HasValue && Ticks.Count >= _maxTickCount.Value)
                {
                    Ticks = Ticks.Skip(Ticks.Count - _maxTickCount.Value + 1).Take(_maxTickCount.Value).ToList();
                }
            }
            Ticks.Add(item);
        }