#EQD-6947 国联民生-保证金计算整体改造-实现第一版盯市规则(不支持同一客户多部门)(1)保证金规则的设置 阶段3
This commit is contained in:
@@ -9,6 +9,7 @@ using YLErp.Helpers;
|
||||
using YLErp.Model;
|
||||
using YLErp.Modules.CalculationModule;
|
||||
using YLErp.Modules.ClientModule;
|
||||
using YLErp.Modules.MarginModule;
|
||||
using YLErp.Modules.TradeModule.DealModule;
|
||||
|
||||
namespace YLErp.Modules.TradeModule
|
||||
@@ -185,6 +186,42 @@ namespace YLErp.Modules.TradeModule
|
||||
}
|
||||
|
||||
DbContext.SaveChanges();
|
||||
|
||||
// 追保规则-合约维度盯市:非互换交易(期权等)成交确认时,按计算保证金生成初始预付金资金记录(入金)。
|
||||
// 客户维度盯市(null/1)不生成出入金,保证金只进 clientbalancedaily.PayableMargin(占用),维持现状。
|
||||
var marginClient = DataCacheProvider.GetClientDataSource().GetData(newtrade.ClientId);
|
||||
if (marginClient != null && marginClient.MarginWatchRule == 0)
|
||||
{
|
||||
var initMargin = GetInitialMarginAmount(newtrade);
|
||||
if (initMargin > 0)
|
||||
{
|
||||
SaveSwapTradeClientCash(newtrade, initMargin, newtrade.TradeDate ?? DateTime.Now, 0, ClientCashInCashOut.系统操作_应付预付金);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算合约维度盯市客户成交时应生成的初始预付金金额:
|
||||
/// 交易绑定了预付金模板V2 → 名义本金(StockEqvNotional) × 初始率x("无预付金"规则算出0,不生成记录);
|
||||
/// 否则(老交易/期权)→ trade.InitialMargin。期权未放开V2绑定,恒走 InitialMargin。
|
||||
/// </summary>
|
||||
public double GetInitialMarginAmount(trade td)
|
||||
{
|
||||
if (td == null) return 0;
|
||||
// 新交易(绑定了 V2 模板)→ 名义本金 × x
|
||||
bool boundV2 = DbContext.trade_margin_template.AsNoTracking().Any(x => x.TradeId == td.id);
|
||||
if (boundV2)
|
||||
{
|
||||
var valueDate = td.TradeDate ?? DateTime.Today;
|
||||
var rate = MarginTemplateV2RateHelper.GetTradeMarginRate(td.id, td.UnderlyingCode, td.UnderlyingInstrumentType, valueDate, DbContext);
|
||||
if (rate != null)
|
||||
{
|
||||
return Math.Abs((double)(rate.InitRate ?? 0m) * td.StockEqvNotional);
|
||||
}
|
||||
// 绑定了模板但取率失败(模板无效/规则不支持/明细无匹配)→ 兜底用 InitialMargin
|
||||
}
|
||||
// 老交易(未绑 V2)/期权 → trade.InitialMargin
|
||||
return Math.Abs(td.InitialMargin ?? 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user