| | |
| | | import com.yami.trading.common.util.StringUtils; |
| | | import com.yami.trading.dao.contract.ContractApplyOrderMapper; |
| | | import com.yami.trading.service.MoneyLogService; |
| | | import com.yami.trading.service.StrongLevelCalculationService; |
| | | import com.yami.trading.service.data.DataService; |
| | | import com.yami.trading.service.user.UserService; |
| | | import com.yami.trading.service.WalletService; |
| | |
| | | private WalletService walletService; |
| | | @Autowired |
| | | private ContractOrderService contractOrderService; |
| | | @Autowired |
| | | private StrongLevelCalculationService strongLevelCalculationService; |
| | | |
| | | public Page<Map<String, Object>> findList(Page<ContractApplyOrder> page, String partyId, String symbol, String type, String startTime, String endTime, String symbolType) { |
| | | QueryWrapper<ContractApplyOrder> queryWrapper = new QueryWrapper<>(); |
| | |
| | | |
| | | public void saveCreate(ContractApplyOrder order) { |
| | | |
| | | if (order.getVolumeOpen().doubleValue() % 1 != 0) { |
| | | throw new YamiShopBindException("Parameter Error1"); |
| | | } |
| | | |
| | | if (order.getVolumeOpen().compareTo(BigDecimal.ZERO) <= 0) { |
| | | throw new YamiShopBindException("Parameter Error2"); |
| | | // if (order.getVolumeOpen().doubleValue() % 1 != 0) { |
| | | // throw new YamiShopBindException("Parameter Error1"); |
| | | // } |
| | | // |
| | | // if (order.getVolumeOpen().compareTo(BigDecimal.ZERO) <= 0) { |
| | | // throw new YamiShopBindException("Parameter Error2"); |
| | | // } |
| | | if(order.getMoney().compareTo(BigDecimal.ZERO) <= 0){ |
| | | throw new YamiShopBindException("Please enter the order amount"); |
| | | } |
| | | |
| | | boolean orderOpen = this.sysparaService.find("order_open").getBoolean(); |
| | |
| | | log.info("{} --- order --- {} --- {}", order.getSymbol(), item.getUuid(), levers.size()); |
| | | checkLever(order, levers); |
| | | |
| | | List<ContractOrder> contractOrderSubmitted = contractOrderService.findSubmitted(order.getPartyId(), |
| | | order.getSymbol(), order.getDirection()); |
| | | for (int i = 0; i < contractOrderSubmitted.size(); i++) { |
| | | BigDecimal sourceLeverRate = order.getLeverRate(); |
| | | sourceLeverRate = sourceLeverRate == null ? BigDecimal.ZERO : sourceLeverRate; |
| | | |
| | | BigDecimal targetLeverRate = contractOrderSubmitted.get(i).getLeverRate(); |
| | | targetLeverRate = targetLeverRate == null ? BigDecimal.ZERO : targetLeverRate; |
| | | if (sourceLeverRate.compareTo(targetLeverRate) != 0) { |
| | | throw new YamiShopBindException("存在不同杠杆的持仓单"); |
| | | } |
| | | } |
| | | List<ContractApplyOrder> applyOrderSubmittedList = this.findSubmitted(order.getPartyId().toString(), |
| | | order.getSymbol(), "open", order.getDirection()); |
| | | for (int i = 0; i < applyOrderSubmittedList.size(); i++) { |
| | | BigDecimal sourceLeverRate = order.getLeverRate(); |
| | | sourceLeverRate = sourceLeverRate == null ? BigDecimal.ZERO : sourceLeverRate; |
| | | BigDecimal targetLeverRate = applyOrderSubmittedList.get(i).getLeverRate(); |
| | | targetLeverRate = targetLeverRate == null ? BigDecimal.ZERO : targetLeverRate; |
| | | if (sourceLeverRate.compareTo(targetLeverRate) != 0) { |
| | | throw new YamiShopBindException("存在不同杠杆的持仓单"); |
| | | } |
| | | } |
| | | |
| | | |
| | | order.setOrderNo(DateUtil.getToday("yyMMddHHmmss") + RandomUtil.getRandomNum(8)); |
| | | |
| | | double number = strongLevelCalculationService.countSheets(order.getMoney().doubleValue(), order.getLeverRate().intValue(), 0.01, order.getPrice().doubleValue()); |
| | | |
| | | order.setVolumeOpen(new BigDecimal(number)); |
| | | order.setVolume(new BigDecimal(number)); |
| | | |
| | | BigDecimal unitAmount = order.getPrice().multiply(BigDecimal.valueOf(item.getFaceValue())); |
| | | unitAmount = unitAmount.setScale(4, RoundingMode.DOWN); |
| | | |
| | | BigDecimal deposit = unitAmount.multiply(order.getVolumeOpen()).divide(order.getLeverRate(), 4, RoundingMode.DOWN); |
| | | |
| | | order.setUnitAmount(unitAmount); |
| | | order.setDeposit(deposit); |
| | | order.setDeposit(order.getMoney()); |
| | | |
| | | if (order.getLeverRate() != null) { |
| | | /** |
| | | * 加上杠杆 |
| | | */ |
| | | // 设置订单数量 |
| | | order.setVolume(order.getVolumeOpen()); |
| | | |
| | | BigDecimal fee = order.getDeposit().multiply(order.getLeverRate()).multiply(item.getUnitFee()); |
| | | fee = fee.setScale(4, RoundingMode.DOWN); // 保留两位小数 |
| | | order.setFee(fee); |
| | | } |
| | | order.setVolumeOpen(order.getVolumeOpen()); |
| | | |
| | | Wallet wallet = this.walletService.findByUserId(order.getPartyId()); |
| | | BigDecimal amountBefore = wallet.getMoney(); |
| | |
| | | volume = volume.subtract(applyOrderSubmittedList.get(i).getVolume()); |
| | | } |
| | | if (order.getVolume().compareTo(volume) > 0) { |
| | | throw new YamiShopBindException("可平仓合约张数不足"); |
| | | throw new YamiShopBindException("可平仓合约数量不足"); |
| | | } |
| | | save(order); |
| | | |