wzy
2020-06-03 c356816bb9969fc5cde71b670461d9ddf7534e8f
src/main/java/com/xcong/excoin/modules/contract/service/impl/OrderWebsocketServiceImpl.java
@@ -30,12 +30,14 @@
import java.math.RoundingMode;
import java.util.*;
/**
 * @author helius
 */
@Service
public class OrderWebsocketServiceImpl {
    @Resource
    ContractHoldOrderService contractHoldOrderService;
    @Resource
    ContractOrderService contractOrderService;
@@ -43,10 +45,8 @@
    @Resource
    ContractEntrustOrderService contractEntrustOrderService;
    @Resource
    MemberWalletContractService memberWalletContractService;
    @Resource
    CacheSettingUtils cacheSettingUtils;
@@ -64,7 +64,6 @@
    private MemberAccountFlowEntityDao memberAccountFlowEntityDao;
    public void dealOrderFromMq(List<OrderModel> list, Integer type) {
        if (CollectionUtils.isNotEmpty(list)) {
            String batchno = UUID.randomUUID().toString();
@@ -80,19 +79,21 @@
                // 6在这里是爆仓 包括爆空和暴多
                switch (type) {
                    case 6:
                        this.dealCoinOut(coinsCoinsOrders,list);
                        this.dealCoinOut(coinsCoinsOrders, list);
                        break;
                    case 9:
                        this.dealForMoreStopPro(coinsCoinsOrders,list);
                        this.dealForMoreStopPro(coinsCoinsOrders, list);
                        break;
                    case 10:
                        this.dealForLessStopPro(coinsCoinsOrders,list);
                        this.dealForLessStopPro(coinsCoinsOrders, list);
                        break;
                    case 11:
                        this.dealForMoreLoss(coinsCoinsOrders,list);
                        this.dealForMoreLoss(coinsCoinsOrders, list);
                        break;
                    case 12:
                        this.dealForLessLoss(coinsCoinsOrders,list);
                        this.dealForLessLoss(coinsCoinsOrders, list);
                        break;
                    default:
                        break;
                }
@@ -102,15 +103,15 @@
        }
    }
    public void dealForLimitMq(List<OrderModel> list){
        if(CollectionUtils.isNotEmpty(list)){
    public void dealForLimitMq(List<OrderModel> list) {
        if (CollectionUtils.isNotEmpty(list)) {
            //查询限价委托的单
            String batchno =UUID.randomUUID().toString();
            String batchno = UUID.randomUUID().toString();
            List<Long> ids = new ArrayList<>();
            list.forEach(model->ids.add(model.getOrderId()));
            list.forEach(model -> ids.add(model.getOrderId()));
            List<ContractEntrustOrderEntity> contractEntrustOrderEntities = contractEntrustOrderService.selectEntrustOrderListByIds(ids);
            if(CollectionUtils.isNotEmpty(contractEntrustOrderEntities)){
            if (CollectionUtils.isNotEmpty(contractEntrustOrderEntities)) {
                this.dealLimitBuyOrder(contractEntrustOrderEntities);
            }
@@ -120,25 +121,25 @@
    /**
     * 开多止盈
     */
    public void dealForMoreStopPro(List<ContractHoldOrderEntity> orderList,List<OrderModel> list) {
    public void dealForMoreStopPro(List<ContractHoldOrderEntity> orderList, List<OrderModel> list) {
        if (CollectionUtils.isNotEmpty(orderList)) {
            Map<Long,BigDecimal> modelMap = new HashMap<Long,BigDecimal>();
            for(OrderModel model : list){
                modelMap.put(model.getOrderId(),new BigDecimal(model.getPrice()));
            Map<Long, BigDecimal> modelMap = new HashMap<Long, BigDecimal>();
            for (OrderModel model : list) {
                modelMap.put(model.getOrderId(), new BigDecimal(model.getPrice()));
            }
            for (ContractHoldOrderEntity order : orderList) {
                Long orderId = order.getId();
                System.out.println("开多止盈订单号:" + order.getOrderNo());
                System.out.println("传来的止盈价格:"+modelMap.get(order.getId()));
                System.out.println("传来的止盈价格:" + modelMap.get(order.getId()));
                if (null != order.getStopProfitPrice()) {
                    BigDecimal closePrice = order.getStopProfitPrice();
                    BigDecimal queuePrice = modelMap.get(order.getId());
                    System.out.println("订单的止盈价格:"+closePrice);
                    System.out.println("订单的止盈价格:" + closePrice);
                    // 判断 保留七位是为了忽略以为小数 防止不精确导致的不相等
                    if(queuePrice.compareTo(closePrice)!=0){
                    if (queuePrice.compareTo(closePrice) != 0) {
                        // 不能止盈
                        System.out.println("数据库价格:"+queuePrice.toPlainString()+"--价格不能止盈:"+closePrice);
                        System.out.println("数据库价格:" + queuePrice.toPlainString() + "--价格不能止盈:" + closePrice);
                        //更新数据
                        contractHoldOrderService.updateOrderIsCanClosingAndBatchNoById(orderId);
                        continue;
@@ -162,27 +163,27 @@
                        // 盈亏额度= (当前的币种的平仓价-下单时的建仓价)*购买的手数/规格*倍率
                        BigDecimal profitLossPrice = (closePrice
                                .subtract(order.getOpeningPrice()))
                                .multiply(new BigDecimal(currentFlat+""))
                                .multiply(new BigDecimal(currentFlat + ""))
                                .multiply(symbolSku).setScale(8, BigDecimal.ROUND_DOWN);
                        MemberEntity memberEntity = memberService.getById(memberId);
                        if(memberEntity.getIsProfit() == 1) {
                        if (memberEntity.getIsProfit() == 1) {
                            PlatformTradeSettingEntity tradeSetting = cacheSettingUtils.getTradeSetting();
                            if(profitLossPrice.compareTo(BigDecimal.ZERO)>0) {
                              profitLossPrice = profitLossPrice.multiply(BigDecimal.ONE.subtract(tradeSetting.getProfitParam()));
                            }else {
                            if (profitLossPrice.compareTo(BigDecimal.ZERO) > 0) {
                                profitLossPrice = profitLossPrice.multiply(BigDecimal.ONE.subtract(tradeSetting.getProfitParam()));
                            } else {
                                profitLossPrice = profitLossPrice.multiply(BigDecimal.ONE.add(tradeSetting.getProfitParam()));
                            }
                        }
                        //回报率
                        BigDecimal returnRate = profitLossPrice.divide((order.getPrePaymentAmount().subtract(contractOrderEntity.getClosingFeeAmount())), 8, BigDecimal.ROUND_DOWN);
                       contractOrderEntity.setRewardAmount(profitLossPrice);
                        contractOrderEntity.setRewardAmount(profitLossPrice);
                        contractOrderEntity.setRewardRatio(returnRate);
                        contractOrderEntity.setClosingFeeAmount(order.getOpeningFeeAmount());
                        contractOrderEntity.setClosingPrice(closePrice);
                        contractOrderEntity.setClosingType(6);
                        BigDecimal totalReturn = BigDecimal.ZERO;
                         contractOrderService.save(contractOrderEntity);
                        contractOrderService.save(contractOrderEntity);
                        // 将需要退回的减去手续费
                        BigDecimal needReturn = prePrice.add(profitLossPrice);
                        //总退回金额=保证金+收益-手续费
@@ -190,13 +191,13 @@
                        // 更新钱包
                        // 总的是收益-平仓手续费
                        BigDecimal totalBalance = profitLossPrice.subtract(contractOrderEntity.getClosingFeeAmount());
                        memberWalletContractService.increaseWalletContractBalanceById(totalBalance,totalReturn,null,wallet.getId());
                        memberWalletContractService.increaseWalletContractBalanceById(totalBalance, totalReturn, null, wallet.getId());
                        // 流水记录 TODO 531e
                        insertAccountFlow(order, wallet, profitLossPrice, "止盈平仓");
                        //返佣
                       calYj(order.getMemberId(), order.getOpeningFeeAmount(), contractOrderEntity, 2);
                        calYj(order.getMemberId(), order.getOpeningFeeAmount(), contractOrderEntity, 2);
                    }
                }
            }
@@ -207,34 +208,34 @@
    /**
     * 开空止盈
     */
    public void dealForLessStopPro(List<ContractHoldOrderEntity> orderList,List<OrderModel> list) {
    public void dealForLessStopPro(List<ContractHoldOrderEntity> orderList, List<OrderModel> list) {
        //List<CoinsCoinsOrder> orderList = orderMapper.selectOrderByBatchNo(batchno);
        //System.out.println("开空止盈订单batchno:" + batchno);
        if (CollectionUtils.isNotEmpty(orderList)) {
            Map<Long,BigDecimal> modelMap = new HashMap<Long,BigDecimal>();
            for(OrderModel model : list){
                modelMap.put(model.getOrderId(),new BigDecimal(model.getPrice()));
            Map<Long, BigDecimal> modelMap = new HashMap<Long, BigDecimal>();
            for (OrderModel model : list) {
                modelMap.put(model.getOrderId(), new BigDecimal(model.getPrice()));
            }
            for (ContractHoldOrderEntity order : orderList) {
                System.out.println("开空止盈订单号:" + order.getOrderNo());
                System.out.println("传来的止盈价格:"+modelMap.get(order.getId()).toPlainString());
                System.out.println("传来的止盈价格:" + modelMap.get(order.getId()).toPlainString());
                BigDecimal closePrice = order.getStopProfitPrice();
                Long orderId = order.getId();
                if (null != closePrice) {
                    // 止盈价
                    System.out.println("订单的止盈价格:"+closePrice);
                    System.out.println("订单的止盈价格:" + closePrice);
                    System.out.println(closePrice.compareTo(modelMap.get(order.getId())));
                    BigDecimal queuePrice = modelMap.get(order.getId()).setScale(7, RoundingMode.HALF_UP);
                    if(closePrice.compareTo(queuePrice)!=0){
                        System.out.println("数据库价格:"+queuePrice.toPlainString()+"--价格不能开空止盈:"+closePrice);
                    if (closePrice.compareTo(queuePrice) != 0) {
                        System.out.println("数据库价格:" + queuePrice.toPlainString() + "--价格不能开空止盈:" + closePrice);
                        contractHoldOrderService.updateOrderIsCanClosingAndBatchNoById(orderId);
                        continue;
                    }
                    System.out.println("执行操作");
                    String symbol = order.getSymbol();
                    // 本次需要退回的预付款
                    BigDecimal prePrice =order.getPrePaymentAmount();
                    BigDecimal prePrice = order.getPrePaymentAmount();
                    Long memberId = order.getMemberId();
                    MemberWalletContractEntity wallet = memberWalletContractService.findWalletContractByMemberIdAndSymbol(memberId, "USDT");
                    if (wallet != null) {
@@ -249,15 +250,15 @@
                        // 盈亏额度= (当前的币种的平仓价-下单时的建仓价)*购买的手数/规格*倍率
                        BigDecimal profitLossPrice = (order.getOpeningPrice()
                                .subtract(closePrice))
                                .multiply(new BigDecimal(currentFlat+""))
                                .multiply(new BigDecimal(currentFlat + ""))
                                .multiply(symbolSku).setScale(8, BigDecimal.ROUND_DOWN);
                        MemberEntity memberEntity = memberService.getById(memberId);
                        if(memberEntity.getIsProfit() == 1) {
                        if (memberEntity.getIsProfit() == 1) {
                            PlatformTradeSettingEntity tradeSetting = cacheSettingUtils.getTradeSetting();
                            if(profitLossPrice.compareTo(BigDecimal.ZERO)>0) {
                            if (profitLossPrice.compareTo(BigDecimal.ZERO) > 0) {
                                profitLossPrice = profitLossPrice.multiply(BigDecimal.ONE.subtract(tradeSetting.getProfitParam()));
                            }else {
                            } else {
                                profitLossPrice = profitLossPrice.multiply(BigDecimal.ONE.add(tradeSetting.getProfitParam()));
                            }
                        }
@@ -277,7 +278,7 @@
                        // 更新钱包
                        // 总的是收益-平仓手续费
                        BigDecimal totalBalance = profitLossPrice.subtract(contractOrderEntity.getClosingFeeAmount());
                        memberWalletContractService.increaseWalletContractBalanceById(totalBalance,totalReturn,null,wallet.getId());
                        memberWalletContractService.increaseWalletContractBalanceById(totalBalance, totalReturn, null, wallet.getId());
                        insertAccountFlow(order, wallet, profitLossPrice, "止盈平仓");
@@ -296,26 +297,26 @@
     *
     * @param
     */
    public void dealForMoreLoss(List<ContractHoldOrderEntity> orderList,List<OrderModel> list) {
    public void dealForMoreLoss(List<ContractHoldOrderEntity> orderList, List<OrderModel> list) {
        //List<CoinsCoinsOrder> orderList = orderMapper.selectOrderByBatchNo(batchno);
        //System.out.println("开多止损批次号batchno:" + batchno);
        if (CollectionUtils.isNotEmpty(orderList)) {
            Map<Long,BigDecimal> modelMap = new HashMap<Long,BigDecimal>();
            for(OrderModel model : list){
                modelMap.put(model.getOrderId(),new BigDecimal(model.getPrice()));
            Map<Long, BigDecimal> modelMap = new HashMap<Long, BigDecimal>();
            for (OrderModel model : list) {
                modelMap.put(model.getOrderId(), new BigDecimal(model.getPrice()));
            }
            for (ContractHoldOrderEntity order : orderList) {
                System.out.println("开多止损订单号:" + order.getOrderNo());
                Long orderId = order.getId();
                System.out.println("传来的止损价格:"+modelMap.get(orderId));
                System.out.println("传来的止损价格:" + modelMap.get(orderId));
                if (null != order.getStopLossPrice()) {
                    // 止损价
                    BigDecimal closePrice = order.getStopLossPrice();
                    System.out.println("订单止损价格:"+closePrice.toPlainString());
                    System.out.println("订单止损价格:" + closePrice.toPlainString());
                    BigDecimal queuePrice = modelMap.get(orderId);
                    if(closePrice.compareTo(queuePrice)!=0){
                        System.out.println("数据库价格:"+queuePrice.toPlainString()+"--价格不能开多止损:"+closePrice);
                    if (closePrice.compareTo(queuePrice) != 0) {
                        System.out.println("数据库价格:" + queuePrice.toPlainString() + "--价格不能开多止损:" + closePrice);
                        contractHoldOrderService.updateOrderIsCanClosingAndBatchNoById(orderId);
                        continue;
                    }
@@ -323,7 +324,7 @@
                    String symbol = order.getSymbol();
                    Long memberId = order.getMemberId();
                    // 本次需要退回的预付款
                    BigDecimal prePrice =order.getPrePaymentAmount();
                    BigDecimal prePrice = order.getPrePaymentAmount();
                    MemberWalletContractEntity wallet = memberWalletContractService.findWalletContractByMemberIdAndSymbol(memberId, "USDT");
                    if (wallet != null) {
@@ -338,15 +339,15 @@
                        // 盈亏额度= (当前的币种的平仓价-下单时的建仓价)*购买的手数/规格*倍率
                        BigDecimal profitLossPrice = (closePrice
                                .subtract(order.getOpeningPrice()))
                                .multiply(new BigDecimal(currentFlat+""))
                                .multiply(new BigDecimal(currentFlat + ""))
                                .multiply(symbolSku).setScale(8, BigDecimal.ROUND_DOWN);
                        MemberEntity memberEntity = memberService.getById(memberId);
                        if(memberEntity.getIsProfit() == 1) {
                        if (memberEntity.getIsProfit() == 1) {
                            PlatformTradeSettingEntity tradeSetting = cacheSettingUtils.getTradeSetting();
                            if(profitLossPrice.compareTo(BigDecimal.ZERO)>0) {
                            if (profitLossPrice.compareTo(BigDecimal.ZERO) > 0) {
                                profitLossPrice = profitLossPrice.multiply(BigDecimal.ONE.subtract(tradeSetting.getProfitParam()));
                            }else {
                            } else {
                                profitLossPrice = profitLossPrice.multiply(BigDecimal.ONE.add(tradeSetting.getProfitParam()));
                            }
                        }
@@ -366,7 +367,7 @@
                        // 更新钱包
                        // 总的是收益-平仓手续费
                        BigDecimal totalBalance = profitLossPrice.subtract(contractOrderEntity.getClosingFeeAmount());
                        memberWalletContractService.increaseWalletContractBalanceById(totalBalance,totalReturn,null,wallet.getId());
                        memberWalletContractService.increaseWalletContractBalanceById(totalBalance, totalReturn, null, wallet.getId());
                        insertAccountFlow(order, wallet, profitLossPrice, "开多止损平仓");
@@ -383,26 +384,26 @@
     *
     * @param
     */
    public void dealForLessLoss(List<ContractHoldOrderEntity> orderList,List<OrderModel> list) {
    public void dealForLessLoss(List<ContractHoldOrderEntity> orderList, List<OrderModel> list) {
        // List<CoinsCoinsOrder> orderList = orderMapper.selectOrderByBatchNo(batchno);
        //System.out.println("开空止损批次号batchno:" + batchno);
        if (CollectionUtils.isNotEmpty(orderList)) {
            Map<Long,BigDecimal> modelMap = new HashMap<Long,BigDecimal>();
            for(OrderModel model : list){
                modelMap.put(model.getOrderId(),new BigDecimal(model.getPrice()));
            Map<Long, BigDecimal> modelMap = new HashMap<Long, BigDecimal>();
            for (OrderModel model : list) {
                modelMap.put(model.getOrderId(), new BigDecimal(model.getPrice()));
            }
            for (ContractHoldOrderEntity order : orderList) {
                Long orderId = order.getId();
                System.out.println("传来的止损价格:"+modelMap.get(orderId).toPlainString());
                System.out.println("传来的止损价格:" + modelMap.get(orderId).toPlainString());
                System.out.println("开空止损订单号:" + order.getOrderNo());
                if (null != order.getStopLossPrice()) {
                    // 止损价
                    BigDecimal closePrice = order.getStopLossPrice();
                    System.out.println("订单止损价格:"+closePrice.toPlainString());
                    System.out.println("订单止损价格:" + closePrice.toPlainString());
                    BigDecimal queuePrice = modelMap.get(orderId);
                    if(closePrice.compareTo(queuePrice)!=0){
                        System.out.println("数据库价格:"+queuePrice.toPlainString()+"--价格不能开空止损:"+closePrice);
                    if (closePrice.compareTo(queuePrice) != 0) {
                        System.out.println("数据库价格:" + queuePrice.toPlainString() + "--价格不能开空止损:" + closePrice);
                        contractHoldOrderService.updateOrderIsCanClosingAndBatchNoById(orderId);
                        continue;
                    }
@@ -410,7 +411,7 @@
                    String symbol = order.getSymbol();
                    Long memberId = order.getMemberId();
                    // 本次需要退回的预付款
                    BigDecimal prePrice =order.getPrePaymentAmount();
                    BigDecimal prePrice = order.getPrePaymentAmount();
                    MemberWalletContractEntity wallet = memberWalletContractService.findWalletContractByMemberIdAndSymbol(memberId, "USDT");
                    if (wallet != null) {
@@ -425,15 +426,15 @@
                        // 盈亏额度= (当前的币种的平仓价-下单时的建仓价)*购买的手数/规格*倍率
                        BigDecimal profitLossPrice = (order.getOpeningPrice()
                                .subtract(closePrice))
                                .multiply(new BigDecimal(currentFlat+""))
                                .multiply(new BigDecimal(currentFlat + ""))
                                .multiply(symbolSku).setScale(8, BigDecimal.ROUND_DOWN);
                        MemberEntity memberEntity = memberService.getById(memberId);
                        if(memberEntity.getIsProfit() == 1) {
                        if (memberEntity.getIsProfit() == 1) {
                            PlatformTradeSettingEntity tradeSetting = cacheSettingUtils.getTradeSetting();
                            if(profitLossPrice.compareTo(BigDecimal.ZERO)>0) {
                            if (profitLossPrice.compareTo(BigDecimal.ZERO) > 0) {
                                profitLossPrice = profitLossPrice.multiply(BigDecimal.ONE.subtract(tradeSetting.getProfitParam()));
                            }else {
                            } else {
                                profitLossPrice = profitLossPrice.multiply(BigDecimal.ONE.add(tradeSetting.getProfitParam()));
                            }
                        }
@@ -453,7 +454,7 @@
                        // 更新钱包
                        // 总的是收益-平仓手续费
                        BigDecimal totalBalance = profitLossPrice.subtract(contractOrderEntity.getClosingFeeAmount());
                        memberWalletContractService.increaseWalletContractBalanceById(totalBalance,totalReturn,null,wallet.getId());
                        memberWalletContractService.increaseWalletContractBalanceById(totalBalance, totalReturn, null, wallet.getId());
                        insertAccountFlow(order, wallet, profitLossPrice, "开空止损平仓");
@@ -488,7 +489,7 @@
        //List<CoinsCoinsOrder> orderList = orderMapper.selectOrderByBatchNo(batchno);
        if (CollectionUtils.isNotEmpty(orderList)) {
            ContractHoldOrderEntity contractHoldOrderEntity=null;
            ContractHoldOrderEntity contractHoldOrderEntity = null;
            for (ContractEntrustOrderEntity coinsCoinsOrder : orderList) {
                MemberWalletContractEntity wallet = memberWalletContractService.findWalletContractByMemberIdAndSymbol(coinsCoinsOrder.getMemberId(), "USDT");
                if (wallet == null) {
@@ -502,7 +503,7 @@
                int symbolCnt = coinsCoinsOrder.getSymbolCnt();
                int type = coinsCoinsOrder.getEntrustType();
                //开仓价
               // Double openPrice = coinsCoinsOrder.getOpenPrice().doubleValue();
                // Double openPrice = coinsCoinsOrder.getOpenPrice().doubleValue();
                //委托价
                // Double markPrice = coinsCoinsOrder.getMarkPrice();
                if (type == 1) {
@@ -528,7 +529,7 @@
                        .setScale(8, BigDecimal.ROUND_DOWN);
                contractHoldOrderEntity.setOpeningFeeAmount(openFeePrice);
                contractHoldOrderEntity.setVersion(1);
                BigDecimal forceSetPrice = CalculateUtil.getForceSetPrice(coinsCoinsOrder.getBondAmount(), entrustPrice, symbolCnt, lotNumber, type, memberEntity);
                BigDecimal forceSetPrice = CalculateUtil.getForceSetPrice(coinsCoinsOrder.getBondAmount().subtract(openFeePrice), entrustPrice, symbolCnt, lotNumber, type, memberEntity);
                contractHoldOrderEntity.setForceClosingPrice(forceSetPrice);
                contractHoldOrderEntity.setLeverRatio(coinsCoinsOrder.getLeverRatio());
@@ -543,24 +544,24 @@
                // 市价
                if (coinsCoinsOrder.getEntrustType() == 1) {
                    // 开多
                    OrderModel model = new OrderModel(contractHoldOrderEntity.getId(), 6, contractHoldOrderEntity.getForceClosingPrice().toPlainString(), coinsCoinsOrder.getSymbol(),1);
                    OrderModel model = new OrderModel(contractHoldOrderEntity.getId(), 6, contractHoldOrderEntity.getForceClosingPrice().setScale(8, RoundingMode.HALF_UP).toPlainString(), coinsCoinsOrder.getSymbol(), 1);
                    producer.sendPriceOperate(JSONObject.toJSONString(model));
                } else {
                    // 开空
                    OrderModel model = new OrderModel(contractHoldOrderEntity.getId(), 7, contractHoldOrderEntity.getForceClosingPrice().toPlainString(), coinsCoinsOrder.getSymbol(),1);
                    OrderModel model = new OrderModel(contractHoldOrderEntity.getId(), 7, contractHoldOrderEntity.getForceClosingPrice().setScale(8, RoundingMode.HALF_UP).toPlainString(), coinsCoinsOrder.getSymbol(), 1);
                    producer.sendPriceOperate(JSONObject.toJSONString(model));
                }
                // 扣除手续费
                //double totalBalance = wallet.getTotalBalance() - coinsCoinsOrder.getClosingPrice();
                BigDecimal totalBalance =  openFeePrice.negate();
                BigDecimal totalBalance = openFeePrice.negate();
               /** TradeSetting tradeSetting = tradeSettingCache.getTradeSetting();
                /** TradeSetting tradeSetting = tradeSettingCache.getTradeSetting();
                Double totalPayPrice = new BigDecimal(coinsCoinsOrder.getPrePrice()).add(new BigDecimal(coinsCoinsOrder.getClosingPrice())).add(new BigDecimal(coinsCoinsOrder.getClosingPrice()))
                        .setScale(8, BigDecimal.ROUND_HALF_UP).doubleValue();
                totalBalance =  totalBalance+(-totalPayPrice*(Double.valueOf(tradeSetting.getSpread())/10000));*/
                 Double totalPayPrice = new BigDecimal(coinsCoinsOrder.getPrePrice()).add(new BigDecimal(coinsCoinsOrder.getClosingPrice())).add(new BigDecimal(coinsCoinsOrder.getClosingPrice()))
                 .setScale(8, BigDecimal.ROUND_HALF_UP).doubleValue();
                 totalBalance =  totalBalance+(-totalPayPrice*(Double.valueOf(tradeSetting.getSpread())/10000));*/
                memberWalletContractService.increaseWalletContractBalanceById(null,totalBalance,null,wallet.getId());
                memberWalletContractService.increaseWalletContractBalanceById(null, totalBalance, null, wallet.getId());
                // TODO 531 待写
                calYj(memId, contractOrderEntity.getClosingFeeAmount(), contractOrderEntity, 1);
            }
@@ -572,21 +573,21 @@
     *
     * @param
     */
    public void dealCoinOut(List<ContractHoldOrderEntity> orderList,List<OrderModel> orderModels) {
    public void dealCoinOut(List<ContractHoldOrderEntity> orderList, List<OrderModel> orderModels) {
        // 需要比较查询到的和消息发来的单的爆仓操作次序号是否相同
        // 构建map
        if (CollectionUtils.isNotEmpty(orderList)) {
            Map<Long,Integer> modelMap = new HashMap<Long,Integer>();
            for(OrderModel model : orderModels){
                modelMap.put(model.getOrderId(),model.getOperateNo());
            Map<Long, Integer> modelMap = new HashMap<Long, Integer>();
            for (OrderModel model : orderModels) {
                modelMap.put(model.getOrderId(), model.getOperateNo());
            }
           // TradeSetting tradeSetting = tradeMapper.findTradeSetting();
            // TradeSetting tradeSetting = tradeMapper.findTradeSetting();
            for (ContractHoldOrderEntity coinsOrder : orderList) {
                Long orderId = coinsOrder.getId();
                Integer operateNo = coinsOrder.getOperateNo();
                //判断当前订单是否是最新的爆仓价 不相等时直接进入下一个订单
                if(!modelMap.get(orderId).equals(operateNo)){
                if (!modelMap.get(orderId).equals(operateNo)) {
                    // 将订单更新为可平仓并删除批次号
                    contractHoldOrderService.updateOrderIsCanClosingAndBatchNoById(orderId);
                    continue;
@@ -638,11 +639,11 @@
                    //更新用户钱包数据
                    MemberWalletContractEntity usdt = memberWalletContractService.findWalletContractByMemberIdAndSymbol(memId, "USDT");
                   // Double totalPrice = wallet.getTotalBalance() - coinsOrder.getPrePrice();
                    // Double totalPrice = wallet.getTotalBalance() - coinsOrder.getPrePrice();
                    // 减去的时候用负数
                    BigDecimal totalPrice = coinsOrder.getPrePaymentAmount().negate();
                    //Double totalPrice = - coinsOrder.getPrePrice();
                    memberWalletContractService.increaseWalletContractBalanceById(null,totalPrice,null,usdt.getId());
                    memberWalletContractService.increaseWalletContractBalanceById(null, totalPrice, null, usdt.getId());
                    // 流水记录 TODO
                    MemberAccountFlowEntity record = new MemberAccountFlowEntity();
                    record.setCreateTime(new Date());
@@ -653,8 +654,6 @@
                    record.setSymbol(coinsOrder.getSymbol());
                    record.setPrice(coinsOrder.getPrePaymentAmount());
                    memberAccountFlowEntityDao.insert(record);
                }
            }
        }
@@ -662,9 +661,9 @@
    public void calYj(Long mid, BigDecimal money, ContractOrderEntity order, int type) {
       if(money!=null) {
          money = money.multiply(new BigDecimal(0.7868));
       }
        if (money != null) {
            money = money.multiply(new BigDecimal(0.7868));
        }
        MemberEntity member = memberService.getById(mid);
        String[] referenceIds = member.getRefererIds().split(",");
        List<String> ids = Arrays.asList(referenceIds);