Esempio n. 1
0
        ///// <summary>
        ///// 技术指标RSI
        ///// </summary>
        //public static void CalculateRSI()
        //{
        //    //取得所有a股安全码
        //    List<ulong> lstSecurityID = MongoDBHelper.AsQueryable<SymbolInfo>().Select(m => m.SecurityID).ToList();

        //    //默认参数14
        //    int param = 14;
        //    int dataCount = param;

        //    MongoDBHelper.DeleteMany<RSIHistory>("{}");
        //    MongoDBHelper.DeleteMany<RSIResult>("{}");

        //    foreach (ulong securityID in lstSecurityID)
        //    {
        //        var lstRaw = (from m in MongoDBHelper.AsQueryable<DataByTime>()
        //                      where m.SecurityID == securityID && m.ChangeRatio.HasValue
        //                      orderby m.TradingDate descending
        //                      select new RSIHistory()
        //                      {
        //                          SecurityID = m.SecurityID,
        //                          TradingDate = m.TradingDate,
        //                          Symbol = m.Symbol,
        //                          ChangeRatio = m.ChangeRatio.Value
        //                      }).OrderBy(m => m.TradingDate).ToList();

        //        CalcRSI.CalcOneStock(lstRaw, param);

        //        if (lstRaw.Count > 0)
        //        {
        //            MongoDBHelper.InsertMany<RSIHistory>(lstRaw);
        //            var lstResult = CalcRSI.History2Result(lstRaw);
        //            MongoDBHelper.InsertMany<RSIResult>(lstResult);
        //        }
        //    }

        //    //if (lstAll.Count > 0)
        //    //{
        //    //    MongoDBHelper.DeleteMany<RSIHistory>("{}");
        //    //    MongoDBHelper.InsertMany<RSIHistory>(lstAll);

        //    //    //var lstResult = CalcRSI.GetLastResult(lstAll);
        //    //    //MongoDBHelper.DeleteMany<RSIResult>("{}");
        //    //    //MongoDBHelper.InsertMany<RSIResult>(lstResult);
        //    //}
        //}

        /// <summary>
        /// 技术指标RSI
        /// </summary>
        public static void CalculateRSI()
        {
            // 获取所有a股代码数据
            var securityIDs = DSPHelper.GetA_PlateSymbols().Select(x => x.SecurityID);
            //默认参数14
            int param     = 14;
            int dataCount = Math.Max(param, 12) + 2;

            List <RSIResult> lstAll = new List <RSIResult>();

            foreach (ulong securityID in securityIDs)
            {
                var lstRaw = (from m in MongoDBHelper.AsQueryable <DataByTime>()
                              where m.SecurityID == securityID && m.ChangeRatio.HasValue
                              orderby m.TradingDate descending
                              select new RSIResult()
                {
                    SecurityID = m.SecurityID,
                    TradingDate = m.TradingDate,
                    Symbol = m.Symbol,
                    ChangeRatio = m.ChangeRatio.Value
                }).Take(dataCount).OrderBy(m => m.TradingDate).ToList();

                CalcRSI.CalcOneStock(lstRaw, param);
                lstAll.AddRange(lstRaw);
            }

            if (lstAll.Count > 0)
            {
                var lstResult = CalcRSI.GetLastResult(lstAll);
                MongoDBHelper.DeleteMany <RSIResult>("{}");
                MongoDBHelper.InsertMany <RSIResult>(lstResult);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 同步所有a股代码
        /// </summary>
        public static void SyncA_PlateIndex()
        {
            // 记日志
            LogHelper.Info("总运行", "开始:同步a股代码");

            try
            {
                // 获取所有a股代码数据
                var symbols = DSPHelper.GetA_PlateSymbols();
                // 获取数据正常
                if (symbols.Count() > 0)
                {
                    MongoDBHelper.DeleteMany <SymbolInfo>("{}");
                    MongoDBHelper.InsertMany <SymbolInfo>(symbols);
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("异常", "同步所有a股代码异常!", ex);
            }
            finally
            {
                LogHelper.Info("总运行", "结束:同步a股代码");
            }
        }