| | |
| | | Item item = itemService.findBySymbol(order.getSymbol()); |
| | | |
| | | |
| | | if(null != order.getProfitLossRatio()){//根据后台设置的盈亏比来 |
| | | if(null != order.getProfitLossRatio() && order.getProfitLossRatio() > 0){//根据后台设置的盈亏比来 |
| | | order.setProfit(order.getDepositOpen().multiply(new BigDecimal((order.getProfitLossRatio()/100))).setScale(2, RoundingMode.DOWN)); |
| | | }else{ |
| | | /* |
| | |
| | | * 偏差点位 |
| | | */ |
| | | BigDecimal point = currentPrice.subtract(order.getTradeAvgPrice()); |
| | | BigDecimal amount = point.multiply(new BigDecimal("0.01")).multiply(order.getVolumeOpen()).setScale(4, BigDecimal.ROUND_DOWN);; |
| | | BigDecimal amount = point.multiply(new BigDecimal("0.01")).multiply(order.getVolumeOpen()).setScale(4, BigDecimal.ROUND_DOWN); |
| | | if (ContractOrder.DIRECTION_BUY.equals(order.getDirection())) { |
| | | order.setProfit(amount); |
| | | } else{ |
| | |
| | | earnings = BigDecimal.ZERO; |
| | | |
| | | // 统计非当前订单的其他收益 |
| | | List<ContractOrder> list = contractOrderService.list(new LambdaQueryWrapper<>(ContractOrder.class) |
| | | /*List<ContractOrder> list = contractOrderService.list(new LambdaQueryWrapper<>(ContractOrder.class) |
| | | .eq(ContractOrder::getState, ContractOrder.STATE_SUBMITTED) |
| | | .eq(ContractOrder::getPartyId, order.getPartyId()) |
| | | .ne(ContractOrder::getOrderNo, order.getOrderNo()) |
| | |
| | | .setScale(4, RoundingMode.DOWN); |
| | | |
| | | earnings = earnings.add(profit); // 累加收益 |
| | | } |
| | | }*/ |
| | | |
| | | // 获取当前账户余额并加到收益中 |
| | | Map<String, Object> moneyAll = walletService.getMoneyAll(order.getPartyId()); |
| | | earnings = earnings.add(new BigDecimal(moneyAll.get("money_all_coin").toString())); |
| | | //Map<String, Object> moneyAll = walletService.getMoneyAll(order.getPartyId()); |
| | | |
| | | Wallet wallet = walletService.saveWalletByPartyId(order.getPartyId()); |
| | | earnings = earnings.add(wallet.getMoney()); |
| | | earnings = earnings.add(order.getDepositOpen()); |
| | | } else { |
| | | // 如果不符合条件,直接使用 order.getDepositOpen() 作为收益 |
| | | earnings = order.getDepositOpen(); |
| | | earnings = order.getDepositOpen().add(order.getAddDepositOpen()); |
| | | } |
| | | |
| | | if(ContractOrder.DIRECTION_BUY.equals(order.getDirection())){ |
| | |
| | | // if (profit.add(wallet.getMoney()).compareTo(BigDecimal.ZERO) <= 0) { |
| | | //判断买涨还是买跌"buy":买(多) "sell":卖(空) |
| | | if(order.getDirection().equals("buy")){ |
| | | if (currentPrice.toString().compareTo(order.getForceClosePrice()) <= 0) {//达到强平价 |
| | | if (currentPrice.compareTo(new BigDecimal(order.getForceClosePrice())) <= 0) {//达到强平价 |
| | | /** |
| | | * 触发全仓强平 |
| | | */ |
| | | log.info("------------------currentPrice-------------:"+currentPrice); |
| | | log.info("------------------order.getForceClosePrice()-------------"+order.getForceClosePrice()); |
| | | log.info("------------------开多强平-------------"); |
| | | this.contractOrderService.allClose(order.getPartyId()); |
| | | |
| | | } |
| | | }else{ |
| | | if (currentPrice.toString().compareTo(order.getForceClosePrice())>= 0) {//达到强平价 |
| | | if (currentPrice.compareTo(new BigDecimal(order.getForceClosePrice()))>= 0) {//达到强平价 |
| | | /** |
| | | * 触发全仓强平 |
| | | */ |
| | | log.info("------------------currentPrice-------------:"+currentPrice); |
| | | log.info("------------------order.getForceClosePrice()-------------"+order.getForceClosePrice()); |
| | | log.info("------------------开空强平-------------"); |
| | | this.contractOrderService.allClose(order.getPartyId()); |
| | | |
| | | } |
| | | } |
| | | } else { |
| | | if(order.getDirection().equals("buy")){ |
| | | if (currentPrice.toString().compareTo(order.getForceClosePrice()) <= 0) {//达到强平价 |
| | | if (currentPrice.compareTo(new BigDecimal(order.getForceClosePrice())) <= 0) {//达到强平价 |
| | | this.contractOrderService.saveClose(order.getPartyId().toString(), order.getOrderNo(),"强平"); |
| | | } |
| | | }else{ |
| | | if (currentPrice.toString().compareTo(order.getForceClosePrice()) >= 0) {//达到强平价 |
| | | if (currentPrice.compareTo(new BigDecimal(order.getForceClosePrice())) >= 0) {//达到强平价 |
| | | this.contractOrderService.saveClose(order.getPartyId().toString(), order.getOrderNo(),"强平"); |
| | | } |
| | | } |