| | |
| | | package project.project.web.api; |
| | | package project.web.api; |
| | | |
| | | import java.io.IOException; |
| | | import java.text.DecimalFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.HashSet; |
| | |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | import kernel.util.Arith; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import project.contract.ContractOrderService; |
| | | import project.data.DataService; |
| | | import project.data.model.Realtime; |
| | | import project.wallet.Wallet; |
| | | import project.wallet.WalletService; |
| | | |
| | | /** |
| | | * 永续合约持仓单 |
| | |
| | | |
| | | @Autowired |
| | | private ContractOrderService contractOrderService; |
| | | |
| | | @Autowired |
| | | private WalletService walletService; |
| | | |
| | | private final String action = "/api/contractOrder!"; |
| | | |
| | |
| | | for (int i = 0; i < data.size(); i++) { |
| | | Map<String, Object> map = data.get(i); |
| | | |
| | | 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 mul = Arith.mul(depositOpen, leverRate);//仓位 |
| | | double div = Arith.div(mul, tradeAvgPrice);//持有币的数量 |
| | | /** |
| | | * 计算全仓收益 保证金 |
| | | */ |
| | | double profit = 0; |
| | | List<ContractOrder> list = contractOrderService.findSubmitted(this.getLoginPartyId(), null, null); |
| | | for (int f = 0; f < list.size(); f++) { |
| | | ContractOrder close_line = list.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); |
| | | |
| | | |
| | | if (map.get("direction") != null) { |
| | | String direction = map.get("direction").toString(); |
| | | double liquidationPrice; |
| | | double deposit = profit; |
| | | |
| | | if(leverRate == 1){ |
| | | liquidationPrice = 0; |
| | | }else { |
| | | if ("sell".equals(direction)) { |
| | | double lossPercentage = deposit / Double.parseDouble(map.get("amount").toString()); |
| | | double priceIncrease = lossPercentage * tradeAvgPrice; |
| | | liquidationPrice = tradeAvgPrice + priceIncrease; |
| | | } else { |
| | | double lossPercentage = deposit / Double.parseDouble(map.get("amount").toString()); |
| | | double priceDrop = lossPercentage * tradeAvgPrice; |
| | | liquidationPrice = tradeAvgPrice - priceDrop; |
| | | } |
| | | } |
| | | DecimalFormat dfs = new DecimalFormat("#.#####"); |
| | | String formattedPrice = dfs.format(liquidationPrice); |
| | | map.put("qiangPing", formattedPrice); |
| | | } |
| | | // 标记价格 |
| | | Realtime realtime = realtimeMap.get(map.get("symbol")); |
| | | if (null == realtime) { |