1
zj
2024-08-10 c47543cbe3f6683567c9398a204a86dc192a9608
src/main/java/project/project/web/admin/AdminContractOrderController.java
@@ -9,6 +9,7 @@
import java.util.List;
import java.util.Map;
import javax.persistence.Column;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.ObjectUtils;
@@ -112,17 +113,19 @@
            }
            double currentPrice = Double.parseDouble(map.get("trade_avg_price").toString());
            // 计算仓位总价
            double positionValue = Double.parseDouble(map.get("deposit_open").toString()) * Double.parseDouble(map.get("lever_rate").toString());
            // 计算数量
            double quantity = positionValue / currentPrice;
            // 得到强平价格
            double liquidationPrice = currentPrice + (110 / quantity);
            DecimalFormat df = new DecimalFormat("#.#####");
            String formattedPrice = df.format(liquidationPrice);
            map.put("qiangPing",formattedPrice);
            double leve = Double.parseDouble(map.get("lever_rate").toString());
            //得到强平价格
            if(null != map.get("direction")){
               double liquidationPrice;
               if(map.get("direction").equals("sell")){
                  liquidationPrice = currentPrice * (1 + (1 / leve));
               }else{
                  liquidationPrice = currentPrice * (1 - 1 / leve);
               }
               DecimalFormat df = new DecimalFormat("#.#####");
               String formattedPrice = df.format(liquidationPrice);
               map.put("qiangPing",formattedPrice);
            }
         }
         List<Item> items = this.itemService.cacheGetAll();
@@ -216,17 +219,19 @@
            }
            double currentPrice = Double.parseDouble(map.get("trade_avg_price").toString());
            // 计算仓位总价
            double positionValue = Double.parseDouble(map.get("deposit_open").toString()) * Double.parseDouble(map.get("lever_rate").toString());
            // 计算数量
            double quantity = positionValue / currentPrice;
            // 得到强平价格
            double liquidationPrice = currentPrice + (110 / quantity);
            DecimalFormat df = new DecimalFormat("#.#####");
            String formattedPrice = df.format(liquidationPrice);
            map.put("qiangPing",formattedPrice);
            double leve = Double.parseDouble(map.get("lever_rate").toString());
            //得到强平价格
            if(null != map.get("direction")){
               double liquidationPrice;
               if(map.get("direction").equals("sell")){
                  liquidationPrice = currentPrice * (1 + (1 / leve));
               }else{
                  liquidationPrice = currentPrice * (1 - 1 / leve);
               }
               DecimalFormat df = new DecimalFormat("#.#####");
               String formattedPrice = df.format(liquidationPrice);
               map.put("qiangPing",formattedPrice);
            }
         }
      } catch (BusinessException e) {