refactor(margin): 抽取 AccumulateMarginSettlement 保证金平仓汇总

把 SwapUnwind 里 inline 的保证金汇总逻辑(SwapMarginRebatePnl +
SwapMarginAmount)抽成独立方法, 与融资腿汇总分离。

原循环里保证金和融资腿混在一起, 现在保证金走
AccumulateMarginSettlement, 融资腿汇总留在主循环。
待迁入 Margin 模块。

验证: 编译0错误, 全量509测试7失败(基线一致)。
This commit is contained in:
hjhan
2026-08-11 13:18:20 +08:00
parent 585cefa85d
commit 870cd337f6
+19 -11
View File
@@ -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.;
/// <summary>
/// 汇总保证金腿的平仓返还金额(SwapMarginAmount)和保证金返息(SwapMarginRebatePnl)。
/// 保证金方向与融资腿相反:interestRatio = InterestDirection==1 ? -1 : 1。
/// 待迁入 Margin 模块。
/// </summary>
private static void AccumulateMarginSettlement(List<swap_flow_event> 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;
}
}
/// <summary>
/// 初始化利息腿信息
/// </summary>
@@ -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);