Example #1
0
        private void GetTickSteps(List <IStep> steps, List <CodeInfo> codes, UpdatedDataInfo updatedDataInfo)
        {
            for (int i = 0; i < codes.Count; i++)
            {
                CodeInfo   codeInfo = codes[i];
                string     code     = codeInfo.Code;
                List <int> notUpdatedTradingDays;

                ITradingDayReader tradingDayReader = dataUpdateHelper.GetAllTradingDayReader();
                int lastUpdatedTickDate            = updatedDataInfo.GetLastUpdatedTickData(code);
                if (!updateFillUp && lastUpdatedTickDate >= 0)
                {
                    int endDate;
                    if (codeInfo.End <= 0)
                    {
                        endDate = tradingDayReader.LastTradingDay;
                    }
                    else if (codeInfo.End < tradingDayReader.LastTradingDay)
                    {
                        endDate = codeInfo.End;
                    }
                    else
                    {
                        endDate = tradingDayReader.LastTradingDay;
                    }

                    if (lastUpdatedTickDate >= endDate)
                    {
                        continue;
                    }
                    int startDate = tradingDayReader.GetNextTradingDay(lastUpdatedTickDate);
                    if (startDate < 0)
                    {
                        continue;
                    }
                    IList <int> days = tradingDayReader.GetTradingDays(startDate, endDate);
                    if (days.Count == 0)
                    {
                        continue;
                    }
                    notUpdatedTradingDays = new List <int>(days);
                }
                else
                {
                    notUpdatedTradingDays = dataUpdateHelper.GetNotUpdateTradingDays_TickData(code, updateFillUp);
                    if (notUpdatedTradingDays == null || notUpdatedTradingDays.Count == 0)
                    {
                        //updatedDataInfo.WriteUpdateInfo_Tick(code, tradingDayReader.LastTradingDay);
                        continue;
                    }

                    int startDate      = notUpdatedTradingDays[0];
                    int lastUpdateDate = tradingDayReader.GetPrevTradingDay(startDate);
                    //updatedDataInfo.WriteUpdateInfo_Tick(code, lastUpdateDate);
                }
                GetTickSteps(steps, codeInfo, notUpdatedTradingDays, updatedDataInfo);
            }
        }
Example #2
0
        /// <summary>
        /// 得到一天内K线的每一根柱子的时间
        /// </summary>
        /// <param name="openDateReader"></param>
        /// <param name="openTimes"></param>
        /// <param name="targetPeriod"></param>
        /// <returns></returns>
        public static List <double> GetKLineTimeList(int date, ITradingDayReader openDateReader, List <double[]> openTimes, KLinePeriod targetPeriod)
        {
            if (!openDateReader.IsTrade(date))
            {
                throw new ArgumentException(date + "不开盘");
            }

            int lastOpenDate = openDateReader.GetPrevTradingDay(date);

            return(GetKLineTimeList(date, lastOpenDate, openTimes, targetPeriod));
        }
Example #3
0
        /// <summary>
        /// 默认获取如下数据:
        /// 日线:获取500日
        /// 1小时:获取4月
        /// 15分钟:获取30日
        /// 5分钟:获取10日
        /// 1分钟:获取3日
        /// </summary>
        /// <param name="dataReaderFactory"></param>
        /// <param name="lastDate"></param>
        /// <param name="period"></param>
        /// <returns></returns>
        private int GetFirstDate(IDataReader dataReaderFactory, int lastDate, KLinePeriod period)
        {
            ITradingDayReader openDateReader = dataReaderFactory.TradingDayReader;

            //if (period.CompareTo(KLinePeriod.KLinePeriod_1Week) >= 0)
            //    return openDateReader.GetPrevOpenDate(lastDate, 500);
            if (period.CompareTo(KLinePeriod.KLinePeriod_1Day) >= 0)
            {
                return(openDateReader.GetPrevTradingDay(lastDate, 500 - 1));
            }
            if (period.CompareTo(KLinePeriod.KLinePeriod_1Hour) >= 0)
            {
                return(openDateReader.GetPrevTradingDay(lastDate, 150 - 1));
            }
            if (period.CompareTo(KLinePeriod.KLinePeriod_15Minute) >= 0)
            {
                return(openDateReader.GetPrevTradingDay(lastDate, 40 - 1));
            }
            if (period.CompareTo(KLinePeriod.KLinePeriod_5Minute) >= 0)
            {
                return(openDateReader.GetPrevTradingDay(lastDate, 10 - 1));
            }
            if (period.CompareTo(KLinePeriod.KLinePeriod_1Minute) >= 0)
            {
                return(openDateReader.GetPrevTradingDay(lastDate, 3 - 1));
            }
            return(openDateReader.GetPrevTradingDay(lastDate, 1 - 1));;
        }
