From 7d0397fc441b910c1ad654581c3cab2439a13284 Mon Sep 17 00:00:00 2001 From: hjhan Date: Tue, 11 Aug 2026 09:13:26 +0800 Subject: [PATCH] =?UTF-8?q?refactor(interest):=20CalcNotionalByMode=20?= =?UTF-8?q?=E8=9E=8D=E8=B5=84=E8=85=BF=E5=A7=94=E6=89=98=E7=AD=96=E7=95=A5?= =?UTF-8?q?=E5=B7=A5=E5=8E=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 融资腿(mode 1固定值/2合约名义本金/9标的期初全价)改由 InterestLegStrategyFactory.Get(mode).CalcNotional(...) 计算, 不再走原 switch 的 case。 保证金(mode 5/6)和多空存续(mode 7/8)暂保留原 switch 逻辑, 待 Margin 上下文接入后再迁出。 行为等价: 全量480测试, 改动前后失败数一致(7个, 全为无库环境问题), 零回归。 --- .../Modules/SwapModule/SwapDealService.cs | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/YLErpDAL/Modules/SwapModule/SwapDealService.cs b/YLErpDAL/Modules/SwapModule/SwapDealService.cs index c9605a21..4183bece 100644 --- a/YLErpDAL/Modules/SwapModule/SwapDealService.cs +++ b/YLErpDAL/Modules/SwapModule/SwapDealService.cs @@ -10,6 +10,7 @@ using YLErp.Modules.DataProviderModule; using YLErp.Modules.EodModule; using YLErp.Modules.TradeModule; using YLErp.Modules.TradeModule.DealModule; +using YLErp.Modules.SwapModule.InterestLegs; using YLErp.QdpModule; namespace YLErp.Modules.SwapModule @@ -898,20 +899,31 @@ namespace YLErp.Modules.SwapModule } /// - /// 根据计息模式计算名义本金 + /// 根据计息模式计算名义本金。 + /// 融资腿(mode 1/2/9)已委托 InterestLegStrategyFactory;保证金(mode 5/6)和 + /// 半禁用的多空存续(mode 7/8)暂保留原逻辑,待 Margin 上下文接入后再迁出。 /// private (decimal close, decimal posi, decimal closePct) CalcNotionalByMode(swap_position position, decimal closePercent, decimal posiNotional, decimal posiLong, decimal posiShort) { - decimal closePrincipal = posiNotional; // 平仓部分的名义本金 - decimal posiPrincipal = posiNotional; // 持仓部分的名义本金 - decimal newClosePercent = closePercent; // 调整后的平仓比例 + var mode = (InterestModeEnum)position.InterestMode; - switch ((InterestModeEnum)position.InterestMode) + // 融资腿(1/2/9)走策略工厂 + if (mode == InterestModeEnum.固定值 + || mode == InterestModeEnum.合约名义本金规模 + || mode == InterestModeEnum.标的期初全价) + { + var r = InterestLegStrategyFactory.Get(mode) + .CalcNotional(position.InterestPrincipalFix, posiNotional, posiLong, posiShort, closePercent); + return (r.ClosePrincipal, r.PosiPrincipal, r.ClosePercent); + } + + // 以下 mode 尚未迁入新架构,保留原逻辑 + decimal closePrincipal = posiNotional; + decimal posiPrincipal = posiNotional; + decimal newClosePercent = closePercent; + + switch (mode) { - case InterestModeEnum.固定值: - closePrincipal = posiPrincipal = position.InterestPrincipalFix; - newClosePercent = 1m; - break; case InterestModeEnum.多头存续名义本金: closePrincipal = posiLong * closePercent; posiPrincipal = posiLong; @@ -920,12 +932,6 @@ namespace YLErp.Modules.SwapModule closePrincipal = posiShort * closePercent; posiPrincipal = posiShort; break; - case InterestModeEnum.合约名义本金规模: - closePrincipal = posiNotional * closePercent; - break; - case InterestModeEnum.标的期初全价: - closePrincipal = posiNotional * closePercent; - break; case InterestModeEnum.追加预付金: case InterestModeEnum.初始预付金: closePrincipal = position.InterestPrincipalFix * closePercent;