新版仿ok交易所-后端
1
dd
2026-05-30 030e1d50c1f643137220f1ecf1d90ce39174204a
trading-order-admin/src/main/java/com/yami/trading/api/controller/ApiContractApplyOrderController.java
@@ -23,10 +23,12 @@
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;
import com.yami.trading.service.contract.ContractOrderService;
import com.yami.trading.service.contract.ContractPositionModeService;
import com.yami.trading.service.data.DataService;
import com.yami.trading.service.item.ItemLeverageService;
import com.yami.trading.service.item.ItemService;
@@ -93,6 +95,9 @@
    private ContractOrderService contractOrderService;
    @Autowired
    private ContractPositionModeService contractPositionModeService;
    @Autowired
    private ContractLockService contractLockService;
    @Autowired
    private SessionTokenService sessionTokenService;
@@ -127,6 +132,7 @@
        data.put("contract_open_limit_min", contractOpenLimitMin);
        BigDecimal contractOpenLimitMax = new BigDecimal(sysparaService.find("contract_open_limit_max").getSvalue());
        data.put("contract_open_limit_max", contractOpenLimitMax);
        data.put("contract_position_mode", contractPositionModeService.getMode());
        return Result.succeed(data);
@@ -196,13 +202,23 @@
        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("请稍后再试");
            }
            //判断下单金额是否符合最低金额  最低下单张数: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("最低下单金额:"+roundedAmount);
            }
            // 校验当前用户订单状态
@@ -253,7 +269,7 @@
    private void checkUserStatus(String partyId) {
        User user = userService.getById(partyId);
        if (!user.isEnabled()) {
            throw new YamiShopBindException("用户已锁定");
            throw new YamiShopBindException("User is locked");
        }
    }
@@ -278,15 +294,16 @@
        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);
    }
@@ -306,7 +323,7 @@
        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");
@@ -326,7 +343,7 @@
            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());