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); + } + } /// /// 加权平均处理当前有持仓,切两个方向多条流水情况 ///