Example #1
0
        /// <summary>
        /// 同步前5个交易日的日线行情数据
        /// </summary>
        public static void SyncDataByTimeIndexInfo()
        {
            LogHelper.Info("总运行", "开始:同步前5个交易日的日线行情");

            //前5个交易日
            List <DateTime> lstTradeDate = MongodbCacheHelper.GetPreTradeDateDescending(5);
            TimePeriod      period       = new TimePeriod();

            period.begin = TransferHelper.DateTimeToString(lstTradeDate[4]);
            period.end   = TransferHelper.DateTimeToString(lstTradeDate[0]);
            try
            {
                var dataByTime = DSPHelper.GetDataByTimeIndexInfo(period);

                if (dataByTime.Count > 0)
                {
                    MongoDBHelper.DeleteMany <DataByTimeIndexInfo>("{}");
                    MongoDBHelper.InsertMany <DataByTimeIndexInfo>(dataByTime);
                }
            }
            catch (Exception ex)
            {
                string errMsg = string.Format("同步前5交易日行情发生异常.begin:{0}; end:{1}", period.begin, period.end);
                LogHelper.Error("异常", errMsg, ex);
            }
            finally
            {
                LogHelper.Info("总运行", "结束:同步前5个交易日的日线行情");
            }
        }
Example #2
0
        /// <summary>
        /// 行情指标信息转成指标股票信息
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static List <DataByTimeIndexInfo> Transfer2ListDataByTimeIndexInfo(object obj)
        {
            //这些字段名不是指标名
            List <string> lstNotIndexCode = new List <string>()
            {
                "SecurityID", "TradingDate", "Symbol", "ShortName", "Filling"
            };
            List <DataByTimeIndexInfo> lstInfo = new List <DataByTimeIndexInfo>();

            //前5个交易日
            List <DateTime> lstTradeDate = MongodbCacheHelper.GetPreTradeDateDescending(5);

            PropertyInfo[] properties = obj.GetType().GetProperties();
            foreach (PropertyInfo pro in properties)
            {
                if (pro.Name.EndsWith("Specified"))
                {
                    continue;
                }

                if (pro.PropertyType.IsGenericType)
                {
                    if (pro.PropertyType.GetGenericArguments()[0] == typeof(DataColumn))
                    {
                        List <DataColumn> lstCol = pro.GetValue(obj, null) as List <DataColumn>;
                        if (lstCol.Count == 0)
                        {
                            continue;
                        }

                        DataColumn colSecurityID  = null;   //安全码列
                        DataColumn colSymbol      = null;   //股票列
                        DataColumn colTradingDate = null;   //交易日列
                        DataColumn colFilling     = null;   //填充判断列 Filling=0:正常数据;其他:填充数据。

                        foreach (DataColumn col in lstCol)
                        {
                            if (col.name == "Symbol")
                            {
                                colSymbol = col;
                            }
                            else if (col.name == "SecurityID")
                            {
                                colSecurityID = col;
                            }
                            else if (col.name == "TradingDate")
                            {
                                colTradingDate = col;
                            }
                            else if (col.name == "Filling")
                            {
                                colFilling = col;
                            }
                        }

                        Dictionary <string, string[]> dicStr = GetStringValue(lstCol);
                        uint count = lstCol[0].count;
                        for (int i = 0; i < count; i++)
                        {
                            string filling = Convert.ToString(GetValueObj(i, colSymbol.type, colSymbol.data, dicStr[colFilling.name]));
                            if (filling != "0")
                            {
                                continue;//不是填充数据不处理
                            }

                            //安全码
                            ulong securityID = Convert.ToUInt64(GetValueObj(i, colSecurityID.type, colSecurityID.data, null));
                            //股票编号
                            string symbol = Convert.ToString(GetValueObj(i, colSymbol.type, colSymbol.data, dicStr[colSymbol.name]));
                            //交易日
                            DateTime tradingDate = Convert.ToDateTime(GetValueObj(i, colTradingDate.type, colTradingDate.data, null));

                            foreach (DataColumn col in lstCol)
                            {
                                if (lstNotIndexCode.Contains(col.name))
                                {
                                    //只处理指标列
                                    continue;
                                }

                                object objValue = GetValueObj(i, col.type, col.data, null);
                                if (IsInvalidDecValue(col.type, objValue) == false) //判断是否非法数值
                                {
                                    DataByTimeIndexInfo info = new DataByTimeIndexInfo();
                                    lstInfo.Add(info);

                                    info.SecurityID      = securityID;
                                    info.Symbol          = symbol;
                                    info.TradingDate     = tradingDate;
                                    info.TradingDateName = GetTermDisplay_Date(tradingDate, lstTradeDate);
                                    info.IndexCode       = col.name;
                                    info.IndexValue      = Convert.ToDouble(objValue);
                                    info.Filling         = filling;
                                }
                            }
                        }
                    }
                }
            }

            return(lstInfo);
        }