Example #4
0
        private int GetLastTradingDayIndex(CodeInfo codeInfo, ITradingDayReader openDateReader)
        {
            int codeLastDate = codeInfo.End;

            if (codeLastDate <= 0)
            {
                return(openDateReader.GetAllTradingDays().Count - 1);
            }
            int lastTradingDay = openDateReader.LastTradingDay;

            lastTradingDay = codeLastDate > lastTradingDay ? lastTradingDay : codeLastDate;

            int index = openDateReader.GetTradingDayIndex(lastTradingDay);

            if (index >= 0)
            {
                return(index);
            }
            int date = openDateReader.GetPrevTradingDay(lastTradingDay);

            return(openDateReader.GetTradingDayIndex(date));
        }
Example #5
0
        private void GetKLineDataSteps(List <IStep> steps, UpdatedDataInfo updatedDataInfo, List <CodeInfo> allCodes)
        {
            List <CodeInfo> codes = allCodes;

            for (int i = 0; i < codes.Count; i++)
            {
                CodeInfo codeInfo = codes[i];
                string   code     = codeInfo.Code;
                //List<int> notUpdatedTradingDays = new List<int>();
                //notUpdatedTradingDays.AddRange(this.dataUpdateHelper.GetAllHolidays());
                //notUpdatedTradingDays.Remove(20171009);
                //Delete(code, notUpdatedTradingDays);
                List <int>        notUpdatedTradingDays;
                ITradingDayReader tradingDayReader = dataUpdateHelper.GetAllTradingDayReader();
                int lastUpdatedKLineDate           = updatedDataInfo.GetLastUpdatedKLineData(code, KLinePeriod.KLinePeriod_1Minute);
                if (!updateFillUp && lastUpdatedKLineDate >= 0)
                {
                    int endDate;
                    if (codeInfo.End <= 0)
                    {
                        endDate = tradingDayReader.LastTradingDay;
                    }
                    else if (codeInfo.End < tradingDayReader.LastTradingDay)
                    {
                        endDate = codeInfo.End;
                    }
                    else
                    {
                        endDate = tradingDayReader.LastTradingDay;
                    }

                    if (lastUpdatedKLineDate >= endDate)
                    {
                        continue;
                    }
                    int startDate = tradingDayReader.GetNextTradingDay(lastUpdatedKLineDate);
                    if (startDate < 0)
                    {
                        continue;
                    }
                    IList <int> days = tradingDayReader.GetTradingDays(startDate, endDate);
                    if (days.Count == 0)
                    {
                        continue;
                    }
                    notUpdatedTradingDays = new List <int>(days);
                }
                else
                {
                    notUpdatedTradingDays = dataUpdateHelper.GetNotUpdateTradingDays_KLineData(code, updateFillUp);
                    if (notUpdatedTradingDays == null || notUpdatedTradingDays.Count == 0)
                    {
                        updatedDataInfo.WriteUpdateInfo_KLine(code, KLinePeriod.KLinePeriod_1Minute, tradingDayReader.LastTradingDay);
                        continue;
                    }
                    int startDate      = notUpdatedTradingDays[0];
                    int lastUpdateDate = tradingDayReader.GetPrevTradingDay(startDate);
                    updatedDataInfo.WriteUpdateInfo_KLine(code, KLinePeriod.KLinePeriod_1Minute, lastUpdateDate);
                }
                GetKLineDataSteps(steps, codeInfo, notUpdatedTradingDays, updatedDataInfo);
            }
        }