Esempio n. 1
0
        public string Proceed()
        {
            IList <MainContractInfo> mainContracts = this.dataUpdateHelper.GetMainContractInfos();
            List <MainContractInfo>  contracts     = new List <MainContractInfo>();
            CacheUtils_MainContract  cache         = new CacheUtils_MainContract(mainContracts);
            ITradingDayReader        reader        = this.dataUpdateHelper.GetAllTradingDayReader();

            string[] varieties = this.dataUpdateHelper.GetAllVarieties();
            for (int i = 0; i < varieties.Length; i++)
            {
                string variety = varieties[i];
                Proceed(variety, cache, contracts, reader);
            }
            contracts.Sort();

            string path = dataUpdateHelper.GetPath_MainFutures();

            string[] contents = new string[contracts.Count];
            for (int i = 0; i < contracts.Count; i++)
            {
                contents[i] = contracts[i].ToString();
            }
            File.WriteAllLines(path, contents);
            return("");
        }
Esempio n. 2
0
        public IKLineData GetKLineData(string code, int startDate, int endDate, KLinePeriod period)
        {
            ITradingDayReader openDateReader = dataReaderFactory.OpenDateReader;

            IList <int>       openDates     = openDateReader.GetOpenDates(startDate, endDate);
            int               prevOpenDate  = openDateReader.GetPrevOpenDate(startDate);
            IKLineData        lastKLineData = dataReaderFactory.KLineDataReader.GetData(code, prevOpenDate, prevOpenDate, period);
            List <IKLineData> klineDataList = new List <IKLineData>();

            for (int i = 0; i < openDates.Count; i++)
            {
                int      openDate = openDates[i];
                TickData tickdata = dataReaderFactory.TickDataReader.GetTickData(code, openDate);
                if (tickdata != null)
                {
                    List <double[]>   openTimes = dataProvider.GetOpenTime(code, openDate);
                    OpenTimeUtilsArgs args      = new OpenTimeUtilsArgs(openDate, openDateReader, openTimes, period);
                    KLineData         klineData = DataTransfer_Tick2KLine2.Transfer(tickdata, lastKLineData, args);
                    klineDataList.Add(klineData);
                }
            }
            if (klineDataList.Count == 0)
            {
                return(null);
            }
            return(KLineData.Merge(klineDataList));
        }
Esempio n. 3
0
 public NewDataInfoGetter(IUpdatedDataInfo historyDataInfoLoader, ITradingDayReader tradingDayReader, DataUpdateHelper dataLoader)
 {
     //this.historyDataInfoLoader = new HistoryDataInfoLoader(srcDataPath);
     this.historyDataInfoLoader = historyDataInfoLoader;
     this.tradingDayReader      = tradingDayReader;
     this.dataLoader            = dataLoader;
 }
Esempio n. 4
0
        private List <IStep> GetAllStep_Varieties()
        {
            List <IStep>    steps         = new List <IStep>();
            Step_CodeInfo   step_CodeInfo = new Step_CodeInfo(dataUpdateHelper);
            List <CodeInfo> allCodes      = step_CodeInfo.GetAllCodes();

            allCodes = FilterCodeInfo(allCodes, new string[] { "RB", "HC", "BU" });
            GetTradingTime(steps, allCodes, true);
            UpdatedDataInfo updatedDataInfo = new UpdatedDataInfo(targetDataPath);

            ITradingDayReader tradingDayReader = dataUpdateHelper.GetAllTradingDayReader();

            for (int i = 0; i < allCodes.Count; i++)
            {
                CodeInfo codeInfo  = allCodes[i];
                int      startDate = codeInfo.Start;
                if (startDate == 0)
                {
                    startDate = tradingDayReader.FirstTradingDay;
                }

                int endDate = codeInfo.End;
                if (endDate <= 0)
                {
                    endDate = tradingDayReader.LastTradingDay;
                }
                List <int> tradingDays = new List <int>();
                tradingDays.AddRange(tradingDayReader.GetTradingDays(startDate, endDate));
                GetKLineDataSteps(steps, codeInfo, tradingDays, updatedDataInfo);
            }
            return(steps);
        }
