Ejemplo n.º 1
0
        /// <summary>
        ///   將設定檔轉換為 InstrumentDataRequest 列表的格式
        /// </summary>
        /// <param name="requests">RequestSetting 陣列</param>
        /// <returns>返回值: InstrumentDataRequest 列表</returns>
        public static List <InstrumentDataRequest> Convert(List <RequestSetting> requests)
        {
            List <InstrumentDataRequest> cResult = new List <InstrumentDataRequest>();

            foreach (RequestSetting cRequest in requests)
            {
                string[]    sPeriods    = cRequest.DataPeriod.Split(',');
                int         iPeriodSize = int.Parse(sPeriods[0]);
                EResolution cResolution = (EResolution)Enum.Parse(typeof(EResolution), sPeriods[1]);

                InstrumentDataRequest cDataRequest = new InstrumentDataRequest()
                {
                    Exchange   = cRequest.Exchange,
                    DataFeed   = cRequest.DataFeed,
                    Resolution = new Resolution(cResolution, iPeriodSize),
                    Symbol     = cRequest.SymbolId
                };

                string[] sParams  = cRequest.Range.Split(',');
                string   sMode    = sParams[0];
                string[] sArgs    = sParams[1].Split(';');
                DateTime cEndDate = DateTime.Parse(sArgs[0]);
                if (cEndDate == MAX_REQUEST_LASTDATE)
                {
                    cEndDate = DateTime.Today;
                }

                switch (sMode)
                {
                case "barsBack":
                    cDataRequest.Range = DataRequest.CreateBarsBack(cEndDate, int.Parse(sArgs[1]));
                    break;

                case "daysBack":
                    cDataRequest.Range = DataRequest.CreateDaysBack(cEndDate, int.Parse(sArgs[1]));
                    break;

                case "fromTo":
                    cDataRequest.Range = DataRequest.CreateFromTo(DateTime.Parse(sArgs[1]), cEndDate);
                    break;
                }
                cResult.Add(cDataRequest);
            }
            return(cResult);
        }