diff --git a/YLErpDAL/BLL/EodSettlement/RealtimePnlCalc.cs b/YLErpDAL/BLL/EodSettlement/RealtimePnlCalc.cs index 97d9d8ea..10f9cb7c 100644 --- a/YLErpDAL/BLL/EodSettlement/RealtimePnlCalc.cs +++ b/YLErpDAL/BLL/EodSettlement/RealtimePnlCalc.cs @@ -8,6 +8,7 @@ using NPOI.SS.Formula.Functions; using Org.BouncyCastle.Asn1.Ocsp; using Org.BouncyCastle.Math.EC.Multiplier; using Qdp.Pricing.Base.Implementations; +using System.IO; using System.Security.Cryptography.Xml; using YLErp.Abstract; using YLErp.Abstract.DataProviders; @@ -589,7 +590,7 @@ namespace YLErp.BLL.Eod bondDb.SaveChanges(); if (clientPosition.deal_full_price_avg > 0 && enableCalcBongd)//发kafka 获取成交收益率 { - BondCalcKafka(bondCalcTopic, clientPosition.id, clientPosition.security_id, clientPosition.side, clientPosition.deal_full_price_avg.Value); + CalcBandPrice(clientPosition); } } var sql = $"{nameof(ClientPosition.create_time)}<'{datenow.AddSeconds(-1):yyyy-MM-dd HH:mm:ss}' or {nameof(ClientPosition.position_qty)}=0"; @@ -633,7 +634,7 @@ namespace YLErp.BLL.Eod //发kafka 获取成交收益率 if (clientPosition.deal_full_price_avg > 0 && enableCalcBongd) { - BondCalcKafka(bondCalcTopic, clientPosition.id, clientPosition.security_id, clientPosition.side, clientPosition.deal_full_price_avg.Value); + CalcBandPrice(clientPosition); } else if (clientPosition.id > 0 && (clientPosition.position_qty > 0 || clientPosition.today_profit_loss != 0)) { @@ -710,42 +711,15 @@ namespace YLErp.BLL.Eod } } } - /// - /// 计算互换成交收益率消费任务 - /// - /// - public static void ConsumerBondCalcResp(KafkaConsumerHelper _kafkaConsumer) - { - _kafkaConsumer.Subscribe(msg => - { - if (!string.IsNullOrEmpty(msg)) - { - var result = JsonHelper.Deserialize(msg); - var logid = Convert.ToInt64(result.requestID); - if (result.errCode == "0") - { - using var bondDb = new BondOmsDBContext(); - string sqlstr = $"update client_position set deal_yield_avg={result.YTM} where id={logid}"; - bondDb.Database.ExecuteSqlRaw(sqlstr); - } - } - }); - } #region 新互换实时持仓私有方法 - private static void BondCalcKafka(string topic, long clientPosiId, string underlyingCode, int side, decimal price) + private static void BondCalcApi(ClientPosition clientPosition) { - BondCalcReq req = new BondCalcReq() + var resp = BondCalcHepler.BondCalc(clientPosition.security_id, clientPosition.deal_full_price_avg ?? 0, "DP"); + if (resp!=null) { - bondId = underlyingCode, - requestId = clientPosiId.ToString(), - direction = side.ToString(), - price = price, - priceType = "DP", - settleType = "0", - requestTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), - valueDate = DateTime.Now.ToString("yyyy-MM-dd") - }; - kafkaProduceHelper.Produce(topic, JsonHelper.Serialize(req)); + clientPosition.deal_yield_avg = resp.ytm* ConsGlobal.bondPriceMultiple; + _yLCache.StringSetWithNoPrefix("TRS-BondFullPrice:" + clientPosition.security_id, resp); + } } /// /// 创建持仓 @@ -892,6 +866,30 @@ namespace YLErp.BLL.Eod } } + /// + /// 计算债券价格 + /// + /// + private static void CalcBandPrice(ClientPosition clientPosition) + { + if (clientPosition.position_qty <= 0 || _yLCache == null) + { + return; + } + try + { + //TRS-BondDepthMarket:160010.IB-0 + CalBondResult bondPrice = _yLCache.StringGetWithNoPrefix("TRS-BondFullPrice:" + clientPosition.security_id); + if (bondPrice?.dirtyPrice != clientPosition.deal_full_price_avg) + { + BondCalcApi(clientPosition); + } + } + catch (Exception ex) + { + + } + } #endregion /// /// 实时risk计算 diff --git a/YLErpDAL/Helpers/HTCalcHepler.cs b/YLErpDAL/Helpers/BondCalcHepler.cs similarity index 78% rename from YLErpDAL/Helpers/HTCalcHepler.cs rename to YLErpDAL/Helpers/BondCalcHepler.cs index 8a40d7ff..b9001f99 100644 --- a/YLErpDAL/Helpers/HTCalcHepler.cs +++ b/YLErpDAL/Helpers/BondCalcHepler.cs @@ -9,23 +9,22 @@ using YLErp.Model; namespace YLErp.Helpers { /// - /// 衡泰计算器帮助类 + /// 计算器帮助类 /// - public class HTCalcHepler + public class BondCalcHepler { /// - /// 衡泰计算器 + /// 计算器 /// /// - public static CalBondResult BondCalc(string underlyingCode,int positionType,decimal price,string valueDate) + public static CalBondResult BondCalc(string underlyingCode,decimal price,string priceType="DP") { var baseUrl = Environment.GetEnvironmentVariable("BondOmsInterface_BaseUrl"); var calculateUrl = "/calc/cal_bond_value"; CalcBondRequest request = new CalcBondRequest() { bondId= underlyingCode, price = price.ToString(), - valueDate=valueDate, - direction= positionType.ToString() + priceType = priceType, }; if (!string.IsNullOrEmpty(baseUrl)) { @@ -34,7 +33,7 @@ namespace YLErp.Helpers var result = httpHelper.PostRequestNoAuth(calculateUrl, request).Result; if (result != null && !result.success) { - LogFactory.GetLogger("HTCalcHepler").Info("衡泰计算器计算失败:" + result.message); + LogFactory.GetLogger("BondCalcHepler").Info("计算器计算失败:" + result.message); } else { diff --git a/YLErpDAL/Model/CalcBondRequest.cs b/YLErpDAL/Model/CalcBondRequest.cs index 20849ec4..cec50478 100644 --- a/YLErpDAL/Model/CalcBondRequest.cs +++ b/YLErpDAL/Model/CalcBondRequest.cs @@ -15,27 +15,13 @@ namespace YLErp.Model /// public string bondId { get; set; } /// - /// 买卖方向0买1卖 - /// - public string direction { get; set; } - /// /// 价格 /// public string price { get; set; } - /// - /// 清算速度 - /// - // public string settleType { get; set; } = "0"; /// /// 价格类型 必填 DP(全价)CP(净价)YD(到期收益率) /// public string priceType { get; set; } = "DP"; - /// - /// 定价日期 - /// - public string valueDate { get; set; } - //public string requestTime { get; set; } - //public string requestId { get; set; } } public class CalcBondRequestList @@ -61,6 +47,6 @@ namespace YLErp.Model /// /// 收益率 /// - public decimal YTM { get; set; } + public decimal ytm { get; set; } } } diff --git a/YLErpDAL/Model/HengTaiModel/BondCalcReq.cs b/YLErpDAL/Model/HengTaiModel/BondCalcReq.cs deleted file mode 100644 index 1567b67a..00000000 --- a/YLErpDAL/Model/HengTaiModel/BondCalcReq.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace YLErp.Model.HengTaiModel -{ - public class BondCalcReq - { - /// - /// 债券代码 必填,格式为"券名,资产类型,市场类型" "220210,SPT_BD,X_CNBD" - /// - public string bondId { get; set; } - /// - /// 定价日 必填 - /// - public string valueDate { get; set; } - /// - /// 价格类型 必填 DP(全价)CP(净价)YD(到期收益率) - /// - public string priceType { get; set; } - /// - /// 价格 必填 - /// - public decimal price { get; set; } - /// - /// 清算速度 必填 - /// - public string settleType { get; set; } - /// - /// 请求编号 - /// - public string requestId { get; set; } - /// - /// 请求时间 - /// - public string requestTime { get; set;} - /// - /// 买卖方向 - /// - public string direction { get; set; } - /// - /// 保留字段1 - /// - public string reserver1 { get; set; } - /// - /// 保留字段2 - /// - public string reserver2 { get; set; } - } -} diff --git a/YLErpDAL/Model/HengTaiModel/BondCalcResp.cs b/YLErpDAL/Model/HengTaiModel/BondCalcResp.cs deleted file mode 100644 index e2125983..00000000 --- a/YLErpDAL/Model/HengTaiModel/BondCalcResp.cs +++ /dev/null @@ -1,90 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace YLErp.Model.HengTaiModel -{ - public class BondCalcResp - { - /// - /// 债券代码 - /// - public string bondId { get; set; } - /// - /// 定价日 - /// - public string valueDate { get; set; } - /// - /// 清算速度 - /// - public string settleType { get; set; } - /// - /// 请求编号 - /// - public string requestID { get; set; } - /// - /// 请求时间 - /// - public string requestTime { get; set; } - /// - /// 买卖方向 - /// - public string direction { get; set; } - /// - /// 保留字段1 - /// - public string reserver1 { get; set; } - /// - /// 保留字段2 - /// - public string reserver2 { get; set; } - /// - /// 全价 - /// - public decimal dirtyPrice { get; set; } - /// - /// 净价 - /// - public decimal cleanPrice { get; set; } - /// - /// 到期收益率 - /// - public decimal YTM { get; set; } - /// - /// 应计利息 - /// - public decimal Al { get; set; } - /// - /// 麦克劳林久期 - /// - public decimal MD { get; set; } - /// - /// 修正久期 - /// - public decimal AD { get; set; } - /// - /// 凸性 - /// - public decimal CV { get; set; } - /// - /// 基点价值 - /// - public decimal DVBP { get; set; } - /// - /// 剩余期限 - /// - public decimal remainTerm { get; set; } - /// - /// 关键基点价值 - /// - public decimal KDVBP { get; set; } - /// - /// 关键久期 - /// - public decimal KD { get; set; } - public string errMsg { get; set; } - public string errCode { get; set; } - } -} diff --git a/YLErpWeb/App_Data/FunctionRight.xml b/YLErpWeb/App_Data/FunctionRight.xml index a1011bbf..c9878eb5 100644 --- a/YLErpWeb/App_Data/FunctionRight.xml +++ b/YLErpWeb/App_Data/FunctionRight.xml @@ -105,9 +105,6 @@ - - - diff --git a/YLErpWeb/App_Data/Menus.txt b/YLErpWeb/App_Data/Menus.txt index 18926d39..f564c05b 100644 --- a/YLErpWeb/App_Data/Menus.txt +++ b/YLErpWeb/App_Data/Menus.txt @@ -37,8 +37,7 @@ {Name:"客户审批",Rights:["客户管理-客户审批"],Url:"clientApproval/openingclientList"}, {Name:"资信等级有效期",Rights:["客户管理-资信等级有效期"],Url:"client_rating/List"}, {Name:"黑名单客户",Rights:["客户管理-黑名单客户"],Url:"clientblack/clientblacklist"}, - {Name:"机构账号设置",Rights:["客户管理-机构账号设置"],Url:"v3/client/account"}, - {Name:"开放API配置",Rights:["客户管理-开放API配置"],Url:"v3/client/open-api"}, + {Name:"机构账号设置",Rights:["客户管理-机构账号设置"],Url:"v3/client/account"} ] }, {Name:"互换簿记预设",Rights:["互换簿记预设"],Icon:"menu-icon iconfour" diff --git a/YLErpWeb/Controllers/BondController.cs b/YLErpWeb/Controllers/BondController.cs index 18477541..ae8a74a1 100644 --- a/YLErpWeb/Controllers/BondController.cs +++ b/YLErpWeb/Controllers/BondController.cs @@ -7,9 +7,9 @@ namespace YLErp.Web.Controllers { [AllowAnonymous] - public JsonResult CalcBond(string underlyingCode, int positionType, decimal price, string valueDate) + public JsonResult CalcBond(string underlyingCode, decimal price, string priceType) { - var obj = HTCalcHepler.BondCalc(underlyingCode, positionType, price, valueDate); + var obj = BondCalcHepler.BondCalc(underlyingCode, price, priceType); if (obj == null) { return JsonError("计算价格失败"); diff --git a/YLWinSer/RealTimeCalcPositionService/appsettings.json b/YLWinSer/RealTimeCalcPositionService/appsettings.json index 871d55f2..b42f6f4b 100644 --- a/YLWinSer/RealTimeCalcPositionService/appsettings.json +++ b/YLWinSer/RealTimeCalcPositionService/appsettings.json @@ -41,7 +41,7 @@ "OnRspCalcBondTopic": "OnRspCalcBond", //互换成交收益率计算器消费topic "OnRspCalcBondTopicGroupId": "OnRspCalcBondConsumer", //互换成交收益率计算器消费topic消费组 "AutoOffsetReset": 1, //Latest(0),Earliest(1),Error(2) - "EnableCalcBongd": false //是否启用kafka计算 + "EnableCalcBongd": true //是否调用计算器 }, "BondOmsInterface": { "BaseUrl": "http://trs.yiliantech.com:8080/trs_hub_api",