using YLErp.Model; namespace YLErp.Modules.RiskModule { public class WarningService : YLBaseService { private static Dictionary dicCache = new Dictionary(); private static int total = 0; private static DateTime? dt = null; private WarningService(OptUserInfo userInfo) : base(userInfo) { } public static Dictionary GetInstance() { return dicCache; } public static int GetModelSum() { if (dicCache != null) { dicCache.TryGetValue("summary", out WarnModel warn); total = (warn?.YellowWarning ?? 0) + (warn?.RedWarning ?? 0); } return total; } public static DateTime? GetUpdateTime() { return dt; } public static void QuotaMonitorMsgQuery() { var dic = new Dictionary(); var service = new QuotaMonitorService(OptUserInfo.SystemUser); QuotaMonitorReq req = new QuotaMonitorReq() { PvPercent = PS.Config.ErpElement.EodVarPvPercent, UseCalcCreditExposure = false, ValueDate = System.DateTime.Today }; List OverallBusinessResult = service.QueryGlobalFromCalc(req); int allRed = 0; int allYellow = 0; if (OverallBusinessResult != null) { string prefixName = "OverallBusiness"; int redshu = 0; int yellowshu = 0; WarnModel warnDeltaCashModel = new WarnModel(); dic.Add($"{prefixName}_Delta", warnDeltaCashModel); WarnModel warnMybjModel = new WarnModel(); dic.Add($"{prefixName}_StockEqvNotional", warnMybjModel); WarnModel warnGammaModel = new WarnModel(); dic.Add($"{prefixName}_Gamma", warnGammaModel); WarnModel warnVegaModel = new WarnModel(); dic.Add($"{prefixName}_Vega", warnVegaModel); WarnModel warnThetaModel = new WarnModel(); dic.Add($"{prefixName}_Theta", warnThetaModel); WarnModel warnPositionPnlModel = new WarnModel(); dic.Add($"{prefixName}_PositionPnl", warnPositionPnlModel); OverallBusinessResult.ForEach(trade => { if (trade.Quota_DeltaCash_Lower > trade.DeltaCash || trade.Quota_DeltaCash_Upper < trade.DeltaCash) { redshu++; if (dic.ContainsKey($"{prefixName}_Delta")) { warnDeltaCashModel = dic[$"{prefixName}_Delta"]; warnDeltaCashModel.RedWarning += 1; } } if (trade.Quota_DeltaCash_wLower > trade.DeltaCash || trade.Quota_DeltaCash_wUpper < trade.DeltaCash) { yellowshu++; if (dic.ContainsKey($"{prefixName}_Delta")) { warnDeltaCashModel = dic[$"{prefixName}_Delta"]; warnDeltaCashModel.YellowWarning += 1; } } if (trade.Quota_StockEqvNotional_Lower > trade.StockEqvNotional || trade.Quota_StockEqvNotional_Upper < trade.StockEqvNotional) { redshu++; if (dic.ContainsKey($"{prefixName}_StockEqvNotional")) { warnMybjModel = dic[$"{prefixName}_StockEqvNotional"]; warnMybjModel.RedWarning += 1; } } if (trade.Quota_StockEqvNotional_wLower > trade.StockEqvNotional || trade.Quota_StockEqvNotional_wUpper < trade.StockEqvNotional) { yellowshu++; if (dic.ContainsKey($"{prefixName}_StockEqvNotional")) { warnMybjModel = dic[$"{prefixName}_StockEqvNotional"]; warnMybjModel.YellowWarning += 1; } } if (trade.Quota_GammaCash_Lower > trade.GammaCash || trade.Quota_GammaCash_Upper < trade.GammaCash) { redshu++; if (dic.ContainsKey($"{prefixName}_Gamma")) { warnGammaModel = dic[$"{prefixName}_Gamma"]; warnGammaModel.RedWarning += 1; } } if (trade.Quota_GammaCash_wLower > trade.GammaCash || trade.Quota_GammaCash_wUpper < trade.GammaCash) { yellowshu++; if (dic.ContainsKey($"{prefixName}_Gamma")) { warnGammaModel = dic[$"{prefixName}_Gamma"]; warnGammaModel.YellowWarning += 1; } } if (trade.Quota_VegaCash_Lower > trade.VegaCash || trade.Quota_VegaCash_Upper < trade.VegaCash) { redshu++; if (dic.ContainsKey($"{prefixName}_Vega")) { warnVegaModel = dic[$"{prefixName}_Vega"]; warnVegaModel.RedWarning += 1; } } if (trade.Quota_VegaCash_wLower > trade.VegaCash || trade.Quota_VegaCash_wUpper < trade.VegaCash) { yellowshu++; if (dic.ContainsKey($"{prefixName}_Vega")) { warnVegaModel = dic[$"{prefixName}_Vega"]; warnVegaModel.YellowWarning += 1; } } //if (trade.Quota_TotalPnL_Lower > trade.TotalPnL || trade.Quota_TotalPnL_Upper < trade.TotalPnL) //{ // yellowshu++; // if (dic.ContainsKey($"{prefixName}_TotalPnL")) // { // warnPnlModel = dic[$"{prefixName}_TotalPnL"]; // warnPnlModel.YellowWarning += 1; // } //} //if (trade.Quota_TotalPnL_wLower > trade.TotalPnL || trade.Quota_TotalPnL_wUpper < trade.TotalPnL) //{ // redshu++; // if (dic.ContainsKey($"{prefixName}_TotalPnL")) // { // warnPnlModel = dic[$"{prefixName}_TotalPnL"]; // warnPnlModel.RedWarning += 1; // } //} if (trade.Quota_PositionPnl_Lower > trade.PositionPnl || trade.Quota_PositionPnl_Upper < trade.PositionPnl) { redshu++; if (dic.ContainsKey($"{prefixName}_PositionPnl")) { warnPositionPnlModel = dic[$"{prefixName}_PositionPnl"]; warnPositionPnlModel.RedWarning += 1; } } if (trade.Quota_PositionPnl_wLower > trade.PositionPnl || trade.Quota_PositionPnl_wUpper < trade.PositionPnl) { yellowshu++; if (dic.ContainsKey($"{prefixName}_PositionPnl")) { warnPositionPnlModel = dic[$"{prefixName}_PositionPnl"]; warnPositionPnlModel.YellowWarning += 1; } } if (trade.Quota_Theta_Lower > trade.Theta || trade.Quota_Theta_Upper < trade.Theta) { redshu++; if (dic.ContainsKey($"{prefixName}_Theta")) { warnThetaModel = dic[$"{prefixName}_Theta"]; warnThetaModel.RedWarning += 1; } } if (trade.Quota_Theta_Lower > trade.Theta || trade.Quota_Theta_wUpper < trade.Theta) { yellowshu++; if (dic.ContainsKey($"{prefixName}_Theta")) { warnThetaModel = dic[$"{prefixName}_Theta"]; warnThetaModel.YellowWarning += 1; } } }); dic.Add($"{prefixName}_summary", new WarnModel() { RedWarning = redshu, YellowWarning = yellowshu }); allRed += redshu; allYellow += yellowshu; } var VarietyResult = service.QueryVarietyFromCalc(req); if (VarietyResult != null) { string prefixName = "Variety"; int redshu = 0; int yellowshu = 0; WarnModel warnDeltaCashModel = new WarnModel(); dic.Add($"{prefixName}_Delta", warnDeltaCashModel); WarnModel warnMybjModel = new WarnModel(); dic.Add($"{prefixName}_StockEqvNotional", warnMybjModel); WarnModel warnGammaModel = new WarnModel(); dic.Add($"{prefixName}_Gamma", warnGammaModel); WarnModel warnThetaModel = new WarnModel(); dic.Add($"{prefixName}_Theta", warnThetaModel); WarnModel warnVegaModel = new WarnModel(); dic.Add($"{prefixName}_Vega", warnVegaModel); WarnModel warnPositionPnlModel = new WarnModel(); dic.Add($"{prefixName}_PositionPnl", warnPositionPnlModel); VarietyResult.ForEach(v => { if (v.Quota_DeltaCash_Lower > v.DeltaCash || v.Quota_DeltaCash_Upper < v.DeltaCash) { redshu++; if (dic.ContainsKey($"{prefixName}_Delta")) { warnDeltaCashModel = dic[$"{prefixName}_Delta"]; warnDeltaCashModel.RedWarning += 1; } } if (v.Quota_DeltaCash_wLower > v.DeltaCash || v.Quota_DeltaCash_wUpper < v.DeltaCash) { yellowshu++; if (dic.ContainsKey($"{prefixName}_Delta")) { warnDeltaCashModel = dic[$"{prefixName}_Delta"]; warnDeltaCashModel.YellowWarning += 1; } } if (v.Quota_StockEqvNotional_Lower > v.StockEqvNotional || v.Quota_StockEqvNotional_Upper < v.StockEqvNotional) { redshu++; if (dic.ContainsKey($"{prefixName}_StockEqvNotional")) { warnMybjModel = dic[$"{prefixName}_StockEqvNotional"]; warnMybjModel.RedWarning += 1; } } if (v.Quota_StockEqvNotional_wLower > v.StockEqvNotional || v.Quota_StockEqvNotional_wUpper < v.StockEqvNotional) { yellowshu++; if (dic.ContainsKey($"{prefixName}_StockEqvNotional")) { warnMybjModel = dic[$"{prefixName}_StockEqvNotional"]; warnMybjModel.YellowWarning += 1; } } if (v.Quota_PositionPnl_Lower > v.PositionPnl || v.Quota_PositionPnl_Upper < v.PositionPnl) { redshu++; if (dic.ContainsKey($"{prefixName}_PositionPnl")) { warnPositionPnlModel = dic[$"{prefixName}_PositionPnl"]; warnPositionPnlModel.RedWarning += 1; } } if (v.Quota_PositionPnl_wLower > v.PositionPnl || v.Quota_PositionPnl_wUpper < v.PositionPnl) { yellowshu++; if (dic.ContainsKey($"{prefixName}_PositionPnl")) { warnPositionPnlModel = dic[$"{prefixName}_PositionPnl"]; warnPositionPnlModel.YellowWarning += 1; } } if (v.Quota_GammaCash_Lower > v.GammaCash || v.Quota_GammaCash_Upper < v.GammaCash) { redshu++; if (dic.ContainsKey($"{prefixName}_Gamma")) { warnGammaModel = dic[$"{prefixName}_Gamma"]; warnGammaModel.RedWarning += 1; } } if (v.Quota_GammaCash_wLower > v.GammaCash || v.Quota_GammaCash_wUpper < v.GammaCash) { yellowshu++; if (dic.ContainsKey($"{prefixName}_Gamma")) { warnGammaModel = dic[$"{prefixName}_Gamma"]; warnGammaModel.YellowWarning += 1; } } if (v.Quota_VegaCash_Lower > v.VegaCash || v.Quota_VegaCash_Upper < v.VegaCash) { redshu++; if (dic.ContainsKey($"{prefixName}_Vega")) { warnVegaModel = dic[$"{prefixName}_Vega"]; warnVegaModel.RedWarning += 1; } } if (v.Quota_VegaCash_wLower > v.VegaCash || v.Quota_VegaCash_wUpper < v.VegaCash) { yellowshu++; if (dic.ContainsKey($"{prefixName}_Vega")) { warnVegaModel = dic[$"{prefixName}_Vega"]; warnVegaModel.YellowWarning += 1; } } if (v.Quota_Theta_Lower > v.Theta || v.Quota_Theta_Upper < v.Theta) { redshu++; if (dic.ContainsKey($"{prefixName}_Theta")) { warnThetaModel = dic[$"{prefixName}_Theta"]; warnThetaModel.RedWarning += 1; } } if (v.Quota_Theta_Lower > v.Theta || v.Quota_Theta_wUpper < v.Theta) { yellowshu++; if (dic.ContainsKey($"{prefixName}_Theta")) { warnThetaModel = dic[$"{prefixName}_Theta"]; warnThetaModel.YellowWarning += 1; } } }); dic.Add($"{prefixName}_summary", new WarnModel() { RedWarning = redshu, YellowWarning = yellowshu }); allRed += redshu; allYellow += yellowshu; } dic.Add("summary", new WarnModel() { RedWarning = allRed, YellowWarning = allYellow }); dt=DateTime.Now; dicCache = dic; } } public class WarnModel { public int YellowWarning { get; set; } = 0; public int RedWarning { get; set; } = 0; } public enum WarnType { //整体业务维度 ztywwd = 1, //品种维度 pzwd = 2, } }