refactor(swap): 删除未接线的衡泰平仓消费死链 AutoSwapUnwindFromConsumer
- 移除 SwapDealService.AutoSwapUnwindFromConsumer 及其私有辅助 GetUnwindInterestsByHT(全仓零调用方,随山证 v2.3.0 拷贝引入后从未接线) - git rm 删除仅被该死链引用的 HengTaiModel/SwapUnwindReq.cs(全仓零引用) - 修正 UnderlyingEntryFullPriceLeg.cs 中指向已删方法的文档注释 - 保留真实平仓路径 DealUnwind / CalcCloseAmount 等共享活代码
This commit is contained in:
@@ -1,67 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace YLErp.Model.HengTaiModel
|
||||
{
|
||||
public class SwapUnwindReq
|
||||
{
|
||||
public SwapUnwindReq() {
|
||||
ACCTSWAP_TERMINATE = new SwapUnwindData();
|
||||
}
|
||||
public SwapUnwindData ACCTSWAP_TERMINATE {get;set;}
|
||||
}
|
||||
public class SwapUnwindData
|
||||
{
|
||||
/// <summary>
|
||||
/// 客户交易号
|
||||
/// </summary>
|
||||
public string CUSTORDID { get; set; }
|
||||
/// <summary>
|
||||
/// 返回的时候EXT_NO 对应推送的CUSTORDID
|
||||
/// </summary>
|
||||
public string EXT_NO { get; set; }
|
||||
/// <summary>
|
||||
/// 合约编号,推送不需要给,返回对应推送的EXT_NO
|
||||
/// </summary>
|
||||
public string CONTRACT_CODE { get; set; }
|
||||
/// <summary>
|
||||
/// 终止类型 全部终止 1 部分终止 0
|
||||
/// </summary>
|
||||
public string TERMINATE_TYPE { get; set; }
|
||||
/// <summary>
|
||||
/// 终止数量
|
||||
/// </summary>
|
||||
public string TERMINATE_COUNT { get; set; }
|
||||
/// <summary>
|
||||
/// 终止日期
|
||||
/// </summary>
|
||||
public string TERMINATE_DAY { get; set; }
|
||||
/// <summary>
|
||||
/// 支付日期
|
||||
/// </summary>
|
||||
public string PAY_DAY { get; set; }
|
||||
/// <summary>
|
||||
/// 资产端终止金额 不可为空
|
||||
/// </summary>
|
||||
public string ZCD_AMOUNT { get; set; }
|
||||
/// <summary>
|
||||
/// 固定端终止金额 不可为空
|
||||
/// </summary>
|
||||
public string GDD_AMOUNT { get; set; }
|
||||
/// <summary>
|
||||
/// 交易状态 不可为空 0新建,1审批中
|
||||
/// </summary>
|
||||
public string ORDSTATUS { get; set; }
|
||||
/// <summary>
|
||||
/// 固定端费用
|
||||
/// </summary>
|
||||
public string FIX_FEE { get; set; }
|
||||
/// <summary>
|
||||
/// 资产端费用
|
||||
/// </summary>
|
||||
public string ASSET_FEE { get; set;}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using YLErp.DBModels;
|
||||
using YLErp.DBModels;
|
||||
|
||||
namespace YLErp.Modules.SwapModule.FundingLegs;
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace YLErp.Modules.SwapModule.FundingLegs;
|
||||
/// 计息基数 = 标的期初含费全价(PosiGrossPrice/EntryDirtyPrice) × 数量。
|
||||
/// "期初(Entry)"是关键——建仓时点的全价,非当前估值全价。
|
||||
/// 主路径 CalcNotionalByMode 公式与合约名义本金规模(2)相同;
|
||||
/// 差异在衡泰路径会乘 grossPrice 折算(SwapDealService.GetUnwindInterestsByHT),
|
||||
/// 衡泰回执折算路径(原 SwapDealService.GetUnwindInterestsByHT 乘 grossPrice 折算)已随死链清理移除;
|
||||
/// 以及 EOD 复利部分平仓后直接返回剩余本金(禁止反推,SwapEodPositionService:1458-1465)。
|
||||
/// </summary>
|
||||
public sealed class UnderlyingEntryFullPriceLeg : IFundingLegStrategy
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using MoreLinq.Extensions;
|
||||
using MoreLinq.Extensions;
|
||||
using Newtonsoft.Json;
|
||||
using YLErp.BLL;
|
||||
using YLErp.BLL.Eod;
|
||||
@@ -1696,153 +1696,6 @@ namespace YLErp.Modules.SwapModule
|
||||
return data.ValueAddedTax ?? 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 衡泰新增平仓事件
|
||||
/// </summary>
|
||||
/// <param name="td"></param>
|
||||
/// <param name="valueDate"></param>
|
||||
/// <param name="markClosePnl"></param>
|
||||
/// <param name="unwindQty"></param>
|
||||
/// <param name="allClose"></param>
|
||||
public void AutoSwapUnwindFromConsumer(trade td, DateTime valueDate, DateTime payDate, decimal markClosePnl, decimal tradeinfFee, decimal interestAmount, decimal fee, decimal unwindQty, bool allClose)
|
||||
{
|
||||
List<int> eventTypes = new List<int>() { (int)SwapEventTypeEnum.平仓, (int)SwapEventTypeEnum.互换 };
|
||||
var dealDate = valueDate;
|
||||
var tradeExtend = DbContext.trade_extend.FirstOrDefault(x => x.TradeId == td.id);
|
||||
td.trade_extend = tradeExtend;
|
||||
var position = DbContext.swap_position.Where(x => !string.IsNullOrEmpty(x.UnderlyingCode) && x.IsInitial && !x.Invalid).FirstOrDefault();
|
||||
var preDealDate = GetPreDealDate(td.id, dealDate, eventTypes);
|
||||
swap_flow_event floatEvent = new swap_flow_event();
|
||||
UnwindData unwindData = new UnwindData();
|
||||
unwindData.CloseType = 2;
|
||||
unwindData.StartDate = td.TradeDate.Value;
|
||||
if (preDealDate.HasValue)
|
||||
{
|
||||
unwindData.StartDate = preDealDate.Value;
|
||||
}
|
||||
unwindData.ValueDate = dealDate;
|
||||
floatEvent.EventDate = dealDate;
|
||||
unwindData.UnwindDate = QdpCalendarHelper.GetNonHoliday(dealDate.AddDays(1));
|
||||
floatEvent.UnwindDate = unwindData.UnwindDate;
|
||||
floatEvent.PayDate = payDate;
|
||||
unwindData.PayDate = floatEvent.PayDate;
|
||||
floatEvent.SwapTradeId = td.id;
|
||||
floatEvent.SwapTradeNo = td.TradeNumber;
|
||||
unwindData.SwapTradeId = td.id;
|
||||
unwindData.StructureType = td.StructureType;
|
||||
unwindData.NotionalValue = Convert.ToDecimal(td.OriginalStockEqvNotional ?? 0);
|
||||
unwindData.NotionalQty = position.PosiQuantity;
|
||||
unwindData.PosiNotionalValue = Convert.ToDecimal(td.StockEqvNotional);
|
||||
unwindData.PositionQty = Convert.ToDecimal(td.TradeAmount);
|
||||
unwindData.AnnualDays = tradeExtend == null ? 365 : tradeExtend.ExtendObj.AnnualDays;
|
||||
unwindData.CloseMethod = allClose ? (int)CloseMethodEnum.全部平仓 : (int)CloseMethodEnum.部分平仓;
|
||||
unwindData.ClosePercent = allClose ? 1 : unwindQty / unwindData.NotionalQty;
|
||||
unwindData.CloseNotionalValue = allClose ? unwindData.PosiNotionalValue : unwindQty;
|
||||
unwindData.CloseQty = allClose ? unwindData.PositionQty : unwindQty;
|
||||
if (position != null)
|
||||
{
|
||||
decimal floatRatio = position.PosiDirection == 1 ? 1m : -1m;
|
||||
floatEvent.PositionId = position.id;
|
||||
floatEvent.EventType = (int)SwapEventTypeEnum.平仓;
|
||||
floatEvent.EventReason = "接口合约终止交易";
|
||||
floatEvent.DividendIn = 0;
|
||||
floatEvent.UnderlyingCode = position.UnderlyingCode;
|
||||
floatEvent.UnderlyingInstrumentType = position.UnderlyingInstrumentType;
|
||||
floatEvent.CloseFee = 0;
|
||||
floatEvent.BeforeCloseFee = position.PosiTradingFee + position.PosiTradingFeePending;
|
||||
floatEvent.PayDirection = position.PosiDirection;
|
||||
floatEvent.PosiGrossPrice = position.PosiGrossPrice;
|
||||
floatEvent.PosiNetPrice = position.PosiNetPrice;
|
||||
floatEvent.TradingAmountNetAvg = position.PosiNetNoFeePrice;
|
||||
floatEvent.TradingFeePending = position.PosiTradingFeePending * unwindData.ClosePercent;
|
||||
floatEvent.TradingFee = tradeinfFee - floatEvent.TradingFeePending;
|
||||
floatEvent.MarkClosePnl = markClosePnl;
|
||||
floatEvent.TradingAmount = floatEvent.Quantity * floatEvent.ContractSize;
|
||||
floatEvent.PositionType = position.PositionType;
|
||||
floatEvent.Quantity = position.PosiQuantity;
|
||||
floatEvent.PositionQty = 0;
|
||||
floatEvent.ContractSize = position.ContractSize;
|
||||
floatEvent.DataState = (int)SwapFlowDateStateEnum.完成;
|
||||
floatEvent.InterestMode = position.InterestMode;
|
||||
floatEvent.TradingAmount = unwindData.CloseQty;
|
||||
floatEvent.ClientId = td.ClientId;
|
||||
floatEvent.OptLog = "衡泰同步";
|
||||
floatEvent.SetOpt(UserInfo);
|
||||
}
|
||||
unwindData.FlowEvents.Add(floatEvent);
|
||||
var interestPositions = GetUnwindInterestsByHT(unwindData, td, interestAmount, fee);
|
||||
unwindData.FlowEvents.AddRange(interestPositions);
|
||||
CalcCloseAmount(unwindData);
|
||||
DealUnwind(unwindData, td, "合约终止接口回执");
|
||||
}
|
||||
private List<swap_flow_event> GetUnwindInterestsByHT(UnwindData unwindData, trade td, decimal interestAmount, decimal fee)
|
||||
{
|
||||
List<swap_flow_event> interests = new List<swap_flow_event>();
|
||||
var allpositions = DbContext.swap_position.Where(x => x.SwapTradeId == unwindData.SwapTradeId && !x.Invalid && x.IsInitial && x.PosiDirection > 0).ToList();
|
||||
var position = allpositions.Where(x => ConsTrade.InterestModels.Contains(x.InterestMode)).FirstOrDefault();
|
||||
if (position == null)
|
||||
{
|
||||
return interests;
|
||||
}
|
||||
var grossPrice = allpositions.Where(x => x.PosiDirection > 0).FirstOrDefault()?.PosiGrossPrice ?? 0;
|
||||
var _closePosiNotionalValue = unwindData.CloseNotionalValue;
|
||||
var _posiNotionalValue = unwindData.PosiNotionalValue;
|
||||
var newClosePercent = unwindData.ClosePercent;
|
||||
foreach (var item in allpositions)
|
||||
{
|
||||
var positionClone = item.Clone();
|
||||
var swapIntervalToday = position.SwapIntervalList.OrderByDescending(o => o.Date).FirstOrDefault();
|
||||
if (item.InterestMode == (int)InterestModeEnum.固定值)
|
||||
{
|
||||
_closePosiNotionalValue = item.InterestPrincipalFix;
|
||||
_posiNotionalValue = item.InterestPrincipalFix;
|
||||
newClosePercent = 1m;
|
||||
}
|
||||
else if (item.InterestMode == (int)InterestModeEnum.标的期初全价)
|
||||
{
|
||||
_closePosiNotionalValue = _posiNotionalValue * grossPrice * newClosePercent;
|
||||
_posiNotionalValue = _posiNotionalValue * grossPrice;
|
||||
}
|
||||
else if (MarginModes.Contains(item.InterestMode))
|
||||
{
|
||||
_closePosiNotionalValue = 0;
|
||||
positionClone.InterestDirection = MarginCalc.FlipDirection(position.InterestDirection);
|
||||
}
|
||||
decimal rate = item.InterestRateDefault;
|
||||
if (swapIntervalToday != null)//当日无适用观察日
|
||||
{
|
||||
rate = swapIntervalToday.Rate;
|
||||
}
|
||||
swap_flow_event interest = new swap_flow_event();
|
||||
interest.SwapTradeId = td.id;
|
||||
interest.SwapTradeNo = td.TradeNumber;
|
||||
interest.EventType = (int)SwapEventTypeEnum.平仓;
|
||||
interest.EventReason = "衡泰同步平仓";
|
||||
interest.EventDate = unwindData.ValueDate;
|
||||
interest.PositionId = item.id;
|
||||
interest.InterestDirection = positionClone.InterestDirection;
|
||||
interest.InterestRate = rate;
|
||||
interest.InterestPrincipal = _closePosiNotionalValue;
|
||||
interest.InterestSwapInterval = item.InterestSwapInterval;
|
||||
interest.InterestMode = item.InterestMode;
|
||||
interest.FloatRate = item.FloatRate;
|
||||
interest.DataState = (int)SwapFlowDateStateEnum.完成;
|
||||
interest.ClientId = td.ClientId;
|
||||
interest.UnwindDate = unwindData.ValueDate;
|
||||
interest.PayDate = unwindData.PayDate;
|
||||
if (position != null && item.id == position.id)
|
||||
{
|
||||
interest.InterestAmount = interestAmount;
|
||||
interest.TdInterestAmount = interestAmount;
|
||||
interest.InterestClosePnL = interestAmount;
|
||||
interest.InterestFee = fee;
|
||||
}
|
||||
UpdateDbOption(interest);
|
||||
interests.Add(interest);
|
||||
}
|
||||
|
||||
return interests;
|
||||
}
|
||||
private void DealUnwind(UnwindData unwindData, trade td, string actionMsg = "系统操作_自动平仓")
|
||||
{
|
||||
int clientCashId = AddClientCashInCashOut(td, Convert.ToDouble(-unwindData.SwapRealizedPnL), ClientCashInCashOut.系统操作_平仓费, unwindData.ValueDate);
|
||||
|
||||
Reference in New Issue
Block a user