From b729b388146ac3d30f38c4d7ae5d815b2d0b888f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=90=8D=E9=94=90?= <1565842059@qq.com> Date: Fri, 24 Jul 2026 13:23:35 +0800 Subject: [PATCH] =?UTF-8?q?fix(swap):=20=E4=BF=AE=E5=A4=8D=E7=BB=AD?= =?UTF-8?q?=E5=81=9A=E4=BA=A4=E6=98=93=E4=B8=AD=E6=8C=81=E4=BB=93=E5=92=8C?= =?UTF-8?q?=E5=90=8D=E4=B9=89=E6=9C=AC=E9=87=91=E7=9A=84=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 恢复初始持仓名义本金,使用OriginalStockEqvNotional和OriginalNotional的原始值 - 只克隆初始持仓(IsInitial=true),避免带入部分平仓后的实时持仓 - 设置预付金腿HappenDate为新交易起始日,非预付金腿置为null - 清空源交易的事件/持仓快照等集合,避免与源交易共享引用 - 初始化swap_Events、swap_Flow_Events等集合为空列表 --- YLErpWeb/Controllers/SwapTrade2Controller.cs | 29 ++++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/YLErpWeb/Controllers/SwapTrade2Controller.cs b/YLErpWeb/Controllers/SwapTrade2Controller.cs index 09cd2df1..954b0f14 100644 --- a/YLErpWeb/Controllers/SwapTrade2Controller.cs +++ b/YLErpWeb/Controllers/SwapTrade2Controller.cs @@ -139,6 +139,14 @@ namespace YLErp.Web.Controllers renewTrade.ValidState = null; renewTrade.CreateDate = null; renewTrade.TradeSource = null; + // 恢复初始持仓名义本金(源交易若有过部分平仓,StockEqvNotional/TradeAmount 已递减, + // 但 OriginalStockEqvNotional 和 OriginalNotional 始终保留原始值不被递减) + if (renewTrade.OriginalStockEqvNotional != null) + { + renewTrade.StockEqvNotional = (double)renewTrade.OriginalStockEqvNotional; + } + + renewTrade.TradeAmount = renewTrade.OriginalNotional ?? renewTrade.TradeAmount; renewTrade.trade_extend = sourceTrade.trade_extend?.Clone() ?? defaultTrade.trade_extend; renewTrade.trade_extend.TradeId = 0; renewTrade.trade_Initial_Margin = sourceTrade.trade_Initial_Margin?.Clone() ?? new trade_initial_margin(); @@ -146,7 +154,10 @@ namespace YLErp.Web.Controllers renewTrade.MetaDic = sourceTrade.MetaDic == null ? new Dictionary() : new Dictionary(sourceTrade.MetaDic); - renewTrade.swap_positions = sourceTrade.swap_positions.Select(position => + // 只克隆初始持仓(IsInitial=true),避免将部分平仓后的实时持仓(名义本金已递减)带入续做交易 + renewTrade.swap_positions = sourceTrade.swap_positions + ?.Where(p => p.IsInitial) + .Select(position => { var renewPosition = position.Clone(); renewPosition.id = 0; @@ -155,11 +166,23 @@ namespace YLErp.Web.Controllers renewPosition.PosiNumber = null; renewPosition.PosiStartDate = defaultTrade.StartDate.Value; renewPosition.PosiMatuirityDate = null; - renewPosition.HappenDate = null; + // 预付金腿的 HappenDate 用于后续生成资金流水(ResetMarginAmount 按 HappenDate 过滤), + // 续做时设为新交易的起始日;非预付金腿的 HappenDate 无实际用途,置 null + renewPosition.HappenDate = + position.InterestMode == (int)YLErp.DBModels.InterestModeEnum.初始预付金 + ? defaultTrade.StartDate + : null; renewPosition.InterestSwapInterval = null; renewPosition.Obervation = null; return renewPosition; - }).ToList(); + }).ToList() ?? new List(); + // 清空源交易的事件/持仓快照等集合,避免与源交易共享引用 + renewTrade.swap_Events = new List(); + renewTrade.swap_Flow_Events = new List(); + renewTrade.eod_swaps = new List(); + renewTrade.inital_eod_swap_positions = new List(); + renewTrade.eod_swap_positions = new List(); + renewTrade.ClientCashInCashOutList = new List(); return renewTrade; } ///