Example #1
0
        /// <summary>
        /// 重试同步行情指标信息
        /// </summary>
        public static void RetrySyncDataByTime(DspRequest dspRequest, int retryTime)
        {
            List <ReqDataByTime> lstRetryReq = new List <ReqDataByTime>();

            lstRetryReq.AddRange(LstRetryReqDataByTime);
            LstRetryReqDataByTime.Clear();

            if (retryTime > DSPHelper.RetryTime)
            {
                foreach (ReqDataByTime req in lstRetryReq)
                {
                    string exMsg = string.Format("同步行情指标异常. 重试{0}次仍未取到值. SecurityID:{1}.", DSPHelper.RetryTime, req.securityIDs[0]);
                    LogHelper.Error("异常", exMsg);
                }
                return;
            }

            DSPHelper.ReConnect();

            foreach (ReqDataByTime req in lstRetryReq)
            {
                string msg = string.Format("SecurityID:{0}.第{1}次重试!", req.securityIDs[0], retryTime);
                LogHelper.Track("所有日线行情", msg);
                dspRequest.AsyncSendData(req, DSPHelper.WaitTime, req);
            }

            //等待DSP任务完成
            dspRequest.WaitFinished();
            if (LstRetryReqDataByTime.Count > 0)
            {
                //重试
                RetrySyncDataByTime(dspRequest, ++retryTime);
            }
        }
Example #2
0
        /// <summary>
        /// 同步财务指标信息
        /// </summary>
        public static void SyncFinaceIndex()
        {
            // 记日志
            LogHelper.Info("总运行", "开始:同步财务指标数据");

            DspRequest dspRequest = new DspRequest();

            dspRequest.DealData = SaveFinaceIndex;
            LstRetryReqFinance  = new List <ReqFinance>();

            try
            {
                //取得所有a股安全码
                List <ulong> lstSecurityID = MongoDBHelper.AsQueryable <SymbolInfo>().Select(m => m.SecurityID).ToList();
                //取得所有财务指标编码
                List <string> lstIndexCode = GetAllFinaceIndexCode();

                ////删除已过期的数据
                //DeleteOverdueFinaceIndex(lstSecurityID[0]);

                // 根据代码同步所有财务指标数据
                foreach (var securityID in lstSecurityID)
                {
                    try
                    {
                        FinanceIndexInfo info = MongoDBHelper.AsQueryable <FinanceIndexInfo>()
                                                .Where(m => m.SecurityID == securityID)
                                                .OrderByDescending(m => m.EndDate)
                                                .FirstOrDefault();
                        DateTime lastDate = new DateTime(1990, 1, 1);
                        if (info != null)
                        {
                            lastDate = info.EndDate;
                        }

                        ReqFinance req = DSPHelper.GetReqFinance(securityID, lstIndexCode, lastDate);
                        if (req != null)
                        {
                            dspRequest.AsyncSendData(req, DSPHelper.WaitTime, req);
                        }
                    }
                    catch (Exception ex)
                    {
                        string errMsg = "同步财务指标异常.SecurityID:" + securityID;
                        LogHelper.Error("异常", errMsg, ex);
                    }
                }

                //等待DSP任务完成
                dspRequest.WaitFinished();
                if (LstRetryReqFinance.Count > 0)
                {
                    //重试
                    RetrySyncFinaceIndex(dspRequest, 1);
                    //等待DSP任务完成
                    dspRequest.WaitFinished();
                }

                ////给10秒钟mongodb。
                //Thread.Sleep(10000);
            }
            catch (Exception ex)
            {
                LogHelper.Error("异常", "同步财务指标发生异常.", ex);
            }
            finally
            {
                dspRequest.Dispose();
                LogHelper.Info("总运行", "结束:同步财务指标数据");
            }
        }
Example #3
0
        /// <summary>
        /// 同步所有日线行情数据
        /// </summary>
        public static void SyncDataByTime()
        {
            // 记日志
            LogHelper.Info("总运行", "开始:同步所有日线行情");

            DspRequest dspRequest = new DspRequest();

            dspRequest.DealData   = SaveDataByTime;
            LstRetryReqDataByTime = new List <ReqDataByTime>();

            try
            {
                //取得所有a股安全码
                List <ulong> lstSecurityID = MongoDBHelper.AsQueryable <SymbolInfo>().Select(m => m.SecurityID).ToList();

                //根据代码同步所有日频行情数据
                foreach (var securityID in lstSecurityID)
                {
                    try
                    {
                        DataByTime info = MongoDBHelper.AsQueryable <DataByTime>()
                                          .Where(m => m.SecurityID == securityID)
                                          .OrderByDescending(m => m.TradingDate)
                                          .FirstOrDefault();

                        ReqDataByTime req = null;
                        if (info == null)
                        {
                            req = DSPHelper.GetReqDataByTimeAll(securityID);
                        }
                        else
                        {
                            DateTime beginDate = Convert.ToDateTime(info.TradingDate).AddDays(1);
                            if (beginDate >= DateTime.Today)
                            {
                                continue;
                            }
                            req = DSPHelper.GetReqDataByTimeLast(securityID, beginDate);
                        }

                        dspRequest.AsyncSendData(req, DSPHelper.WaitTime, req);
                    }
                    catch (Exception ex)
                    {
                        string errMsg = string.Format("同步所有日线行情发生异常.securityID:{0}", securityID);
                        LogHelper.Error("异常", errMsg, ex);
                    }
                }

                //等待DSP任务完成
                dspRequest.WaitFinished();
                if (LstRetryReqDataByTime.Count > 0)
                {
                    //重试
                    RetrySyncDataByTime(dspRequest, 1);
                    //等待DSP任务完成
                    dspRequest.WaitFinished();
                }

                ////给10秒钟mongodb。
                //Thread.Sleep(10000);
            }
            catch (Exception ex)
            {
                LogHelper.Error("异常", "同步所有日线行情发生异常.", ex);
            }
            finally
            {
                dspRequest.Dispose();
                LogHelper.Info("总运行", "结束:同步所有日线行情");
            }
        }