新版仿ok交易所-后端
1
zyy
2026-03-06 a36efade6f46f7e5d54b531d1adbf67771929a3b
trading-order-service/src/main/java/com/yami/trading/service/contract/ContractOrderCalculationServiceImpl.java
@@ -9,6 +9,7 @@
import com.yami.trading.service.StrongLevelCalculationService;
import com.yami.trading.service.WalletService;
import com.yami.trading.service.data.DataService;
import com.yami.trading.service.impl.StrongLevelCalculationServiceImpl;
import com.yami.trading.service.item.ItemService;
import com.yami.trading.service.syspara.SysparaService;
import lombok.extern.slf4j.Slf4j;
@@ -246,6 +247,22 @@
        /**
         * 强平计算
         */
        //重新计算强平
        BigDecimal forceClosePrice = new BigDecimal(order.getForceClosePrice());
        if (currentPrice.compareTo(new BigDecimal(order.getForceClosePrice())) <= 0) {//达到强平价
            BigDecimal point = forceClosePrice.subtract(order.getTradeAvgPrice());
            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{
                order.setProfit(amount.negate());
            }
            //逐仓强平利润固定-100%
            if (order.getLocationType() == 0) {
                order.setProfit(order.getDepositOpen().add(order.getAddDepositOpen()).negate());
            }
        }
        this.contractOrderService.updateByIdBuffer(order);
        //判断是全仓还是逐仓
        if (order.getLocationType() == 1) {
//            /**
@@ -261,7 +278,7 @@
//            Wallet wallet = this.walletService.findByUserId(order.getPartyId().toString());
            this.contractOrderService.updateByIdBuffer(order);
            //this.contractOrderService.updateByIdBuffer(order);
//            if (profit.add(wallet.getMoney()).compareTo(BigDecimal.ZERO) <= 0) {
            //判断买涨还是买跌"buy":买(多) "sell":卖(空)
@@ -274,7 +291,6 @@
                    log.info("------------------order.getForceClosePrice()-------------"+order.getForceClosePrice());
                    log.info("------------------开多强平-------------");
                    this.contractOrderService.allClose(order.getPartyId());
                }
            }else{
                if (currentPrice.compareTo(new BigDecimal(order.getForceClosePrice()))>= 0) {//达到强平价
@@ -327,4 +343,10 @@
        this.order_close_line_type = order_close_line_type;
    }
    public static void main(String[] args) {
        StrongLevelCalculationService strongLevelCalculationService = new StrongLevelCalculationServiceImpl();
        double forceClosePrice = strongLevelCalculationService.calculateLiquidationPrice(100,
                0.01, 67704.80, 1.477
                , 0.004, 0.0005);
    }
}