diff --git a/YLErpDAL/Model/HengTaiModel/SwapUnwindReq.cs b/YLErpDAL/Model/HengTaiModel/SwapUnwindReq.cs deleted file mode 100644 index 40aea13e..00000000 --- a/YLErpDAL/Model/HengTaiModel/SwapUnwindReq.cs +++ /dev/null @@ -1,67 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace YLErp.Model.HengTaiModel -{ - public class SwapUnwindReq - { - public SwapUnwindReq() { - ACCTSWAP_TERMINATE = new SwapUnwindData(); - } - public SwapUnwindData ACCTSWAP_TERMINATE {get;set;} - } - public class SwapUnwindData - { - /// - /// 客户交易号 - /// - public string CUSTORDID { get; set; } - /// - /// 返回的时候EXT_NO 对应推送的CUSTORDID - /// - public string EXT_NO { get; set; } - /// - /// 合约编号,推送不需要给,返回对应推送的EXT_NO - /// - public string CONTRACT_CODE { get; set; } - /// - /// 终止类型 全部终止 1 部分终止 0 - /// - public string TERMINATE_TYPE { get; set; } - /// - /// 终止数量 - /// - public string TERMINATE_COUNT { get; set; } - /// - /// 终止日期 - /// - public string TERMINATE_DAY { get; set; } - /// - /// 支付日期 - /// - public string PAY_DAY { get; set; } - /// - /// 资产端终止金额 不可为空 - /// - public string ZCD_AMOUNT { get; set; } - /// - /// 固定端终止金额 不可为空 - /// - public string GDD_AMOUNT { get; set; } - /// - /// 交易状态 不可为空 0新建,1审批中 - /// - public string ORDSTATUS { get; set; } - /// - /// 固定端费用 - /// - public string FIX_FEE { get; set; } - /// - /// 资产端费用 - /// - public string ASSET_FEE { get; set;} - } -} diff --git a/YLErpDAL/Modules/SwapModule/FundingLegs/UnderlyingEntryFullPriceLeg.cs b/YLErpDAL/Modules/SwapModule/FundingLegs/UnderlyingEntryFullPriceLeg.cs index 6838f7e0..a1294649 100644 --- a/YLErpDAL/Modules/SwapModule/FundingLegs/UnderlyingEntryFullPriceLeg.cs +++ b/YLErpDAL/Modules/SwapModule/FundingLegs/UnderlyingEntryFullPriceLeg.cs @@ -1,4 +1,4 @@ -using YLErp.DBModels; +using YLErp.DBModels; namespace YLErp.Modules.SwapModule.FundingLegs; @@ -7,7 +7,7 @@ namespace YLErp.Modules.SwapModule.FundingLegs; /// 计息基数 = 标的期初含费全价(PosiGrossPrice/EntryDirtyPrice) × 数量。 /// "期初(Entry)"是关键——建仓时点的全价,非当前估值全价。 /// 主路径 CalcNotionalByMode 公式与合约名义本金规模(2)相同; -/// 差异在衡泰路径会乘 grossPrice 折算(SwapDealService.GetUnwindInterestsByHT), +/// 衡泰回执折算路径(原 SwapDealService.GetUnwindInterestsByHT 乘 grossPrice 折算)已随死链清理移除; /// 以及 EOD 复利部分平仓后直接返回剩余本金(禁止反推,SwapEodPositionService:1458-1465)。 /// public sealed class UnderlyingEntryFullPriceLeg : IFundingLegStrategy diff --git a/YLErpDAL/Modules/SwapModule/SwapDealService.cs b/YLErpDAL/Modules/SwapModule/SwapDealService.cs index 69b0d9e5..7990a964 100644 --- a/YLErpDAL/Modules/SwapModule/SwapDealService.cs +++ b/YLErpDAL/Modules/SwapModule/SwapDealService.cs @@ -1,4 +1,4 @@ -using MoreLinq.Extensions; +using MoreLinq.Extensions; using Newtonsoft.Json; using YLErp.BLL; using YLErp.BLL.Eod; @@ -1696,153 +1696,6 @@ namespace YLErp.Modules.SwapModule return data.ValueAddedTax ?? 0; } - /// - /// 衡泰新增平仓事件 - /// - /// - /// - /// - /// - /// - public void AutoSwapUnwindFromConsumer(trade td, DateTime valueDate, DateTime payDate, decimal markClosePnl, decimal tradeinfFee, decimal interestAmount, decimal fee, decimal unwindQty, bool allClose) - { - List eventTypes = new List() { (int)SwapEventTypeEnum.平仓, (int)SwapEventTypeEnum.互换 }; - var dealDate = valueDate; - var tradeExtend = DbContext.trade_extend.FirstOrDefault(x => x.TradeId == td.id); - td.trade_extend = tradeExtend; - var position = DbContext.swap_position.Where(x => !string.IsNullOrEmpty(x.UnderlyingCode) && x.IsInitial && !x.Invalid).FirstOrDefault(); - var preDealDate = GetPreDealDate(td.id, dealDate, eventTypes); - swap_flow_event floatEvent = new swap_flow_event(); - UnwindData unwindData = new UnwindData(); - unwindData.CloseType = 2; - unwindData.StartDate = td.TradeDate.Value; - if (preDealDate.HasValue) - { - unwindData.StartDate = preDealDate.Value; - } - unwindData.ValueDate = dealDate; - floatEvent.EventDate = dealDate; - unwindData.UnwindDate = QdpCalendarHelper.GetNonHoliday(dealDate.AddDays(1)); - floatEvent.UnwindDate = unwindData.UnwindDate; - floatEvent.PayDate = payDate; - unwindData.PayDate = floatEvent.PayDate; - floatEvent.SwapTradeId = td.id; - floatEvent.SwapTradeNo = td.TradeNumber; - unwindData.SwapTradeId = td.id; - unwindData.StructureType = td.StructureType; - unwindData.NotionalValue = Convert.ToDecimal(td.OriginalStockEqvNotional ?? 0); - unwindData.NotionalQty = position.PosiQuantity; - unwindData.PosiNotionalValue = Convert.ToDecimal(td.StockEqvNotional); - unwindData.PositionQty = Convert.ToDecimal(td.TradeAmount); - unwindData.AnnualDays = tradeExtend == null ? 365 : tradeExtend.ExtendObj.AnnualDays; - unwindData.CloseMethod = allClose ? (int)CloseMethodEnum.全部平仓 : (int)CloseMethodEnum.部分平仓; - unwindData.ClosePercent = allClose ? 1 : unwindQty / unwindData.NotionalQty; - unwindData.CloseNotionalValue = allClose ? unwindData.PosiNotionalValue : unwindQty; - unwindData.CloseQty = allClose ? unwindData.PositionQty : unwindQty; - if (position != null) - { - decimal floatRatio = position.PosiDirection == 1 ? 1m : -1m; - floatEvent.PositionId = position.id; - floatEvent.EventType = (int)SwapEventTypeEnum.平仓; - floatEvent.EventReason = "接口合约终止交易"; - floatEvent.DividendIn = 0; - floatEvent.UnderlyingCode = position.UnderlyingCode; - floatEvent.UnderlyingInstrumentType = position.UnderlyingInstrumentType; - floatEvent.CloseFee = 0; - floatEvent.BeforeCloseFee = position.PosiTradingFee + position.PosiTradingFeePending; - floatEvent.PayDirection = position.PosiDirection; - floatEvent.PosiGrossPrice = position.PosiGrossPrice; - floatEvent.PosiNetPrice = position.PosiNetPrice; - floatEvent.TradingAmountNetAvg = position.PosiNetNoFeePrice; - floatEvent.TradingFeePending = position.PosiTradingFeePending * unwindData.ClosePercent; - floatEvent.TradingFee = tradeinfFee - floatEvent.TradingFeePending; - floatEvent.MarkClosePnl = markClosePnl; - floatEvent.TradingAmount = floatEvent.Quantity * floatEvent.ContractSize; - floatEvent.PositionType = position.PositionType; - floatEvent.Quantity = position.PosiQuantity; - floatEvent.PositionQty = 0; - floatEvent.ContractSize = position.ContractSize; - floatEvent.DataState = (int)SwapFlowDateStateEnum.完成; - floatEvent.InterestMode = position.InterestMode; - floatEvent.TradingAmount = unwindData.CloseQty; - floatEvent.ClientId = td.ClientId; - floatEvent.OptLog = "衡泰同步"; - floatEvent.SetOpt(UserInfo); - } - unwindData.FlowEvents.Add(floatEvent); - var interestPositions = GetUnwindInterestsByHT(unwindData, td, interestAmount, fee); - unwindData.FlowEvents.AddRange(interestPositions); - CalcCloseAmount(unwindData); - DealUnwind(unwindData, td, "合约终止接口回执"); - } - private List GetUnwindInterestsByHT(UnwindData unwindData, trade td, decimal interestAmount, decimal fee) - { - List interests = new List(); - var allpositions = DbContext.swap_position.Where(x => x.SwapTradeId == unwindData.SwapTradeId && !x.Invalid && x.IsInitial && x.PosiDirection > 0).ToList(); - var position = allpositions.Where(x => ConsTrade.InterestModels.Contains(x.InterestMode)).FirstOrDefault(); - if (position == null) - { - return interests; - } - var grossPrice = allpositions.Where(x => x.PosiDirection > 0).FirstOrDefault()?.PosiGrossPrice ?? 0; - var _closePosiNotionalValue = unwindData.CloseNotionalValue; - var _posiNotionalValue = unwindData.PosiNotionalValue; - var newClosePercent = unwindData.ClosePercent; - foreach (var item in allpositions) - { - var positionClone = item.Clone(); - var swapIntervalToday = position.SwapIntervalList.OrderByDescending(o => o.Date).FirstOrDefault(); - if (item.InterestMode == (int)InterestModeEnum.固定值) - { - _closePosiNotionalValue = item.InterestPrincipalFix; - _posiNotionalValue = item.InterestPrincipalFix; - newClosePercent = 1m; - } - else if (item.InterestMode == (int)InterestModeEnum.标的期初全价) - { - _closePosiNotionalValue = _posiNotionalValue * grossPrice * newClosePercent; - _posiNotionalValue = _posiNotionalValue * grossPrice; - } - else if (MarginModes.Contains(item.InterestMode)) - { - _closePosiNotionalValue = 0; - positionClone.InterestDirection = MarginCalc.FlipDirection(position.InterestDirection); - } - decimal rate = item.InterestRateDefault; - if (swapIntervalToday != null)//当日无适用观察日 - { - rate = swapIntervalToday.Rate; - } - swap_flow_event interest = new swap_flow_event(); - interest.SwapTradeId = td.id; - interest.SwapTradeNo = td.TradeNumber; - interest.EventType = (int)SwapEventTypeEnum.平仓; - interest.EventReason = "衡泰同步平仓"; - interest.EventDate = unwindData.ValueDate; - interest.PositionId = item.id; - interest.InterestDirection = positionClone.InterestDirection; - interest.InterestRate = rate; - interest.InterestPrincipal = _closePosiNotionalValue; - interest.InterestSwapInterval = item.InterestSwapInterval; - interest.InterestMode = item.InterestMode; - interest.FloatRate = item.FloatRate; - interest.DataState = (int)SwapFlowDateStateEnum.完成; - interest.ClientId = td.ClientId; - interest.UnwindDate = unwindData.ValueDate; - interest.PayDate = unwindData.PayDate; - if (position != null && item.id == position.id) - { - interest.InterestAmount = interestAmount; - interest.TdInterestAmount = interestAmount; - interest.InterestClosePnL = interestAmount; - interest.InterestFee = fee; - } - UpdateDbOption(interest); - interests.Add(interest); - } - - return interests; - } private void DealUnwind(UnwindData unwindData, trade td, string actionMsg = "系统操作_自动平仓") { int clientCashId = AddClientCashInCashOut(td, Convert.ToDouble(-unwindData.SwapRealizedPnL), ClientCashInCashOut.系统操作_平仓费, unwindData.ValueDate);