zyy
2025-11-15 36e04e9e9cdcebd3305316c8d93d97d351d47f9d
trading-order-admin/src/main/java/com/yami/trading/api/controller/exchange/ApiExchangeApplyOrderController.java
@@ -37,6 +37,7 @@
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.ArrayList;
@@ -393,6 +394,24 @@
        map.put("close_price", order.getClosePrice());
        map.put("close_time", order.getCloseTime());
        map.put("close_time_ts", order.getCloseTime() == null ? "" : order.getCloseTime().getTime());
        if (ExchangeApplyOrder.OFFSET_CLOSE.equals(order.getOffset())) {
            List<ExchangeSymbolDto> exchangeSymbolDtos = exchangeApplyOrderService.querySpotTradPosition(order.getPartyId(), order.getSymbol());
            if (exchangeSymbolDtos != null && !exchangeSymbolDtos.isEmpty()) {
                ExchangeSymbolDto  exchangeSymbolDto = exchangeSymbolDtos.get(0);
                double costPrice = exchangeSymbolDto.getPrice();
                //单个收益
                double profitLoss = order.getClosePrice() - costPrice;
                double profitLossPercentage = (profitLoss / costPrice ) * 100;
                profitLossPercentage = new BigDecimal(profitLossPercentage).setScale(2, RoundingMode.HALF_UP).doubleValue();
                //总收益
                double profitLossSum = new BigDecimal(profitLoss * order.getVolume()).setScale(4, RoundingMode.HALF_UP).doubleValue();
                map.put("costPrice", costPrice);
                map.put("profitLoss", profitLossSum);
                map.put("profitLossPercentage", profitLossPercentage);
            }
        }
        return map;
    }