| | |
| | | import com.nq.vo.position.UserPositionVO; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | |
| | | /** |
| | | * 仓位计算工具类 |
| | |
| | | return userPositionVO; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 返回当前 仓位表 实时数据 |
| | | * */ |
| | | public static UserPositionVO assembleUserPositionVO2(UserPositionVO userPositionVO,BigDecimal nowPrice) { |
| | | PositionProfitVO positionProfitVO = getPositionProfitVO2(userPositionVO, nowPrice); |
| | | BigDecimal ss = positionProfitVO.getProfitAndLose().divide(userPositionVO.getOrderTotalPrice(), RoundingMode.CEILING) |
| | | .multiply(new BigDecimal(100)); |
| | | ss = ss.setScale(2, RoundingMode.DOWN); |
| | | userPositionVO.setProfitAndLoseParent(ss+"%"); |
| | | userPositionVO.setProfitAndLoseParent2(ss); |
| | | userPositionVO.setProfitAndLose(positionProfitVO.getProfitAndLose()); |
| | | userPositionVO.setAllProfitAndLose(positionProfitVO.getAllProfitAndLose()); |
| | | if(StringUtil.isEmpty(userPositionVO.getSellOrderId())){ |
| | | userPositionVO.setNow_price(nowPrice.toString()); |
| | | }else{ |
| | | userPositionVO.setNow_price(userPositionVO.getSellOrderPrice().toString()); |
| | | } |
| | | userPositionVO.setAmountToBeCovered(userPositionVO.getAmountToBeCovered()); |
| | | return userPositionVO; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 计算仓位盈亏计算方法 |
| | | * */ |
| | |
| | | positionProfitVO.setNowPrice(nowPrice.setScale(5,BigDecimal.ROUND_UP).toString()); |
| | | return positionProfitVO; |
| | | } |
| | | |
| | | /** |
| | | * 计算仓位盈亏计算方法 |
| | | * */ |
| | | public static PositionProfitVO getPositionProfitVO2(UserPositionVO position,BigDecimal nowPrice) { |
| | | BigDecimal profitAndLose = new BigDecimal("0"); |
| | | BigDecimal allProfitAndLose = new BigDecimal("0"); |
| | | |
| | | if (position.getSellOrderId() != null) { |
| | | |
| | | BigDecimal subPrice = position.getSellOrderPrice().subtract(position.getBuyOrderPrice()); |
| | | profitAndLose = subPrice.multiply(new BigDecimal(position.getOrderNum().intValue())); |
| | | if ("买跌".equals(position.getOrderDirection())) { |
| | | profitAndLose = profitAndLose.negate(); |
| | | } |
| | | allProfitAndLose = profitAndLose.subtract(position.getOrderSpread()).subtract(position.getOrderStayFee()).subtract(position.getSpreadRatePrice()); |
| | | } else { |
| | | BigDecimal subPrice = nowPrice.subtract(position.getBuyOrderPrice()); |
| | | profitAndLose = subPrice.multiply(new BigDecimal(position.getOrderNum().intValue())); |
| | | if ("买跌".equals(position.getOrderDirection())) { |
| | | profitAndLose = profitAndLose.negate(); |
| | | } |
| | | //总盈亏= 浮动盈亏 – 手续费 – 印花税 – 留仓费 – 点差费 |
| | | allProfitAndLose = profitAndLose.subtract(position.getOrderSpread()).subtract(position.getOrderStayFee()).subtract(position.getSpreadRatePrice()); |
| | | } |
| | | PositionProfitVO positionProfitVO = new PositionProfitVO(); |
| | | positionProfitVO.setProfitAndLose(profitAndLose); |
| | | positionProfitVO.setAllProfitAndLose(allProfitAndLose); |
| | | positionProfitVO.setNowPrice(nowPrice.setScale(5,BigDecimal.ROUND_UP).toString()); |
| | | return positionProfitVO; |
| | | } |
| | | } |