| | |
| | | |
| | | Wallet wallet = walletService.findByUserId(order.getPartyId()); |
| | | if (wallet.getMoney().add(profit).compareTo(BigDecimal.ZERO) < 0) { |
| | | // 如果结果是负数,就归零 |
| | | /*// 如果结果是负数,就归零 |
| | | if (wallet.getMoney().compareTo(BigDecimal.ZERO) < 0) { |
| | | profit = BigDecimal.ZERO; |
| | | } |
| | | }*/ |
| | | profit = wallet.getMoney().negate(); |
| | | } |
| | | |
| | | walletService.updateMoney(order.getSymbol(), partyId, profit, BigDecimal.ZERO, |
| | |
| | | * 合约产品平仓后添加当前流水setWithdraw_limit_now_amount |
| | | */ |
| | | User party = userService.getById(order.getPartyId()); |
| | | if (party.getWithdrawLimitNowAmount() == null) { |
| | | party.setWithdrawLimitNowAmount(BigDecimal.ZERO); |
| | | } |
| | | party.setWithdrawLimitNowAmount(party.getWithdrawLimitNowAmount().add(order.getDepositOpen())); |
| | | userService.updateById(party); |
| | | if (ObjectUtils.isEmpty(order.getCloseAvgPrice())) { |
| | |
| | | * 计算收益 |
| | | */ |
| | | BigDecimal earnings = settle(order, order.getVolume()); |
| | | System.out.println("------------------计算收益earnings-------------:"+earnings); |
| | | finalProfit = finalProfit.add(earnings); |
| | | |
| | | |
| | |
| | | Wallet wallet = walletService.findByUserId(userId); |
| | | BigDecimal amountBefore = wallet.getMoney(); |
| | | wallet.setMoney(BigDecimal.ZERO); |
| | | //wallet.setMoney(amountBefore.add(money)); |
| | | if(wallet.getMoney().compareTo(BigDecimal.ZERO) < 0){ |
| | | wallet.setMoney(BigDecimal.ZERO); |
| | | } |
| | |
| | | BigDecimal close = realtime.getClose(); |
| | | BigDecimal point = close.subtract(order.getTradeAvgPrice()); |
| | | BigDecimal profit = point.multiply(new BigDecimal("0.01")).multiply(order.getVolumeOpen()).setScale(4, BigDecimal.ROUND_DOWN);; |
| | | if(null != order.getProfitLossRatio() || order.getProfitLossRatio() > 0){ |
| | | if (order.getForceClosePrice() != null && !order.getForceClosePrice().isEmpty() && |
| | | close.compareTo(new BigDecimal(order.getForceClosePrice())) <= 0) { //达到强平价 |
| | | point = new BigDecimal(order.getForceClosePrice()).subtract(order.getTradeAvgPrice()); |
| | | profit = point.multiply(new BigDecimal("0.01")).multiply(order.getVolumeOpen()).setScale(4, BigDecimal.ROUND_DOWN);; |
| | | System.out.println("------------------point-------------:"+point); |
| | | System.out.println("------------------profit------------:"+profit); |
| | | profit = order.getDepositOpen().add(order.getAddDepositOpen()).negate(); |
| | | System.out.println("------------------扣除保证金------------:"+profit); |
| | | if (order.getLocationType() == 1) { |
| | | Wallet wallet = this.walletService.findByUserId(order.getPartyId()); |
| | | System.out.println("------------------扣除余额------------:"+wallet.getMoney()); |
| | | profit = profit.subtract(wallet.getMoney()); |
| | | } |
| | | if (ContractOrder.DIRECTION_BUY.equals(order.getDirection())) { |
| | | order.setProfit(profit); |
| | | } else{ |
| | | order.setProfit(profit.negate()); |
| | | } |
| | | } |
| | | |
| | | if(null != order.getProfitLossRatio() && order.getProfitLossRatio() > 0){ |
| | | profit = order.getDepositOpen().multiply(new BigDecimal((order.getProfitLossRatio()/100))).setScale(2, RoundingMode.DOWN); |
| | | } |
| | | BigDecimal rentalProfit = order.getDeposit().add(profit).add(order.getAddDepositOpen()); |
| | | BigDecimal rentalProfit = order.getDepositOpen().add(profit).add(order.getAddDepositOpen()); |
| | | System.out.println("------------------rentalProfit------------:"+rentalProfit); |
| | | BigDecimal rate = volume.divide(order.getVolumeOpen(), 2, RoundingMode.HALF_UP); |
| | | order.setAmountClose(order.getAmountClose().add(profit)); |
| | | order.setVolume(order.getVolume().subtract(volume)); |
| | |
| | | BigDecimal earnings = BigDecimal.ZERO; |
| | | if(order.getLocationType() == 1){//全仓 |
| | | // 获取当前账户余额并加到收益中 |
| | | Map<String, Object> moneyAll = walletService.getMoneyAll(order.getPartyId()); |
| | | earnings = order.getDepositOpen().add(new BigDecimal(moneyAll.get("money_all_coin").toString())); |
| | | //Map<String, Object> moneyAll = walletService.getMoneyAll(order.getPartyId()); |
| | | //earnings = order.getDepositOpen().add(new BigDecimal(moneyAll.get("money_wallet").toString())); |
| | | Wallet wallet = walletService.saveWalletByPartyId(order.getPartyId()); |
| | | earnings = order.getDepositOpen().add(earnings.add(wallet.getMoney())); |
| | | }else{ |
| | | earnings = order.getDepositOpen().add(order.getAddDepositOpen()); |
| | | } |