From 1684bae60dfeafe0f403a95fcef1d54ce1f89845 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=96=B9=E6=B5=B7?= Date: Fri, 21 Jun 2024 13:45:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B1=B1=E8=AF=81bug=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RealTimeClientBanlanceService.cs | 14 +++---- .../PayoffSwapCalcService.cs | 4 +- .../SettlementModule/EodClientBalanceCalc.cs | 6 +-- .../Modules/RiskModule/QuotaMonitorService.cs | 2 +- .../Scripts/app/swaptrade/SwapflowList.js | 38 ++++++++++++++----- .../Scripts/app/trade/TradeConfirmBook.js | 14 +++++++ 6 files changed, 55 insertions(+), 23 deletions(-) diff --git a/YLErpDAL/BLL/EodSettlement/RealTimeClientBanlanceService.cs b/YLErpDAL/BLL/EodSettlement/RealTimeClientBanlanceService.cs index 420b0d81..c4d1d0e7 100644 --- a/YLErpDAL/BLL/EodSettlement/RealTimeClientBanlanceService.cs +++ b/YLErpDAL/BLL/EodSettlement/RealTimeClientBanlanceService.cs @@ -1401,9 +1401,9 @@ namespace YLErp.BLL.Eod var clientEodSwaps = data.GroupBy(g => g.SwapTradeId).ToList(); foreach (var item in clientEodSwaps) { - var eodSwapList= item.OrderBy(o => o.ValueDate).ToList(); - var eodSwap = eodSwapList[eodSwapList.Count-1]; - var lastEodSwap= eodSwapList.Count<=1?null: eodSwapList[eodSwapList.Count - 2]; + var eodSwapList = item.OrderBy(o => o.ValueDate).ToList(); + var eodSwap = eodSwapList[eodSwapList.Count - 1]; + var lastEodSwap = eodSwapList.Count <= 1 ? null : eodSwapList[eodSwapList.Count - 2]; //潜在行权收益等于实值额 balance.PotentialSurpluses += -Convert.ToDouble(eodSwap.PostionValue); //持仓市值 @@ -1411,17 +1411,17 @@ namespace YLErp.BLL.Eod balance.RoundedPositionPv += Math.Round(Convert.ToDouble(eodSwap.PostionValue), 2); balance.SellPv += -Convert.ToDouble(eodSwap.MarketValueShort); //持仓盈亏 - var pnl = eodSwap.FloatingPnL + eodSwap.InterestPnL; - var lastPnl = lastEodSwap?.FloatingPnL??0 + lastEodSwap?.InterestPnL??0; + var pnl = eodSwap.PostionValue; + var lastPnl = lastEodSwap?.PostionValue; //当日盈亏 if (eodSwap.ValueDate == startDate) { - balance.DaliyPnl += Convert.ToDouble(pnl- lastPnl+ eodSwap.TdRealizedPnL); + balance.DaliyPnl += Convert.ToDouble(pnl - lastPnl + eodSwap.TdRealizedPnL); balance.RoundedDaliyPnl += Math.Round(Convert.ToDouble(pnl - lastPnl), 2); balance.UpdateDate = balance.UpdateDate > eodSwap.OptTime ? balance.UpdateDate : eodSwap.OptTime; } balance.WinLoss += Convert.ToDouble(eodSwap.TdRealizedPnL); - + balance.PositionPnl += Convert.ToDouble(pnl); balance.RoundedPositionPnl += Math.Round(Convert.ToDouble(pnl), 2); //期权空头浮动盈利=∑max(期权空头持仓*(期权合约成本价-期权合约现价), 0) 从客户角度看的 diff --git a/YLErpDAL/Modules/CalculationModule/PayoffSwapCalcService.cs b/YLErpDAL/Modules/CalculationModule/PayoffSwapCalcService.cs index 8dad5329..c75bb494 100644 --- a/YLErpDAL/Modules/CalculationModule/PayoffSwapCalcService.cs +++ b/YLErpDAL/Modules/CalculationModule/PayoffSwapCalcService.cs @@ -157,7 +157,7 @@ namespace YLErp.Modules.CalculationModule eodSwap.NotionalValueLong = positions.Where(x => x.PositionType == (int)PositionTypeFlag.Long).Sum(s => s.PosiNotionalValue); eodSwap.NotionalValueShort = positions.Where(x => x.PositionType == (int)PositionTypeFlag.Short).Sum(s => s.PosiNotionalValue); eodSwap.NotionalValue = eodSwap.NotionalValueLong + eodSwap.NotionalValueShort; - var lastEod = db.eod_swap.Where(x => x.SwapTradeId == trade.id).OrderByDescending(o => o.ValueDate).FirstOrDefault(); + var lastEod = db.eod_swap.Where(x => x.SwapTradeId == trade.id && x.ValueDate <= valuedateBLL.ValueDate).OrderByDescending(o => o.ValueDate).FirstOrDefault(); eodSwap.RealizedPnL = lastEod?.RealizedPnL ?? 0; eodSwap.InterestPnL = lastEod?.InterestPnL ?? 0; foreach (var item in positions) @@ -186,7 +186,7 @@ namespace YLErp.Modules.CalculationModule } eodSwap.NotionalValue += pvNoPrice; } - eodSwap.PostionValue = eodSwap.InterestPnL + eodSwap.FloatingPnL; + eodSwap.PostionValue = lastEod?.PostionValue ?? 0; return eodSwap; } diff --git a/YLErpDAL/Modules/EodModule/SettlementModule/EodClientBalanceCalc.cs b/YLErpDAL/Modules/EodModule/SettlementModule/EodClientBalanceCalc.cs index 14815698..aff6b5a2 100644 --- a/YLErpDAL/Modules/EodModule/SettlementModule/EodClientBalanceCalc.cs +++ b/YLErpDAL/Modules/EodModule/SettlementModule/EodClientBalanceCalc.cs @@ -903,7 +903,7 @@ namespace YLErp.Modules.EodModule.SettlementModule WinLoss += Convert.ToDouble(item.TdRealizedPnL) * (-1); var lastPv = lastEodSwap != null ? Convert.ToDouble(lastEodSwap.PostionValue) * (-1) : 0; eodPnlSum.LastPvSum = eodPnlSum.LastPvSum.HasValue ? eodPnlSum.LastPvSum + lastPv : lastPv; - var pnl = item.FloatingPnL + item.InterestPnL; + var pnl = item.PostionValue; eodPnlSum.PvSum = eodPnlSum.PvSum.HasValue ? eodPnlSum.PvSum - Convert.ToDouble(item.PostionValue) : Convert.ToDouble(item.PostionValue) * (-1); eodPnlSum.SellPvSum = eodPnlSum.SellPvSum.HasValue ? eodPnlSum.SellPvSum - Convert.ToDouble(item.MarketValueShort) : Convert.ToDouble(item.MarketValueShort) * (-1); eodPnlSum.RoundedPvSum = eodPnlSum.RoundedPvSum.HasValue ? eodPnlSum.RoundedPvSum - Math.Round(Convert.ToDouble(item.PostionValue), 2) : Math.Round(Convert.ToDouble(item.PostionValue), 2) * (-1); @@ -912,8 +912,8 @@ namespace YLErp.Modules.EodModule.SettlementModule RoundedPositionPnl += Math.Round(Convert.ToDouble(pnl), 2) * (-1); TotalPnl += Convert.ToDouble(item.RealizedPnL) * (-1); ClientSellPositionPnl += Math.Max(-Convert.ToDouble(item.MarketValueShort), 0); - var lastPnl = lastEodSwap != null ? lastEodSwap.FloatingPnL + lastEodSwap.InterestPnL : 0; - DailyPnl += Convert.ToDouble(pnl - lastPnl+item.TdRealizedPnL) * (-1); + var lastPnl = lastEodSwap != null ? lastEodSwap.PostionValue : 0; + DailyPnl += Convert.ToDouble(pnl - lastPnl + item.TdRealizedPnL) * (-1); //PayableMargin += Convert.ToDouble(item.InitMarginLoss + item.InitMarginGain+ item.PostionMarginLoss + item.PostionMarginGain); } var clientmarignQuery = marignQuery.Where(x => x.ClientId == client.id&&x.StructureType!="多空组合"); diff --git a/YLErpDAL/Modules/RiskModule/QuotaMonitorService.cs b/YLErpDAL/Modules/RiskModule/QuotaMonitorService.cs index e87ba2db..c0cb89a1 100644 --- a/YLErpDAL/Modules/RiskModule/QuotaMonitorService.cs +++ b/YLErpDAL/Modules/RiskModule/QuotaMonitorService.cs @@ -5056,7 +5056,7 @@ namespace YLErp.Modules.RiskModule lastPrice = bondPrice != null ? bondPrice.ClosePrice : (um.Price ?? 0) * Convert.ToDouble(ConsGlobal.bondPriceMultiple); } } - currentValue += lastPrice * Math.Abs(item.Position) - Math.Abs(item.PositionCost); + currentValue += lastPrice * item.Position - item.PositionCost; } return currentValue; } diff --git a/YLErpWeb/wwwroot/Scripts/app/swaptrade/SwapflowList.js b/YLErpWeb/wwwroot/Scripts/app/swaptrade/SwapflowList.js index 3ae3ed69..339a1f60 100644 --- a/YLErpWeb/wwwroot/Scripts/app/swaptrade/SwapflowList.js +++ b/YLErpWeb/wwwroot/Scripts/app/swaptrade/SwapflowList.js @@ -17,6 +17,7 @@ function CombookingHub() { // 创建SignalR连接并连接到服务器上的Hub var bookconnection = new signalR.HubConnectionBuilder() .withUrl('/swapflow/combookinghub') + .withAutomaticReconnect() .build(); bookconnection.start() .then(function () { @@ -51,17 +52,26 @@ function CombookingHub() { $('#msg').text(msg); getList(); }); - // 监听连接关闭,启动启动重连 - bookconnection.Closed += async (error) => { - await Task.Delay(3 * 1000); - await bookconnection.StartAsync(); - }; + // 监听连接关闭,启动重连 + bookconnection.onclose(async (error) => { + console.log("连接断开"); + // 等待3秒后尝试重新连接 + setTimeout(async () => { + try { + await bookconnection.start(); + console.log("已重新连接"); + } catch (err) { + console.error("重新连接失败: ", err); + } + }, 3000); // 3秒 + }); } // 流水重置交互 function ResetHub() { // 创建SignalR连接并连接到服务器上的Hub var connection = new signalR.HubConnectionBuilder() .withUrl('/swapflow/resethub') + .withAutomaticReconnect() .build(); connection.start() .then(function () { @@ -99,11 +109,19 @@ function ResetHub() { layer.close(progressBar); getList(); }); - // 监听连接关闭,启动启动重连 - connection.Closed += async (error) => { - await Task.Delay(3 * 1000); - await connection.StartAsync(); - }; + // 监听连接关闭,启动重连 + connection.onclose(async (error) => { + console.log("连接断开"); + // 等待3秒后尝试重新连接 + setTimeout(async () => { + try { + await connection.start(); + console.log("已重新连接"); + } catch (err) { + console.error("重新连接失败: ", err); + } + }, 3000); // 3秒 + }); } //标的选择组件 const vueUnderlying = function () { diff --git a/YLErpWeb/wwwroot/Scripts/app/trade/TradeConfirmBook.js b/YLErpWeb/wwwroot/Scripts/app/trade/TradeConfirmBook.js index 1aecfe40..2674908f 100644 --- a/YLErpWeb/wwwroot/Scripts/app/trade/TradeConfirmBook.js +++ b/YLErpWeb/wwwroot/Scripts/app/trade/TradeConfirmBook.js @@ -1128,6 +1128,7 @@ function SendEmailHub() { // 创建SignalR连接并连接到服务器上的Hub var connection = new signalR.HubConnectionBuilder() .withUrl('/tradeconfirm/sendemailhub') + .withAutomaticReconnect() .build(); connection.start() .then(function () { @@ -1167,4 +1168,17 @@ function SendEmailHub() { main.waitMe(false); SearchClick(true); }); + // 监听连接关闭,启动重连 + connection.onclose(async (error) => { + console.log("连接断开"); + // 等待3秒后尝试重新连接 + setTimeout(async () => { + try { + await connection.start(); + console.log("已重新连接"); + } catch (err) { + console.error("重新连接失败: ", err); + } + }, 3000); // 3秒 + }); } \ No newline at end of file