| | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author wzy |
| | |
| | | Long memberId = memberEntity.getId(); |
| | | List<ContractHoldOrderEntity> holdOrderEntities = contractHoldOrderDao.selectHoldOrderListForWholeByMemberIdAndSymbol(memberId, null); |
| | | MemberWalletContractEntity wallet = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(memberId, CoinTypeEnum.USDT.name()); |
| | | BigDecimal currentPrice = new BigDecimal(orderModel.getPrice()); |
| | | |
| | | Map<Object, Object> value = redisUtils.hmget(AppContants.WHOLE_BOMB_PREFIX + memberId); |
| | | if (CollUtil.isNotEmpty(holdOrderEntities)) { |
| | | PlatformTradeSettingEntity tradeSetting = cacheSettingUtils.getTradeSetting(); |
| | | for (ContractHoldOrderEntity holdOrderEntity : holdOrderEntities) { |
| | | // 删除次仓订单 |
| | | contractHoldOrderDao.deleteById(holdOrderEntity.getId()); |
| | | BigDecimal lotNumber = cacheSettingUtils.getSymbolSku(holdOrderEntity.getSymbol()); |
| | | |
| | | String symbolPrice = (String) value.get(holdOrderEntity.getSymbol()); |
| | | log.info("symbolPrice : {}, symbol : {}", symbolPrice, holdOrderEntity.getSymbol()); |
| | | BigDecimal currentPrice = new BigDecimal(symbolPrice); |
| | | // 单个订单盈利 |
| | | BigDecimal profitOrLess = BigDecimal.ZERO; |
| | | // 开多 |
| | | if (ContractHoldOrderEntity.OPENING_TYPE_MORE == holdOrderEntity.getOpeningType()) { |
| | | profitOrLess = currentPrice.subtract(holdOrderEntity.getOpeningPrice()).multiply(new BigDecimal(holdOrderEntity.getSymbolCnt())).multiply(lotNumber); |
| | | // 开空 |
| | | } else { |
| | | profitOrLess = holdOrderEntity.getOpeningPrice().subtract(currentPrice).multiply(new BigDecimal(holdOrderEntity.getSymbolCnt())).multiply(lotNumber); |
| | | } |
| | | |
| | | if (MemberEntity.IS_PROFIT_Y == memberEntity.getIsProfit()) { |
| | | if (profitOrLess.compareTo(BigDecimal.ZERO) > 0) { |
| | | profitOrLess = profitOrLess.multiply(BigDecimal.ONE.subtract(tradeSetting.getForceParam())); |
| | | } else { |
| | | profitOrLess = profitOrLess.multiply(BigDecimal.ONE.add(tradeSetting.getForceParam())); |
| | | } |
| | | } |
| | | |
| | | // BigDecimal profitOrLess = BigDecimal.ZERO; |
| | | // // 开多 |
| | | // if (ContractHoldOrderEntity.OPENING_TYPE_MORE == holdOrderEntity.getOpeningType()) { |
| | | // profitOrLess = currentPrice.subtract(holdOrderEntity.getOpeningPrice()).multiply(new BigDecimal(holdOrderEntity.getSymbolCntSale())).multiply(lotNumber); |
| | | // // 开空 |
| | | // } else { |
| | | // profitOrLess = holdOrderEntity.getOpeningPrice().subtract(currentPrice).multiply(new BigDecimal(holdOrderEntity.getSymbolCntSale())).multiply(lotNumber); |
| | | // } |
| | | // |
| | | // if (MemberEntity.IS_PROFIT_Y == memberEntity.getIsProfit()) { |
| | | // if (profitOrLess.compareTo(BigDecimal.ZERO) > 0) { |
| | | // profitOrLess = profitOrLess.multiply(BigDecimal.ONE.subtract(tradeSetting.getForceParam())); |
| | | // } else { |
| | | // profitOrLess = profitOrLess.multiply(BigDecimal.ONE.add(tradeSetting.getForceParam())); |
| | | // } |
| | | // } |
| | | BigDecimal profitOrLess = CalculateUtil.calOrderProfitOrLess(holdOrderEntity.getOpeningType(), currentPrice, holdOrderEntity.getOpeningPrice(), lotNumber, holdOrderEntity.getSymbolCntSale(), memberEntity.getIsProfit()); |
| | | log.info("profitOrLess ---> {}", profitOrLess); |
| | | ContractOrderEntity contractOrderEntity = ContractHoldOrderEntityMapper.INSTANCE.holdOrderToOrder(holdOrderEntity); |
| | | |
| | | // 查询是否满足爆仓条件 |
| | |
| | | contractOrderEntity.setRewardRatio(rewardRatio); |
| | | contractOrderEntity.setRewardAmount(profitOrLess); |
| | | contractOrderEntity.setClosingPrice(currentPrice); |
| | | contractOrderEntity.setForceClosingPrice(currentPrice); |
| | | |
| | | // 订单状态转换 |
| | | if (ContractOrderEntity.ORDER_TYPE_OPEN_MORE == contractOrderEntity.getOrderType()) { |
| | |
| | | } |
| | | } |
| | | |
| | | memberWalletContractDao.increaseWalletContractBalanceById(BigDecimal.ZERO, wallet.getTotalBalance().subtract(totalAmount), null, wallet.getId()); |
| | | memberWalletContractDao.increaseWalletContractBalanceById(wallet.getAvailableBalance().negate(), wallet.getTotalBalance().subtract(totalAmount).negate(), null, wallet.getId()); |
| | | |
| | | redisUtils.del(AppContants.WHOLE_BOMB_PREFIX + memberId); |
| | | } else { |