From 7b73a544cec17c05b5931cf6c2b5cdf598e127b4 Mon Sep 17 00:00:00 2001
From: zj <1772600164@qq.com>
Date: Wed, 07 Aug 2024 18:36:09 +0800
Subject: [PATCH] 1

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

diff --git a/src/main/java/project/contract/internal/ContractOrderServiceImpl.java b/src/main/java/project/contract/internal/ContractOrderServiceImpl.java
index a71fe22..006f318 100644
--- a/src/main/java/project/contract/internal/ContractOrderServiceImpl.java
+++ b/src/main/java/project/contract/internal/ContractOrderServiceImpl.java
@@ -461,6 +461,7 @@
 
 	public Map<String, Object> bulidOne(ContractOrder order) {
 		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd  hh:mm:ss  a", Locale.ENGLISH);
+		simpleDateFormat.setTimeZone(TimeZone.getTimeZone("America/New_York"));
 		DecimalFormat df = new DecimalFormat("#.##");
 		Map<String, Object> map = new HashMap<String, Object>();
 		map.put("order_no", order.getOrder_no());
@@ -501,6 +502,28 @@
 			map.put("profit", df.format(Arith.sub(Arith.add(order.getAmount_close(), order.getDeposit()), order.getDeposit_open())));
 		}
 
+
+		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;
+
+		// 得到强平价格
+		if(null != map.get("direction")){
+			double liquidationPrice;
+			if(map.get("direction").equals("sell")){
+				liquidationPrice = currentPrice + (100 / quantity);
+			}else{
+				liquidationPrice = currentPrice - (100 / quantity);
+			}
+			DecimalFormat dfs = new DecimalFormat("#.#####");
+			String formattedPrice = dfs.format(liquidationPrice);
+			map.put("qiangPing",formattedPrice);
+		}
+
 		map.put("volume", order.getVolume());
 		map.put("volume_open", order.getVolume_open());
 

--
Gitblit v1.9.3