From a949bf71283aeabbf4ac26adb7f183b67c02dfc7 Mon Sep 17 00:00:00 2001
From: zj <1772600164@qq.com>
Date: Wed, 14 Aug 2024 06:18:45 +0800
Subject: [PATCH] 1
---
src/main/java/project/project/web/admin/AdminContractOrderController.java | 135 ++++++++++++++++++++++++++++++++++++++------
1 files changed, 115 insertions(+), 20 deletions(-)
diff --git a/src/main/java/project/project/web/admin/AdminContractOrderController.java b/src/main/java/project/project/web/admin/AdminContractOrderController.java
index 0be3d94..58c4475 100644
--- a/src/main/java/project/project/web/admin/AdminContractOrderController.java
+++ b/src/main/java/project/project/web/admin/AdminContractOrderController.java
@@ -41,6 +41,8 @@
import project.log.LogService;
import project.syspara.Syspara;
import project.syspara.SysparaService;
+import project.wallet.Wallet;
+import project.wallet.WalletService;
import security.SecUser;
import security.internal.SecUserService;
@@ -70,6 +72,9 @@
@Autowired
private AdminContractOrderService adminContractOrderService;
+
+ @Autowired
+ private WalletService walletService;
private final String action = "normal/adminContractOrderAction!";
@@ -110,19 +115,63 @@
String roleName = map.get("rolename").toString();
map.put("roleNameDesc", Constants.ROLE_MAP.containsKey(roleName) ? Constants.ROLE_MAP.get(roleName) : roleName);
}
- 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 depositOpen = Double.parseDouble(map.get("deposit_open").toString());
+ double leverRate = Double.parseDouble(map.get("lever_rate").toString());
+ double tradeAvgPrice = Double.parseDouble(map.get("trade_avg_price").toString());
- // 计算数量
- double quantity = positionValue / currentPrice;
+ double mul = Arith.mul(depositOpen, leverRate);//仓位
+ double div = Arith.div(mul, tradeAvgPrice);//持有币的数量
+ /**
+ * 计算全仓收益 保证金
+ */
+ double profit = 0;
+ List<ContractOrder> contractOrders = contractOrderService.findSubmitted(this.getLoginPartyId(), null, null);
+ for (int f = 0; f < contractOrders.size(); f++) {
+ ContractOrder close_line = contractOrders.get(f);
+ if(close_line.getProfit() > 0){
+ profit = Arith.add(profit, Arith.add(close_line.getProfit(), close_line.getDeposit()));
+ }else{
+ profit = Arith.add(profit, close_line.getDeposit());
+ } }
+ Wallet wallet = this.walletService.saveWalletByPartyId(this.getLoginPartyId());
+ double totleMoney = wallet.getMoney();
+ profit = Arith.add(profit,totleMoney);
- // 得到强平价格
- double liquidationPrice = currentPrice + (110 / quantity);
- DecimalFormat df = new DecimalFormat("#.#####");
- String formattedPrice = df.format(liquidationPrice);
- map.put("qiangPing",formattedPrice);
+
+ if (map.get("direction") != null) {
+ String direction = map.get("direction").toString();
+ double liquidationPrice;
+ double deposit = depositOpen + profit;
+ if(leverRate == 1){
+ liquidationPrice = 0;
+ }else {
+ if ("sell".equals(direction)) {
+ liquidationPrice = tradeAvgPrice + (deposit / div);
+ } else {
+ liquidationPrice = (mul * tradeAvgPrice) / (deposit + mul);
+ }
+ }
+ DecimalFormat dfs = new DecimalFormat("#.#####");
+ String formattedPrice = dfs.format(liquidationPrice);
+ map.put("qiangPing", formattedPrice);
+ }
+
+// double currentPrice = Double.parseDouble(map.get("trade_avg_price").toString());
+//
+// 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();
@@ -214,19 +263,65 @@
String roleName = map.get("rolename").toString();
map.put("roleNameDesc", Constants.ROLE_MAP.containsKey(roleName) ? Constants.ROLE_MAP.get(roleName) : roleName);
}
- double currentPrice = Double.parseDouble(map.get("trade_avg_price").toString());
+// double currentPrice = Double.parseDouble(map.get("trade_avg_price").toString());
+//
+// 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);
+// }
- // 计算仓位总价
- double positionValue = Double.parseDouble(map.get("deposit_open").toString()) * Double.parseDouble(map.get("lever_rate").toString());
+ double depositOpen = Double.parseDouble(map.get("deposit_open").toString());
+ double leverRate = Double.parseDouble(map.get("lever_rate").toString());
+ double tradeAvgPrice = Double.parseDouble(map.get("trade_avg_price").toString());
- // 计算数量
- double quantity = positionValue / currentPrice;
+ double mul = Arith.mul(depositOpen, leverRate);//仓位
+ double div = Arith.div(mul, tradeAvgPrice);//持有币的数量
+ /**
+ * 计算全仓收益 保证金
+ */
+ double profit = 0;
+ List<ContractOrder> contractOrders = contractOrderService.findSubmitted(this.getLoginPartyId(), null, null);
+ for (int f = 0; f < contractOrders.size(); f++) {
+ ContractOrder close_line = contractOrders.get(f);
+ if(close_line.getProfit() > 0){
+ profit = Arith.add(profit, Arith.add(close_line.getProfit(), close_line.getDeposit()));
+ }else{
+ profit = Arith.add(profit, close_line.getDeposit());
+ }
+ }
+ Wallet wallet = this.walletService.saveWalletByPartyId(this.getLoginPartyId());
+ double totleMoney = wallet.getMoney();
+ profit = Arith.add(profit,totleMoney);
- // 得到强平价格
- double liquidationPrice = currentPrice + (110 / quantity);
- DecimalFormat df = new DecimalFormat("#.#####");
- String formattedPrice = df.format(liquidationPrice);
- map.put("qiangPing",formattedPrice);
+
+ if (map.get("direction") != null) {
+ String direction = map.get("direction").toString();
+ double liquidationPrice;
+ double deposit = depositOpen + profit;
+ if(leverRate == 1){
+ liquidationPrice = 0;
+ }else {
+ if ("sell".equals(direction)) {
+ liquidationPrice = tradeAvgPrice + (deposit / div);
+ } else {
+ liquidationPrice = (mul * tradeAvgPrice) / (deposit + mul);
+ }
+ }
+
+ DecimalFormat dfs = new DecimalFormat("#.#####");
+ String formattedPrice = dfs.format(liquidationPrice);
+ map.put("qiangPing", formattedPrice);
+ }
+
}
} catch (BusinessException e) {
--
Gitblit v1.9.3