From 4e165a4c131350a3b4356476346f6b809272155a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=96=B9=E6=B5=B7?= Date: Thu, 13 Jun 2024 13:20:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=88=E8=BF=9B=E5=85=88=E5=87=BAbug?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SwapModule/SwapTradeAutoService.cs | 41 +++++++++++++++++-- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/YLErpDAL/Modules/SwapModule/SwapTradeAutoService.cs b/YLErpDAL/Modules/SwapModule/SwapTradeAutoService.cs index 49689822..3be05eb7 100644 --- a/YLErpDAL/Modules/SwapModule/SwapTradeAutoService.cs +++ b/YLErpDAL/Modules/SwapModule/SwapTradeAutoService.cs @@ -905,10 +905,9 @@ namespace YLErp.Modules.SwapModule string clearingAgency) { var firstFlow = flowList.First(); - var negativeFlow = flowList.Where(x => x.BsType != firstFlow.BsType).FirstOrDefault(); - if (negativeFlow==null)//只有同向流水情况 + if (flowList.Count==1)//只有一条流水情况 { - NewSwapTrade(firstFlow, client, asset, underlying, floatRate, clientMarginTemplate, clearingAgency); + AvgDealSingleFlow(firstFlow, clientSwapPositionList, clientSwapTrades, client, asset, underlying, floatRate, clientMarginTemplate, clearingAgency); } else { @@ -1049,7 +1048,43 @@ namespace YLErp.Modules.SwapModule swapTradeService.NewSwapTrade(flowMergeLastClone, client, asset, underlying, floatRate, clientMarginTemplate, clearingAgency); } } + /// + /// 加权平均处理当前有持仓,切两个方向多条流水情况 + /// + /// + /// + /// + /// + /// + /// + /// + /// + public void AvgDealSingleFlow(swap_flow_merge flow, + List clientSwapPositionList, + List clientSwapTrades, + Client client, + AssetUnit asset, + underlying_manager underlying, + SwapFloatRate floatRate, + client_marginrate clientMarginTemplate, + string clearingAgency) + { + var swapTradeService = new SwapTradeService(UserInfo); + var firstPosi = clientSwapPositionList.First(); + var swapPositions = clientSwapPositionList.Where(x => x.PositionType == firstPosi.PositionType).ToList(); + var posiQty = swapPositions.Sum(s => s.PosiQuantity); + var flowClone = DataHelper.DeepCopyObject(flow); + // 同向新开 + if (flow.BsType== firstPosi.PositionType) + { + NewSwapTrade(flowClone, client, asset, underlying, floatRate, clientMarginTemplate, clearingAgency); + } + else //反向先平仓,有剩余开仓 + { + AvgDealUnwind(flowClone, clientSwapTrades, swapPositions, client, asset, underlying, floatRate, clientMarginTemplate, clearingAgency); + } + } /// /// 加权平均处理当前有持仓,切两个方向多条流水情况 ///