| | |
| | | import com.yami.trading.common.util.ThreadUtils; |
| | | import com.yami.trading.security.common.util.SecurityUtils; |
| | | import com.yami.trading.service.SessionTokenService; |
| | | import com.yami.trading.service.StrongLevelCalculationService; |
| | | import com.yami.trading.service.WalletService; |
| | | import com.yami.trading.service.contract.ContractApplyOrderService; |
| | | import com.yami.trading.service.contract.ContractLockService; |
| | |
| | | BigDecimal contractOpenLimitMax = new BigDecimal(sysparaService.find("contract_open_limit_max").getSvalue()); |
| | | data.put("contract_open_limit_max", contractOpenLimitMax); |
| | | |
| | | |
| | | return Result.succeed(data); |
| | | |
| | | } |
| | |
| | | String partyId = SecurityUtils.getUser().getUserId(); |
| | | RLock rLock = redissonClient.getLock("contract_open_" + partyId); |
| | | boolean lockAcquired = false; |
| | | |
| | | double faceValue = 0.01;//面值 |
| | | double minAmount = 0.01;//最低张数 |
| | | try { |
| | | // 尝试获取锁,最多等待5秒 |
| | | lockAcquired = rLock.tryLock(5, TimeUnit.SECONDS); |
| | | if (!lockAcquired) { |
| | | log.warn("无法获取锁: contract_open_{}", partyId); |
| | | throw new YamiShopBindException("请稍后再试"); |
| | | throw new YamiShopBindException("Please try again later"); |
| | | } |
| | | //判断下单金额是否符合最低金额 最低下单张数:0.01 |
| | | //合约张数 张数=保证金*杠杆倍数/(面值*最新成交价) |
| | | double v = openAction.getAmount().doubleValue() * openAction.getLever_rate().doubleValue() / (faceValue * openAction.getPrice().doubleValue()); |
| | | BigDecimal amount = BigDecimal.valueOf(v).setScale(4, RoundingMode.DOWN); |
| | | if (amount.compareTo(new BigDecimal(faceValue)) < 0) { |
| | | double minimumAmount = minAmount * faceValue * openAction.getPrice().doubleValue() / openAction.getLever_rate().doubleValue(); |
| | | double roundedAmount = Math.ceil(minimumAmount * 10000) / 10000; |
| | | throw new YamiShopBindException("Minimum order amount: " + roundedAmount); |
| | | } |
| | | |
| | | // 校验当前用户订单状态 |
| | |
| | | throw e; // 重新抛出自定义异常 |
| | | } catch (Exception e) { |
| | | log.error("系统异常: {}", e.getMessage(), e); |
| | | throw new YamiShopBindException("操作失败,请稍后再试"); |
| | | throw new YamiShopBindException("Operation failed, please try again later"); |
| | | } finally { |
| | | // 确保释放锁 |
| | | if (lockAcquired && rLock.isHeldByCurrentThread()) { |
| | |
| | | private void checkUserStatus(String partyId) { |
| | | User user = userService.getById(partyId); |
| | | if (!user.isEnabled()) { |
| | | throw new YamiShopBindException("用户已锁定"); |
| | | throw new YamiShopBindException("User is locked"); |
| | | } |
| | | } |
| | | |
| | |
| | | String[] stopUsers = stopUserInternet.split(","); |
| | | User user = userService.getById(partyId); |
| | | if (Arrays.asList(stopUsers).contains(user.getUserName())) { |
| | | throw new YamiShopBindException("无网络"); |
| | | throw new YamiShopBindException("No network connection"); |
| | | } |
| | | } |
| | | } |
| | |
| | | order.setSymbol(openAction.getSymbol()); |
| | | order.setDirection(openAction.getDirection()); |
| | | order.setOffset(ContractApplyOrder.OFFSET_OPEN); |
| | | order.setVolume(openAction.getAmount()); |
| | | order.setVolumeOpen(openAction.getAmount()); |
| | | // order.setVolume(openAction.getAmount()); |
| | | // order.setVolumeOpen(openAction.getAmount()); |
| | | order.setLeverRate(openAction.getLever_rate()); |
| | | order.setPrice(openAction.getPrice()); |
| | | order.setStopPriceProfit(openAction.getStop_price_profit()); |
| | | order.setStopPriceLoss(openAction.getStop_price_loss()); |
| | | order.setOrderPriceType(openAction.getPrice_type()); |
| | | order.setState(ContractApplyOrder.STATE_SUBMITTED); |
| | | |
| | | order.setMoney(openAction.getAmount()); |
| | | order.setLocationType(openAction.getLocationType()); |
| | | contractApplyOrderService.saveCreate(order); |
| | | } |
| | | |
| | |
| | | RLock rLock = redissonClient.getLock("contract_close_" + partyId); |
| | | boolean lockResult = rLock.tryLock(5, TimeUnit.SECONDS); |
| | | if (!lockResult) { |
| | | throw new YamiShopBindException("请稍后再试"); |
| | | throw new YamiShopBindException("Please try again later"); |
| | | } |
| | | try { |
| | | User user = userService.getById(partyId); |
| | | if (!user.isEnabled()) { |
| | | throw new YamiShopBindException("用户已锁定"); |
| | | throw new YamiShopBindException("User is locked"); |
| | | } |
| | | |
| | | Syspara syspara = sysparaService.find("stop_user_internet"); |
| | |
| | | System.out.println("stopUserInternet = " + stopUserInternet); |
| | | |
| | | if(Arrays.asList(stopUsers).contains(user.getUserName())){ |
| | | throw new YamiShopBindException("无网络"); |
| | | throw new YamiShopBindException("No network connection"); |
| | | } |
| | | } |
| | | |
| | |
| | | order.setPartyId(partyId); |
| | | order.setSymbol(closeAction.getSymbol()); |
| | | order.setDirection(closeAction.getDirection()); |
| | | order.setOffset(ContractApplyOrder.OFFSET_OPEN); |
| | | order.setOffset(ContractApplyOrder.OFFSET_CLOSE); |
| | | order.setVolume(closeAction.getAmount()); |
| | | order.setVolumeOpen(closeAction.getAmount()); |
| | | order.setPrice(closeAction.getPrice()); |
| | |
| | | |
| | | ContractApplyOrder order = this.contractApplyOrderService.findByOrderNo(order_no); |
| | | if (order == null) { |
| | | throw new YamiShopBindException("委托单不存在"); |
| | | throw new YamiShopBindException("Order does not exist"); |
| | | } |
| | | Map<String, Object> map = new HashMap<String, Object>(); |
| | | map.put("order_no", order.getOrderNo()); |
| | |
| | | |
| | | } catch (Exception e) { |
| | | log.error("执行撤单异常", e); |
| | | throw new YamiShopBindException("执行撤单异常"); |
| | | throw new YamiShopBindException("Failed to cancel order"); |
| | | } |
| | | |
| | | return Result.succeed(null,"success"); |
| | |
| | | |
| | | } catch (Exception e) { |
| | | log.error("执行撤单异常", e); |
| | | throw new YamiShopBindException("执行撤单异常"); |
| | | throw new YamiShopBindException("Failed to cancel order"); |
| | | } |
| | | |
| | | return Result.succeed(null,"success"); |
| | |
| | | Page<ContractApplyOrder> result = contractApplyOrderService.findList(page, SecurityUtils.getUser().getUserId(), type, symbolType); |
| | | List<ContractApplyOrder> datas = result.getRecords(); |
| | | if (!StringUtils.isInteger(page_no)) { |
| | | throw new YamiShopBindException("页码不是整数"); |
| | | throw new YamiShopBindException("Page number must be an integer"); |
| | | } |
| | | if (Integer.valueOf(page_no).intValue() <= 0) { |
| | | throw new YamiShopBindException("页码不能小于等于0"); |
| | | throw new YamiShopBindException("Page number must be greater than 0"); |
| | | } |
| | | Long count = 0L; |
| | | |