Example #1
0
        public CandleStickData UpdateCandleStickData(CandleStickData newData)
        {
            DateTime dt  = newData.Time;
            int      end = Math.Max(0, CandleStickData.Count - 30);

            for (int i = CandleStickData.Count - 1; i >= end; i--)
            {
                CandleStickData data = CandleStickData[i];
                if (dt > data.Time)
                {
                    break;
                }
                if (dt == data.Time)
                {
                    CandleStickData[i] = newData;
                    return(newData);
                }
                if (dt < data.Time)
                {
                    CandleStickData.Insert(i, newData);
                    return(newData);
                }
            }
            CandleStickData.Add(newData);
            return(newData);
        }
        public CandleStickData GetOrCreateCandleStickData(DateTime dt)
        {
            int end = Math.Max(0, CandleStickData.Count - 30);

            for (int i = CandleStickData.Count - 1; i >= end; i--)
            {
                CandleStickData data = CandleStickData[i];
                if (dt > data.Time)
                {
                    break;
                }
                if (dt == data.Time)
                {
                    return(data);
                }
                if (dt < data.Time)
                {
                    CandleStickData d = new CandleStickData();
                    d.Time = dt;
                    CandleStickData.Insert(i, d);
                    return(d);
                }
            }
            CandleStickData dd = new CandleStickData();

            dd.Time = dt;
            CandleStickData.Add(dd);
            return(dd);
        }