fix(swap): 修复续做交易中持仓和名义本金的初始化问题
- 恢复初始持仓名义本金,使用OriginalStockEqvNotional和OriginalNotional的原始值 - 只克隆初始持仓(IsInitial=true),避免带入部分平仓后的实时持仓 - 设置预付金腿HappenDate为新交易起始日,非预付金腿置为null - 清空源交易的事件/持仓快照等集合,避免与源交易共享引用 - 初始化swap_Events、swap_Flow_Events等集合为空列表
This commit is contained in:
@@ -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<string, string>()
|
||||
: new Dictionary<string, string>(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<swap_position>();
|
||||
// 清空源交易的事件/持仓快照等集合,避免与源交易共享引用
|
||||
renewTrade.swap_Events = new List<swap_event>();
|
||||
renewTrade.swap_Flow_Events = new List<swap_flow_event>();
|
||||
renewTrade.eod_swaps = new List<eod_swap>();
|
||||
renewTrade.inital_eod_swap_positions = new List<eod_swap_position>();
|
||||
renewTrade.eod_swap_positions = new List<eod_swap_position>();
|
||||
renewTrade.ClientCashInCashOutList = new List<ClientCashInCashOut>();
|
||||
return renewTrade;
|
||||
}
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user