Beispiel #1
0
 /// <summary>
 /// 计算股票指标
 /// </summary>
 /// <param name="date">计算指标的日期,为空计算当前日期</param>
 /// <param name="stockCode">计算指标的股票,为空计算所有股票</param>
 public void ComputeStockIndex(string date = "", string stockCode = "")
 {
     try
     {
         List <StockMatchedIndex> smiLst = new List <StockMatchedIndex>();
         DateTime qDate = string.IsNullOrEmpty(date) ? DateTime.Now : Convert.ToDateTime(date);
         if (oh.IsWorkingDay(qDate))
         {
             if (string.IsNullOrEmpty(stockCode))
             {
                 var stockList = proc.getStockList(" and len(StockCode)=6");
                 foreach (DataRow dr in stockList.Rows)
                 {
                     string code = dr["StockCode"].ToString();
                     var    rs   = GetStockIndex(qDate.AddMonths(-4).ToString(("yyyy-MM-dd")), qDate.ToString("yyyy-MM-dd"), code);
                     smiLst.AddRange(rs);
                 }
             }
             else
             {
                 var rs = GetStockIndex(qDate.AddMonths(-4).ToString(("yyyy-MM-dd")), qDate.ToString("yyyy-MM-dd"), stockCode);
                 smiLst.AddRange(rs);
             }
             DataTable dt = Utility.XHelper.FillDataTableByEntity(smiLst);
             var       t1 = DateTime.Now;
             var       i  = proc.insertUpdateStockMatchedIndex(dt);
             var       t  = (DateTime.Now - t1).Seconds;
             Console.WriteLine(string.Format("时间:{0}计算股票匹配指标成功。日期:{1}", DateTime.Now.ToString(), date));
         }
     }
     catch (Exception ex)
     {
         LogHelper.WriteLog("计算股票指标出错", ex);
     }
 }