From a0295049dfce83691dccab5d33992a368e78bc48 Mon Sep 17 00:00:00 2001
From: zj <1772600164@qq.com>
Date: Sun, 25 May 2025 21:40:17 +0800
Subject: [PATCH] 1

---
 src/main/java/project/contract/internal/ContractOrderServiceImpl.java |   56 +++++++++-----------------------------------------------
 1 files changed, 9 insertions(+), 47 deletions(-)

diff --git a/src/main/java/project/contract/internal/ContractOrderServiceImpl.java b/src/main/java/project/contract/internal/ContractOrderServiceImpl.java
index 63378f2..4016e81 100644
--- a/src/main/java/project/contract/internal/ContractOrderServiceImpl.java
+++ b/src/main/java/project/contract/internal/ContractOrderServiceImpl.java
@@ -1,5 +1,7 @@
 package project.contract.internal;
 
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.text.DecimalFormat;
 import java.text.SimpleDateFormat;
 import java.util.*;
@@ -540,22 +542,24 @@
 		double totleMoney = wallet.getMoney();
 		profit = Arith.add(profit,totleMoney);
 
-
 		if (map.get("direction") != null) {
 			String direction = map.get("direction").toString();
 			double liquidationPrice;
-			double deposit = depositOpen + profit;
+			double deposit =  profit;
 
 			if(leverRate == 1){
 				liquidationPrice = 0;
 			}else {
 				if ("sell".equals(direction)) {
-					liquidationPrice = tradeAvgPrice + (deposit / div);
+					double lossPercentage = deposit / (Arith.mul(order.getVolume(), order.getUnit_amount()));
+					double priceIncrease = lossPercentage * tradeAvgPrice;
+					liquidationPrice = tradeAvgPrice + priceIncrease;
 				} else {
-					liquidationPrice = (mul * tradeAvgPrice) / (deposit + mul);
+					double lossPercentage = deposit / (Arith.mul(order.getVolume(), order.getUnit_amount()));
+					double priceDrop = lossPercentage * tradeAvgPrice;
+					liquidationPrice = tradeAvgPrice - priceDrop;
 				}
 			}
-
 			DecimalFormat dfs = new DecimalFormat("#.#####");
 			String formattedPrice = dfs.format(liquidationPrice);
 			map.put("qiangPing", formattedPrice);
@@ -566,48 +570,6 @@
 
 		return map;
 	}
-//
-//
-	public static void main(String[] args) {
-		Map<String, Object> map = new HashMap<>();
-		map.put("direction", "buy");  // "buy" 或 "sell"
-		double currentPrice = 59649.7;  // 开仓价格
-		double leve = 10;  // 杠杆倍数
-		double bzj = 500; // 保证金
-		double zjbzj = 500; // 资金账户
-		double xj = 70781.28; // 现价
-
-		double mul = Arith.mul(bzj, leve);//仓位
-		double div = Arith.div(mul, currentPrice);//持有币的数量
-		double amount = Arith.mul(div, Arith.sub(xj, currentPrice));
-		System.out.println(amount);
-
-		if (map.get("direction") != null) {
-			String direction = map.get("direction").toString();
-			double liquidationPrice;
-
-			double bcbzj = bzj + zjbzj;
-			if(leve == 1){
-				liquidationPrice = 0;
-			}else{
-				if ("sell".equals(direction)) {
-					liquidationPrice = currentPrice + (bcbzj / div);
-				} else {
-					liquidationPrice = (mul * currentPrice) / (bcbzj + mul);
-				}
-			}
-			DecimalFormat dfs = new DecimalFormat("#.#####");
-			String formattedPrice = dfs.format(liquidationPrice);
-			map.put("qiangPing", formattedPrice);
-		}
-
-		// 打印结果以验证
-		System.out.println("Calculated Liquidation Price: " + map.get("qiangPing"));
-	}
-
-//
-
-
 
 	@Override
 	public List<ContractOrder> findSubmitted() {

--
Gitblit v1.9.3