Exemplo n.º 1
0
        }                                         //码表缓存

        public string AnnouncementMsg(DataModel.MarketData md)
        {
            string compareMsg = " " + CommonUtils.CompareString(CompareTypeInfo) + " ";
            var    msg        = string.Format("{0}({1}) - {2}({3}){4}{5}({6}) {7} {8}",
                                              FirstSetting.Description,
                                              FirstSetting.GetValue(md),
                                              SecondSetting.Description,
                                              SecondSetting.GetValue(md),
                                              compareMsg,
                                              ThirdSetting.Description,
                                              ThirdSetting.GetValue(md),
                                              ParamCalType.CalculateString(),
                                              Param);

            return(string.Format(" {0}:{1}", md.Code, msg));
        }
Exemplo n.º 2
0
 //价差值
 public decimal GetSubValue(DataModel.MarketData md)
 {
     return(Math.Abs(FirstSetting.GetValue(md) - SecondSetting.GetValue(md)));
 }
Exemplo n.º 3
0
        public bool Match(DataModel.MarketData md)
        {
            if (!IsSubAll && !this.CodeList.Contains(md.Code))
            {
                return(false);
            }
            //if (CodeList.Contains(md.Code))
            //{
            //    Program.logger.LogRunning("检测到预警列表中的数据" + md.Code + md.Time);
            //}
            var      dt = md.Time.DateTimeFormat();
            DateTime mdTime;

            if (DateTime.TryParse(dt, out mdTime) && (DateTime.Now - mdTime).TotalMinutes > 5)
            {
                return(false);
            }

            if (Program.MatchedDataCache.ContainsKey(this.ID))
            {
                if (Program.MatchedDataCache[this.ID].ContainsKey(md.Code))
                {
                    if ((decimal)(mdTime - Program.MatchedDataCache[this.ID][md.Code].Time).TotalSeconds < Frequency)
                    {
                        return(false);
                    }
                }
            }
            else
            {
                Program.MatchedDataCache.TryAdd(this.ID, new ConcurrentDictionary <string, MarketDataExtend>());
            }

            if (FirstSetting.GetValue(md) == 0 || SecondSetting.GetValue(md) == 0 || ThirdSetting.GetValue(md) == 0)
            {
                return(false);
            }


            bool isMatch           = false;
            var  leftCompareValue  = FirstSetting.GetValue(md) - SecondSetting.GetValue(md);
            var  rightCompareValue = ParamCalType.Calculate(ThirdSetting.GetValue(md), Param);

            switch (CompareTypeInfo)
            {
            case CompareType.More:
                isMatch = leftCompareValue > rightCompareValue;
                break;

            case CompareType.MoreOrEqual:
                isMatch = leftCompareValue >= rightCompareValue;
                break;

            case CompareType.Less:
                isMatch = leftCompareValue < rightCompareValue;
                break;

            case CompareType.LessOrEqual:
                isMatch = leftCompareValue <= rightCompareValue;
                break;
            }

            if (isMatch)
            {
                //匹配,则刷新预警次数,及预警列表。
                if (!Program.Warnings.ContainsKey(this.ID))
                {
                    Program.Warnings.TryAdd(this.ID, new ConcurrentQueue <WarningEntity>());
                }
                Program.Warnings[this.ID].Enqueue(this.GetWarning(md));

                if (Program.MatchedDataCache[this.ID].ContainsKey(md.Code))
                {
                    Program.MatchedDataCache[ID][md.Code].RefreshData(md);
                }
                else
                {
                    Program.MatchedDataCache[this.ID].TryAdd(md.Code, new MarketDataExtend(md));
                }
            }
            //无论是否有预警信息,肯定刷新市场缓存。


            return(isMatch);
        }