盘中部分平仓逻辑挪到内部

This commit is contained in:
吴方海
2026-05-29 14:39:44 +08:00
parent 53c89f1e26
commit 4e53f822ab
+17 -13
View File
@@ -333,18 +333,7 @@ namespace YLErp.Modules.SwapModule
var grossPrice = realPostitions.Where(x => x.PosiDirection > 0).FirstOrDefault()?.PosiGrossPrice;
var closeList = DbContext.swap_flow_event.Where(x => x.SwapTradeId == tradeId && x.UnwindDate == unwindDate && eventTypes.Contains(x.EventType) && x.DataState == (int)SwapFlowDateStateEnum.).ToList();
bool tdClose = closeList.Count > 0;
interests = GetInterests(td, tradeExtend, valueDate, unwindDate, lastEodPositions, positions, stockEqvNotional, posiLongNotionalValue, posiShortNotionalValue, posiNotionalValue, closePercent, eventType, tdClose, false, grossPrice ?? 0, orginPv, true, false);
//当日有平仓或互换记录时,需要把平仓或互换已经结算的利息从计算结果中扣除,避免重复计算
foreach (var item in interests)
{
var closeEvent = closeList.Where(x => x.PositionId == item.PositionId);
var closePnl = closeEvent.Sum(s=>s.InterestClosePnL);
var closeAmount = closeEvent.Sum(s=>s.InterestAmount);
var closeTdAmount= closeEvent.Sum(s=>s.TdInterestAmount);
item.InterestAmount=item.InterestAmount-closeAmount;
item.TdInterestAmount=item.TdInterestAmount-closeTdAmount;
item.InterestClosePnL= item.InterestClosePnL-closePnl;
}
interests = GetInterests(td, tradeExtend, valueDate, unwindDate, lastEodPositions, positions, stockEqvNotional, posiLongNotionalValue, posiShortNotionalValue, posiNotionalValue, closePercent, eventType, tdClose, false, grossPrice ?? 0, orginPv, true, false, closeList);
return interests;
}
/// <summary>
@@ -382,7 +371,8 @@ namespace YLErp.Modules.SwapModule
decimal grossPrice,
decimal orginPv,
bool add = false,
bool settment = true)
bool settment = true,
List<swap_flow_event> closeList = null)
{
List<swap_flow_event> interests = new List<swap_flow_event>();
var annualDays = tradeExtend == null ? 365 : tradeExtend.ExtendObj.AnnualDays;
@@ -422,6 +412,20 @@ namespace YLErp.Modules.SwapModule
interests.Add(CalcUnwindInterest(td, valueDate, endDate, positionClone, rate, floatRate, posiPrincipal, closePrincipal, newClosePercent, annualDays, preEodPosition, eventType, add, swap, orginPv, calcFirst, calcLast));
}
}
//当日有平仓或互换记录时,需要把平仓或互换已经结算的利息从计算结果中扣除,避免重复计算
if (closeList != null && closeList.Count > 0)
{
foreach (var item in interests)
{
var closeEvent = closeList.Where(x => x.PositionId == item.PositionId);
var closePnl = closeEvent.Sum(s => s.InterestClosePnL);
var closeAmount = closeEvent.Sum(s => s.InterestAmount);
var closeTdAmount = closeEvent.Sum(s => s.TdInterestAmount);
item.InterestAmount = item.InterestAmount - closeAmount;
item.TdInterestAmount = item.TdInterestAmount - closeTdAmount;
item.InterestClosePnL = item.InterestClosePnL - closePnl;
}
}
return interests;
}