Esempio n. 5
0
        //private List<CodeInfo> newcodes;

        public DataUpdateUtils2(string dataPath, ITradingDayReader tradingDayReader, IUpdatedDataInfo openDateReader_HistoryData, DataUpdateHelper dataLoader)
        {
            // this.dataLoader_InstrumentInfo = dataLoader_InstrumentInfo;
            this.codes            = dataLoader.GetNewCodes(); //dataLoader_InstrumentInfo.GetAllInstruments();
            this.openDates        = tradingDayReader.GetAllTradingDays();
            this.updateDateGetter = new NewDataInfoGetter(openDateReader_HistoryData, tradingDayReader, dataLoader, this.codes);
        }
Esempio n. 6
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));;
        }
Esempio n. 7
0
        public List <TradingSession> LoadTradingSessions(string code)
        {
            List <TradingSession> dayStartTimes = this.LoadUpdatedTradingSessions(code);

            ITradingDayReader openDateReader = this.LoadTradingDayReader();
            int firstIndex = 0;

            if (dayStartTimes != null && dayStartTimes.Count != 0)
            {
                int lastDate = dayStartTimes[dayStartTimes.Count - 1].TradingDay;
                if (lastDate == openDateReader.LastTradingDay)
                {
                    return(null);
                }
                int lastIndex = openDateReader.GetTradingDayIndex(lastDate);
                firstIndex = lastIndex + 1;
            }
            List <int>            openDates        = openDateReader.GetAllTradingDays();
            List <TradingSession> updateStartTimes = CalcDayOpenTime(code, openDates, firstIndex, openDates.Count - 1);

            List <TradingSession> result = new List <TradingSession>();

            if (dayStartTimes != null)
            {
                result.AddRange(dayStartTimes);
            }
            result.AddRange(updateStartTimes);
            return(result);
        }
Esempio n. 8
0
 public ITradingDayReader GetTradingDayReader()
 {
     if (tradingDayReader == null)
     {
         tradingDayReader = new CacheUtils_TradingDay(allTradingDays);
     }
     return(tradingDayReader);
 }
Esempio n. 9
0
 public ITradingDayReader GetNewTradingDayCache()
 {
     if (newTradingDayReader == null)
     {
         newTradingDayReader = new CacheUtils_TradingDay(GetNewTradingDays());
     }
     return(newTradingDayReader);
 }
Esempio n. 10
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);
            }
        }
Esempio n. 11
0
        //public Step_UpdateKLineData(string code, int startDate, int endDate, KLinePeriod period, IPlugin_HistoryData historyData, IKLineDataStore klineDataStore)
        //{
        //    this.code = code;

        //    this.period = period;
        //    this.historyData = historyData;
        //    this.klineDataStore = klineDataStore;
        //}

        public Step_UpdateKLineData(CodeInfo codeInfo, KLinePeriod period, ITradingDayReader tradingDayReader, IPlugin_HistoryData historyData, IKLineDataStore klineDataStore, UpdatedDataInfo updatedDataInfo, IUpdateInfoStore updateInfoStore, bool updateFillUp)
        {
            this.codeInfo         = codeInfo;
            this.tradingDayReader = tradingDayReader;
            this.period           = period;
            this.historyData      = historyData;
            this.klineDataStore   = klineDataStore;
            this.updatedDataInfo  = updatedDataInfo;
            this.updateInfoStore  = updateInfoStore;
            this.updateFillUp     = updateFillUp;
        }
Esempio n. 12
0
        private void initTradingDays()
        {
            if (this.tradingDays != null)
            {
                return;
            }
            String path = srcDataPath + "\\DL";

            this.tradingDays    = GetTradingDays(path);
            this.openDateReader = new CacheUtils_TradingDay(tradingDays);
        }
Esempio n. 13
0
 public DataReader(string dataCenterUri)
 {
     this.dataStore           = DataStoreFactory.CreateDataStore(dataCenterUri);
     this.codeReader          = new CodeReader(dataStore.CreateInstrumentStore());
     this.tradingDayReader    = new CacheUtils_TradingDay(dataStore.CreateTradingDayStore().Load());
     this.tradingSessionStore = dataStore.CreateTradingSessionStore();
     this.tradingTimeStore    = dataStore.CreateTradingTimeStore();
     this.tickDataReader      = new TickDataReader(dataStore, this);
     this.klineDataReader     = new KLineDataReader(dataStore, this);
     this.timeLineDataReader  = new TimeLineDataReader(this);
     this.mainContractReader  = new MainContractReader(dataStore);
 }
