Browse Source

update:增加currentPlan v1

tujidelv 2 years ago
parent
commit
ee74c87b5c
1 changed files with 49 additions and 6 deletions
  1. 49 6
      src/main/java/top/lvzhiqiang/service/impl/CoinServiceImpl.java

+ 49 - 6
src/main/java/top/lvzhiqiang/service/impl/CoinServiceImpl.java

@@ -32,10 +32,7 @@ import java.security.InvalidKeyException;
 import java.time.Duration;
 import java.time.LocalDateTime;
 import java.util.*;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.ScheduledThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
+import java.util.concurrent.*;
 import java.util.stream.Collectors;
 
 /**
@@ -317,7 +314,7 @@ public class CoinServiceImpl implements CoinService {
             Map<String, String> paramMap = new HashMap<>();
             paramMap.put("productType", "umcbl");
 
-            String signQueryString = "productType=umcbl";
+            String signQueryString = paramMap.entrySet().stream().map(e -> e.getKey() + "=" + e.getValue()).collect(Collectors.joining("&"));
 
             JSONObject response = requestApi4Common(params.getString("url"), signQueryString, null, JsoupUtil.HTTP_GET, paramMap);
 
@@ -329,7 +326,7 @@ public class CoinServiceImpl implements CoinService {
             paramMap.put("productType", "umcbl");
             paramMap.put("marginCoin", "USDT");
 
-            String signQueryString = "productType=umcbl&marginCoin=USDT";
+            String signQueryString = paramMap.entrySet().stream().map(e -> e.getKey() + "=" + e.getValue()).collect(Collectors.joining("&"));
 
             JSONObject response = requestApi4Common(params.getString("url"), signQueryString, null, JsoupUtil.HTTP_GET, paramMap);
 
@@ -350,11 +347,57 @@ public class CoinServiceImpl implements CoinService {
             result = JSONObject.parseObject(response.body()).getJSONArray("data");
 
             result = renderMainSearch4MonitorCurrency(result, monitorCurrencyList);
+        } else if (params.getString("nameEn").equals("currentPlan")) {
+            Map<String, String> paramMap = new LinkedHashMap<>();
+            paramMap.put("productType", "umcbl");
+            paramMap.put("isPlan", "plan");
+
+            String signQueryString = paramMap.entrySet().stream().map(e -> e.getKey() + "=" + e.getValue()).collect(Collectors.joining("&"));
+
+
+            JSONObject response = requestApi4Common(params.getString("url"), signQueryString, null, JsoupUtil.HTTP_GET, paramMap);
+
+            result = response.getJSONArray("data");
+
+            renderMainSearch4CurrentPlan(result);
         }
 
         return result;
     }
 
+    private void renderMainSearch4CurrentPlan(JSONArray result) {
+        beforeProxy();
+
+        ForkJoinPool forkJoinPool = new ForkJoinPool(16);
+        forkJoinPool.submit(() -> result.parallelStream().forEach(e -> {
+            JSONObject jsonObject = (JSONObject) e;
+
+            jsonObject.put("orderType", jsonObject.getString("orderType").equals("limit") ? "限价" : "市价");
+
+            jsonObject.put("cTime", DateUtils.longToString(jsonObject.getLong("cTime")));
+            jsonObject.put("uTime", StringUtils.isEmpty(jsonObject.getString("uTime")) ? "--" : DateUtils.longToString(jsonObject.getLong("uTime")));
+
+            String requestUrl = mainUrl + "/api/mix/v1/market/ticker?symbol=" + jsonObject.getString("symbol");
+            try {
+                Connection.Response response = JsoupUtil.requestBody(requestUrl, JsoupUtil.HTTP_GET, proxy, null, null);
+                String last = JSONObject.parseObject(response.body()).getJSONObject("data").getString("last");
+
+                BigDecimal chaRate;
+                if ("open_long".equals(jsonObject.getString("side"))) {
+                    chaRate = new BigDecimal(last).divide(new BigDecimal(jsonObject.getString("triggerPrice")), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP);
+                } else {
+                    chaRate = new BigDecimal(jsonObject.getString("triggerPrice")).divide(new BigDecimal(last), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP);
+                }
+
+                jsonObject.put("last", last);
+                jsonObject.put("chaRate", chaRate.toPlainString() + "%");
+                jsonObject.put("chaRateStyle", " style=\"color:#FFFFFF;background-color:red;\"");
+            } catch (Exception ex) {
+                throw new RuntimeException(ex);
+            }
+        })).join();
+    }
+
     private JSONArray renderMainSearch4MonitorCurrency(JSONArray result, List<String> monitorCurrencyList) {
         return result.stream().filter(iter -> monitorCurrencyList.contains(((JSONObject) iter).getString("symbol"))).collect(Collectors.toCollection(JSONArray::new));
     }