Merge branch 'hotfix/zs_trs'
This commit is contained in:
@@ -135,19 +135,17 @@ namespace YLErp.Modules.SwapModule
|
||||
{
|
||||
throw new Exception($"交易【{td.TradeNumber}】到期扔有持仓信息");
|
||||
}
|
||||
//实际自动互换数据开头已删除
|
||||
var longEventTypes = eventTyps;
|
||||
longEventTypes.Add((int)SwapFlowEventTypeEnum.开仓);
|
||||
var flowEvents = new List<swap_flow_event>();
|
||||
Expression<Func<swap_flow_event, bool>> eventExpression = x => x.SwapTradeId == td.id && x.DataState == (int)SwapFlowDateStateEnum.完成 && longEventTypes.Contains(x.EventType);
|
||||
if (settleDate == td.TradeDate)
|
||||
{
|
||||
eventExpression = eventExpression.And(x => x.EventDate == settleDate);
|
||||
}
|
||||
else
|
||||
{
|
||||
eventExpression = eventExpression.And(x => x.UnwindDate == settleDate);
|
||||
}
|
||||
Expression<Func<swap_flow_event, bool>> eventExpression = x => x.SwapTradeId == td.id && x.DataState == (int)SwapFlowDateStateEnum.完成;
|
||||
eventExpression = eventExpression.And(x => (x.EventDate == settleDate && x.EventType == (int)SwapFlowEventTypeEnum.开仓) || (x.UnwindDate == settleDate && eventTyps.Contains(x.EventType)));
|
||||
//if (settleDate == td.TradeDate)
|
||||
//{
|
||||
// eventExpression = eventExpression.And(x => x.EventDate == settleDate);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// eventExpression = eventExpression.And(x => x.UnwindDate == settleDate);
|
||||
//}
|
||||
flowEvents = DbContext.swap_flow_event.Where(eventExpression).ToList();
|
||||
var preDealDate = GetPreDealDate(td.id, settleDate, eventTyps);//上一次平仓/互换/自动互换处理日期
|
||||
List<swap_flow_event> autoInterests = new List<swap_flow_event>();//自动互换利息腿信息
|
||||
@@ -1349,16 +1347,15 @@ namespace YLErp.Modules.SwapModule
|
||||
curretEod.PosiTradingFee = position.PosiTradingFee;
|
||||
curretEod.UnderlyingPrice = UnderlyingCodePrice(position.UnderlyingCode, dealDate, out decimal vobp);
|
||||
SetPriceInfoByFlowEvent(eod, curretEod, unwindEvents, position);
|
||||
if (settleDate == td.TradeDate)
|
||||
{
|
||||
curretEod.UnderlyingPrice = curretEod.PosiGrossPrice;
|
||||
curretEod.TdCloseMtmPnl = 0;
|
||||
curretEod.TdCloseFee = 0;
|
||||
}
|
||||
curretEod.TdCloseDividend = curretEod.TdPosiDividend;
|
||||
curretEod.UnderlyingMarketValue = curretEod.UnderlyingPrice * curretEod.PosiQuantity * curretEod.ContractSize * shortRatio;
|
||||
curretEod.PosiMtmPnL = (curretEod.UnderlyingPrice - curretEod.PosiGrossPrice) * curretEod.PosiQuantity * curretEod.ContractSize * shortRatio * directionRatio;
|
||||
if (settleDate == td.TradeDate)
|
||||
{
|
||||
curretEod.PosiMtmPnL = 0;
|
||||
//curretEod.TdCloseMtmPnl = 0;
|
||||
//curretEod.TdCloseFee = 0;
|
||||
}
|
||||
curretEod.PosiDividendSum = curretEod.TdPosiDividend;
|
||||
curretEod.PosiProfitSum = curretEod.PosiMtmPnL + curretEod.PosiDividendSum + curretEod.VTradingFee;
|
||||
curretEod.RealizedMtmPnL = curretEod.TdCloseMtmPnl;
|
||||
curretEod.RealizedDividend = curretEod.TdCloseDividend;
|
||||
|
||||
@@ -28,6 +28,101 @@ namespace YLErp.Modules.SwapModule
|
||||
{
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 查询今天是否有FR007的数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
|
||||
public eod_commodity_future_price SearchTodayFRData(DateTime dateTime)
|
||||
{
|
||||
var data = DbContext.eod_commodity_future_price.Where(a => a.ValueDate == dateTime).FirstOrDefault();
|
||||
if (data == null)
|
||||
{
|
||||
data = new eod_commodity_future_price();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询选择的时间是否拥有FR007的数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
|
||||
public List<eod_commodity_future_price> SearchdateFRData(List<DateTime> date)
|
||||
{
|
||||
var datafr007 = DbContext.eod_commodity_future_price.Where(a => date.Contains(a.ValueDate)).ToList();
|
||||
return datafr007;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除的RF007数据
|
||||
/// </summary>
|
||||
/// <param name="id">要删除的RF007数据Id</param>
|
||||
/// <exception cref="ServiceException"></exception>
|
||||
public bool DeleteFRData(int id)
|
||||
{
|
||||
|
||||
var frdata = DbContext.eod_commodity_future_price.Find(id);
|
||||
if (frdata == null)
|
||||
{
|
||||
throw new ServiceException("未找到FR007流水");
|
||||
}
|
||||
DbContext.eod_commodity_future_price.Remove(frdata);
|
||||
DbContext.SaveChanges();
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// 新增或者修改FR007数据
|
||||
/// </summary>
|
||||
/// <param name="price">FR007价格</param>
|
||||
/// <param name="dateTime">新增或者修改时间</param>
|
||||
/// <exception cref="ServiceException"></exception>
|
||||
public bool AddOrUpdateFRdata(Double price, DateTime dateTime)
|
||||
{
|
||||
string beforedate = "";
|
||||
var frdata = DbContext.eod_commodity_future_price.Where(a => a.ValueDate == dateTime).FirstOrDefault();
|
||||
if (frdata == null)
|
||||
{
|
||||
frdata = new eod_commodity_future_price();
|
||||
}
|
||||
//修改
|
||||
if (frdata != null && frdata?.UnderlyingCode != null)
|
||||
{
|
||||
frdata.ValueDate = dateTime;
|
||||
frdata.HighPrice = 0;
|
||||
frdata.LowPrice = 0;
|
||||
beforedate = JsonHelper.Serialize(frdata);
|
||||
}
|
||||
else
|
||||
{
|
||||
//新增
|
||||
var newestdata = DbContext.eod_commodity_future_price.OrderByDescending(a => a.ValueDate).FirstOrDefault();
|
||||
if (newestdata == null)
|
||||
{
|
||||
var underlyingCode = DbContext.underlying_manager.Where(a => a.UnderlyingCode == "FR007").FirstOrDefault();
|
||||
if (underlyingCode == null)
|
||||
{
|
||||
throw new ServiceException("找不到FR007的标的");
|
||||
}
|
||||
newestdata = new eod_commodity_future_price();
|
||||
newestdata.UnderlyingId = underlyingCode.id;
|
||||
}
|
||||
frdata.ValueDate = dateTime;
|
||||
frdata.UnderlyingCode = "FR007";
|
||||
frdata.UnderlyingId = newestdata.UnderlyingId;
|
||||
frdata.DataSource = "人工";
|
||||
DbContext.Add(frdata);
|
||||
}
|
||||
frdata.ClosePrice = Math.Round(price, 4);
|
||||
frdata.SettlePrice = Math.Round(price, 4);
|
||||
frdata.ReferencePrice = Math.Round(price, 4);
|
||||
frdata.OptId = UserInfo.UserId;
|
||||
frdata.OptName = UserInfo.UserName;
|
||||
frdata.OptDate = DateTime.Now;
|
||||
DbContext.SaveChanges();
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询互换流水导入
|
||||
/// </summary>
|
||||
|
||||
@@ -107,8 +107,8 @@ namespace YLErp.Modules.SwapModule
|
||||
swapRate.DiscountRateIsPercent = req.DiscountRateIsPercent;
|
||||
swapRate.DiscountRate = req.DiscountRate;
|
||||
swapRate.FrontDeskCharge = req.FrontDeskCharge;
|
||||
swapRate.FrontDeskChargeIsPercent=req.FrontDeskChargeIsPercent;
|
||||
swapRate.BackDeskCharge=req.BackDeskCharge;
|
||||
swapRate.FrontDeskChargeIsPercent = req.FrontDeskChargeIsPercent;
|
||||
swapRate.BackDeskCharge = req.BackDeskCharge;
|
||||
swapRate.BackDeskChargeIsPercent = req.BackDeskChargeIsPercent;
|
||||
swapRate.SetOpt(UserId, UserName);
|
||||
}
|
||||
@@ -227,34 +227,55 @@ namespace YLErp.Modules.SwapModule
|
||||
var tempRate = reader.GetString("临时费率");
|
||||
if (!string.IsNullOrEmpty(tempRate))
|
||||
{
|
||||
decimal rate = 0;
|
||||
if (tempRate.EndsWith("%"))
|
||||
{
|
||||
swapRate.TempRateIsPercent = true;
|
||||
tempRate = tempRate.Replace("%", "");
|
||||
decimal.TryParse(tempRate, out rate);
|
||||
rate = rate / 100;
|
||||
}
|
||||
else
|
||||
{
|
||||
swapRate.TempRateIsPercent = false;
|
||||
decimal.TryParse(tempRate, out rate);
|
||||
}
|
||||
decimal.TryParse(tempRate, out var rate);
|
||||
swapRate.TempRate = rate;
|
||||
}
|
||||
var baseRate = reader.GetString("基础费率");
|
||||
if (!string.IsNullOrEmpty(baseRate))
|
||||
{
|
||||
decimal rate = 0;
|
||||
if (baseRate.EndsWith("%"))
|
||||
{
|
||||
swapRate.BaseRateIsPercent = true;
|
||||
baseRate = baseRate.Replace("%", "");
|
||||
decimal.TryParse(baseRate, out rate);
|
||||
rate = rate / 100;
|
||||
}
|
||||
else
|
||||
{
|
||||
swapRate.BaseRateIsPercent = false;
|
||||
decimal.TryParse(baseRate, out rate);
|
||||
}
|
||||
decimal.TryParse(baseRate, out var rate);
|
||||
swapRate.BaseRate = rate;
|
||||
}
|
||||
var disAccRate = reader.GetString("优惠费率");
|
||||
if (!string.IsNullOrEmpty(disAccRate))
|
||||
{
|
||||
decimal rate = 0;
|
||||
if (disAccRate.EndsWith("%"))
|
||||
{
|
||||
swapRate.DiscountRateIsPercent = true;
|
||||
disAccRate = disAccRate.Replace("%", "");
|
||||
decimal.TryParse(disAccRate, out rate);
|
||||
rate = rate / 100;
|
||||
}
|
||||
else
|
||||
{
|
||||
swapRate.DiscountRateIsPercent = false;
|
||||
decimal.TryParse(disAccRate, out rate);
|
||||
}
|
||||
decimal.TryParse(disAccRate, out var rate);
|
||||
swapRate.DiscountRate = rate;
|
||||
}
|
||||
var frontRate = reader.GetString("现券对冲交易费用");
|
||||
@@ -265,7 +286,8 @@ namespace YLErp.Modules.SwapModule
|
||||
swapRate.FrontDeskChargeIsPercent = true;
|
||||
frontRate = frontRate.Replace("‱", "");
|
||||
}
|
||||
decimal.TryParse(frontRate, out var rate);
|
||||
|
||||
decimal.TryParse(frontRate, out var rate);
|
||||
swapRate.FrontDeskCharge = rate * 0.0001m;
|
||||
}
|
||||
var backRate = reader.GetString("现券对冲结算费用");
|
||||
@@ -277,7 +299,7 @@ namespace YLErp.Modules.SwapModule
|
||||
backRate = backRate.Replace("‱", "");
|
||||
}
|
||||
decimal.TryParse(backRate, out var rate);
|
||||
swapRate.BackDeskCharge = rate*0.0001m;
|
||||
swapRate.BackDeskCharge = rate * 0.0001m;
|
||||
}
|
||||
swapRate.DiscountAccDown = reader.GetDecimal("优惠累计量下限");
|
||||
ValidateSwapRate(swapRate);
|
||||
@@ -321,7 +343,7 @@ namespace YLErp.Modules.SwapModule
|
||||
exportModel.TempRate = item.TempRateIsPercent ? item.TempRate.OtcFormatPercent(4) : item.TempRate.OtcFormatMoney(true);
|
||||
exportModel.DiscountRate = item.DiscountRateIsPercent ? item.DiscountRate.OtcFormatPercent(4) : item.DiscountRate.OtcFormatMoney(true);
|
||||
exportModel.DiscountAccDown = item.DiscountAccDown.OtcFormatMoney(true);
|
||||
exportModel.FrontDeskCharge= item.FrontDeskChargeIsPercent==true ? item.FrontDeskCharge.OtcFormatTenThousandsPercent(4) : item.FrontDeskCharge.OtcFormatMoney(true);
|
||||
exportModel.FrontDeskCharge = item.FrontDeskChargeIsPercent == true ? item.FrontDeskCharge.OtcFormatTenThousandsPercent(4) : item.FrontDeskCharge.OtcFormatMoney(true);
|
||||
exportModel.BackDeskCharge = item.BackDeskChargeIsPercent == true ? item.BackDeskCharge.OtcFormatTenThousandsPercent(4) : item.BackDeskCharge.OtcFormatMoney(true);
|
||||
list.Add(exportModel);
|
||||
}
|
||||
@@ -363,11 +385,11 @@ namespace YLErp.Modules.SwapModule
|
||||
var posiNotionalValueGroup = DbContext.trade.Where(x => x.TradeDate >= monthStart
|
||||
&& x.ValidState != ConsGlobal.InValid
|
||||
&& x.TradeType == "收益互换"
|
||||
&& ConsTrade.TradeStatusCustomexport.Contains(x.TradeStatus)).ToList().GroupBy(x=>x.ClientId);
|
||||
&& ConsTrade.TradeStatusCustomexport.Contains(x.TradeStatus)).ToList().GroupBy(x => x.ClientId);
|
||||
foreach (var swapRate in swapRates)
|
||||
{
|
||||
var clientPosiNotional = posiNotionalValueGroup.FirstOrDefault(x=>x.Key== swapRate.ClientId).ToList().Sum(s=>s.OriginalStockEqvNotional??0);
|
||||
SendToKafka(swapRate, clientPosiNotional);
|
||||
var clientPosiNotional = posiNotionalValueGroup.FirstOrDefault(x => x.Key == swapRate.ClientId).ToList().Sum(s => s.OriginalStockEqvNotional ?? 0);
|
||||
SendToKafka(swapRate, clientPosiNotional);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
@@ -398,13 +420,13 @@ namespace YLErp.Modules.SwapModule
|
||||
swapRateKafkaModel.isRate = swapRate.BaseRateIsPercent;
|
||||
swapRateKafkaModel.rate = swapRate.BaseRate ?? 0;
|
||||
swapRateKafkaModel.disRateDown = swapRate.DiscountAccDown ?? 0;
|
||||
if (swapRate.DiscountAccDown.HasValue&&Convert.ToDecimal(clientPosiNotional)>= swapRateKafkaModel.disRateDown)
|
||||
if (swapRate.DiscountAccDown.HasValue && Convert.ToDecimal(clientPosiNotional) >= swapRateKafkaModel.disRateDown)
|
||||
{
|
||||
swapRateKafkaModel.isDisRate = swapRate.DiscountRateIsPercent;
|
||||
swapRateKafkaModel.disRate= swapRate.DiscountRate ?? 0;
|
||||
swapRateKafkaModel.disRate = swapRate.DiscountRate ?? 0;
|
||||
swapRateKafkaModel.rate = swapRateKafkaModel.disRate;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
kafkaProduceHelper.Produce(Environment.GetEnvironmentVariable("KafkaConfig_ClientRateTopic"), JsonConvert.SerializeObject(swapRateKafkaModel));
|
||||
}
|
||||
|
||||
@@ -1350,8 +1350,11 @@ namespace YLErp.Modules.SwapModule
|
||||
position.UnderlyingInstrumentType = swap.UnderlyingInstrumentType;
|
||||
position.PosiDirection = swap.PosiDirection;
|
||||
position.PosiGrossPrice = swap.PosiGrossPrice;
|
||||
position.PosiNetPrice = swap.PosiQuantity == 0 ? 0 : (swap.PosiGrossPrice + (position.PosiTradingFee / swap.PosiQuantity) * ratio);
|
||||
position.PosiNetPrice = swap.PosiQuantity == 0 ? 0 : (swap.PosiGrossPrice + (position.PosiTradingFeePending / swap.PosiQuantity) * ratio);
|
||||
position.PosiNetPrice = Math.Round(position.PosiNetPrice, ConsGlobal.PriceRound, MidpointRounding.AwayFromZero);
|
||||
position.PosiNetNoFeePrice = swap.PosiNetNoFeePrice;
|
||||
position.PosiNetFeePrice = swap.PosiQuantity == 0 ? 0 : (swap.PosiNetNoFeePrice + (position.PosiTradingFeePending / swap.PosiQuantity) * ratio);
|
||||
position.PosiNetFeePrice = Math.Round(position.PosiNetFeePrice??0, ConsGlobal.PriceRound, MidpointRounding.AwayFromZero);
|
||||
position.PosiNotionalValue = position.PosiGrossPrice * swap.PosiQuantity * swap.ContractSize;
|
||||
position.PosiQuantity = swap.PosiQuantity;
|
||||
position.InterestDirection = swap.InterestDirection;
|
||||
|
||||
Reference in New Issue
Block a user