Esempio n. 14
0
        private int GetLastUpdatedIndex(List <TradingSession> dayStartTimes)
        {
            if (dayStartTimes == null || dayStartTimes.Count == 0)
            {
                return(-1);
            }
            int lastDate = dayStartTimes[dayStartTimes.Count - 1].TradingDay;
            ITradingDayReader openDateReader = this.LoadTradingDayReader();
            int lastIndex = openDateReader.GetTradingDayIndex(lastDate);

            return(lastIndex);
        }
Esempio n. 15
0
 public NewDataInfoGetter(IUpdatedDataInfo historyDataInfoLoader, ITradingDayReader tradingDayReader, DataUpdateHelper dataLoader, List <CodeInfo> newcodes) : this(historyDataInfoLoader, tradingDayReader, dataLoader)
 {
     this.newcodes        = newcodes;
     this.dic_Id_CodeInfo = new Dictionary <string, CodeInfo>();
     for (int i = 0; i < newcodes.Count; i++)
     {
         string code = newcodes[i].ServerCode;
         if (this.dic_Id_CodeInfo.ContainsKey(code))
         {
             this.dic_Id_CodeInfo.Remove(code);
         }
         this.dic_Id_CodeInfo.Add(code, newcodes[i]);
     }
 }
Esempio n. 16
0
 public DataReaderFactory2(String dataPath)
 {
     this.dataPath  = dataPath;
     this.pathUtils = new DataPathUtils(dataPath);
     //this.codeReader = new InstrumentReader(PathUtils.GetCodePath());
     this.openDateReader  = new TradingDayReader(PathUtils.GetTradingDayPath());
     this.openTimeReader  = new TradingSessionReader_Code(dataPath);
     this.tickDataReader  = new HistoryDataReader_Tick(dataPath);
     this.klineDataReader = new KLineDataReader(dataPath);
     this.realDataReader  = new TimeLineDataReader(this);
     //this.dataNavigate = new DataNavigate3(this);
     //this.cacheFactory = new DataCacheFactory(this);
     //this.dataNavigateMgr = new DataNavigateMgr(this);
     this.openDateReaderMgr = new TradingSessionReader_CodeMgr(this);
 }
Esempio n. 17
0
        public List <TradingSession> LoadTradingSessions(string code)
        {
            List <TradingSession> dayStartTimes = this.LoadUpdatedTradingSessions(code);

            CodeInfo          codeInfo       = this.dataLoader_Instrument.GetInstrument(code);
            ITradingDayReader openDateReader = this.LoadTradingDayReader();
            int firstCodeTradingDayIndex;
            int lastCodeTradingDayIndex;
            int lastUpdateTradingDayIndex = GetLastUpdatedIndex(dayStartTimes);

            if (lastUpdateTradingDayIndex < 0)
            {
                firstCodeTradingDayIndex = GetFirstTradingDayIndex(codeInfo, openDateReader);
                lastCodeTradingDayIndex  = GetLastTradingDayIndex(codeInfo, openDateReader);
            }
            else
            {
                lastCodeTradingDayIndex = lastUpdateTradingDayIndex + 1;
                if (lastCodeTradingDayIndex >= openDateReader.GetAllTradingDays().Count)
                {
                    return(null);
                }
                firstCodeTradingDayIndex = GetFirstTradingDayIndex(codeInfo, openDateReader);
            }
            if (firstCodeTradingDayIndex < 0)
            {
                return(null);
            }

            List <int>            openDates        = openDateReader.GetAllTradingDays();
            List <TradingSession> updateStartTimes = CalcDayOpenTime(code, openDates, firstCodeTradingDayIndex, lastCodeTradingDayIndex);

            List <TradingSession> result = new List <TradingSession>();

            if (dayStartTimes != null)
            {
                result.AddRange(dayStartTimes);
            }
            result.AddRange(updateStartTimes);
            return(result);
        }
Esempio n. 18
0
        private void initTradingDays()
        {
            if (this.tradingDays != null)
            {
                return;
            }

            DirectoryInfo srcPathDir = new DirectoryInfo(srcDataPath);

            DirectoryInfo[] dirs = srcPathDir.GetDirectories();
            this.tradingDays = new List <int>();
            for (int i = 0; i < dirs.Length; i++)
            {
                DirectoryInfo dir   = dirs[i];
                int           month = int.Parse(dir.Name);
                GetTradingDays(month, tradingDays);
            }

            //String path = srcDataPath + "\\DL";
            //this.tradingDays = GetTradingDays(path);
            this.openDateReader = new CacheUtils_TradingDay(tradingDays);
        }