From 870cd337f6f78a7c11ce1600779dbfd468800212 Mon Sep 17 00:00:00 2001 From: hjhan Date: Tue, 11 Aug 2026 13:18:20 +0800 Subject: [PATCH] =?UTF-8?q?refactor(margin):=20=E6=8A=BD=E5=8F=96=20Accumu?= =?UTF-8?q?lateMarginSettlement=20=E4=BF=9D=E8=AF=81=E9=87=91=E5=B9=B3?= =?UTF-8?q?=E4=BB=93=E6=B1=87=E6=80=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 把 SwapUnwind 里 inline 的保证金汇总逻辑(SwapMarginRebatePnl + SwapMarginAmount)抽成独立方法, 与融资腿汇总分离。 原循环里保证金和融资腿混在一起, 现在保证金走 AccumulateMarginSettlement, 融资腿汇总留在主循环。 待迁入 Margin 模块。 验证: 编译0错误, 全量509测试7失败(基线一致)。 --- .../Modules/SwapModule/SwapDealService.cs | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/YLErpDAL/Modules/SwapModule/SwapDealService.cs b/YLErpDAL/Modules/SwapModule/SwapDealService.cs index e95b395b..2c4f24fe 100644 --- a/YLErpDAL/Modules/SwapModule/SwapDealService.cs +++ b/YLErpDAL/Modules/SwapModule/SwapDealService.cs @@ -1,7 +1,5 @@ using MoreLinq.Extensions; using Newtonsoft.Json; -using Qdp.Pricing.Library.Base.Utilities; -using System.Linq.Expressions; using YLErp.BLL; using YLErp.BLL.Eod; using YLErp.DBModels.Enums; @@ -9,11 +7,11 @@ using YLErp.Derivatives.Interest; using YLErp.Helpers; using YLErp.Modules.DataProviderModule; using YLErp.Modules.EodModule; -using YLErp.Modules.TradeModule; -using YLErp.Modules.TradeModule.DealModule; using YLErp.Modules.SwapModule.FundingLegs; using YLErp.Modules.SwapModule.Margin; using YLErp.Modules.SwapModule.ReturnLegs; +using YLErp.Modules.TradeModule; +using YLErp.Modules.TradeModule.DealModule; using YLErp.QdpModule; namespace YLErp.Modules.SwapModule @@ -1153,6 +1151,22 @@ namespace YLErp.Modules.SwapModule ? (int)SwapDirectionEnum.支付 : (int)SwapDirectionEnum.收取; + /// + /// 汇总保证金腿的平仓返还金额(SwapMarginAmount)和保证金返息(SwapMarginRebatePnl)。 + /// 保证金方向与融资腿相反:interestRatio = InterestDirection==1 ? -1 : 1。 + /// 待迁入 Margin 模块。 + /// + private static void AccumulateMarginSettlement(List interestList, UnwindData unwindData) + { + foreach (var x in interestList) + { + if (!MarginModes.Contains(x.InterestMode)) continue; + var interestRatio = x.InterestDirection == 1 ? -1m : 1m; + unwindData.SwapMarginRebatePnl += x.InterestClosePnL; + unwindData.SwapMarginAmount += x.InterestPrincipal * interestRatio; + } + } + /// /// 初始化利息腿信息 /// @@ -1993,17 +2007,11 @@ namespace YLErp.Modules.SwapModule unwindData.SwapMarginAmount = 0; if (interestList != null) { + AccumulateMarginSettlement(interestList.ToList(), unwindData); interestList.ForEach(x => { - if (MarginModes.Contains(x.InterestMode)) - { - decimal interestRatio = x.InterestDirection == 1 ? -1m : 1m; - unwindData.SwapMarginRebatePnl += x.InterestClosePnL; - unwindData.SwapMarginAmount += x.InterestPrincipal * interestRatio; - } unwindData.SwapRealizedPnL += x.InterestClosePnL; unwindData.SwapCloseAmount += x.InterestClosePnL; - }); } unwindData.SwapCloseAmount = Math.Round(unwindData.SwapCloseAmount, 2, MidpointRounding.AwayFromZero);