浏览代码

update:coin v2

tujidelv 2 年之前
父节点
当前提交
916f6f9f88

+ 35 - 0
src/main/java/top/lvzhiqiang/controller/CoinBgController.java

@@ -0,0 +1,35 @@
+package top.lvzhiqiang.controller;
+
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+import top.lvzhiqiang.service.CoinService;
+
+import javax.annotation.Resource;
+
+/**
+ * CoinBg Controller
+ *
+ * @author lvzhiqiang
+ * 2023/9/5 15:23
+ */
+@Controller
+@RequestMapping("/bg/coin")
+public class CoinBgController {
+
+    @Resource
+    private CoinService coinService;
+
+    /**
+     * 获取全部合约仓位信息V2
+     *
+     * @author lvzhiqiang
+     * 2023/9/5 15:23
+     */
+    @RequestMapping("/findAllPositionv2")
+    @ResponseBody
+    public String findAllPositionv2() {
+
+        return coinService.findAllPositionv2();
+    }
+}

+ 21 - 9
src/main/java/top/lvzhiqiang/controller/CoinController.java

@@ -1,11 +1,16 @@
 package top.lvzhiqiang.controller;
 
-import org.springframework.stereotype.Controller;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.RestController;
 import top.lvzhiqiang.service.CoinService;
+import top.lvzhiqiang.util.DateUtils;
 
 import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 
 /**
  * Coin Controller
@@ -13,8 +18,8 @@ import javax.annotation.Resource;
  * @author lvzhiqiang
  * 2023/9/5 15:23
  */
-@Controller
-@RequestMapping("/bg/coin")
+@RestController
+@RequestMapping("/coin")
 public class CoinController {
 
     @Resource
@@ -26,10 +31,17 @@ public class CoinController {
      * @author lvzhiqiang
      * 2023/9/5 15:23
      */
-    @RequestMapping("/findAllPositionv2")
-    @ResponseBody
-    public String findAllPositionv2() {
-
-        return coinService.findAllPositionv2();
+    @PostMapping("/findAllPositionv2")
+    public JSONArray findAllPositionv2() {
+        JSONArray jsonArray = coinService.handleAllPositionV2().getJSONArray("data");
+        for (int i = 0; i < jsonArray.size(); i++) {
+            JSONObject jsonObject = jsonArray.getJSONObject(i);
+            jsonObject.put("cTime", DateUtils.timeToString(jsonObject.getLong("cTime")));
+            jsonObject.put("margin", new BigDecimal(jsonObject.getString("margin")).setScale(4, RoundingMode.HALF_UP));
+            jsonObject.put("averageOpenPrice", new BigDecimal(jsonObject.getString("averageOpenPrice")).setScale(4, RoundingMode.HALF_UP));
+            jsonObject.put("unrealizedPL", new BigDecimal(jsonObject.getString("unrealizedPL")).setScale(4, RoundingMode.HALF_UP));
+            jsonObject.put("liquidationPrice", new BigDecimal(jsonObject.getString("liquidationPrice")).setScale(4, RoundingMode.HALF_UP));
+        }
+        return jsonArray;
     }
 }

+ 4 - 0
src/main/java/top/lvzhiqiang/service/CoinService.java

@@ -1,5 +1,7 @@
 package top.lvzhiqiang.service;
 
+import com.alibaba.fastjson.JSONObject;
+
 /**
  * Coin Service
  *
@@ -17,4 +19,6 @@ public interface CoinService {
      * 2023/9/5 15:23
      */
     String findAllPositionv2();
+
+    JSONObject handleAllPositionV2();
 }

+ 2 - 1
src/main/java/top/lvzhiqiang/service/impl/CoinServiceImpl.java

@@ -122,7 +122,8 @@ public class CoinServiceImpl implements CoinService {
     /**
      * 处理全部合约仓位信息V2
      */
-    private JSONObject handleAllPositionV2() {
+    @Override
+    public JSONObject handleAllPositionV2() {
         String requestPath = "/api/mix/v1/position/allPosition-v2";
         String timestamp = String.valueOf(System.currentTimeMillis());
         String queryString = "productType=umcbl";

+ 46 - 8
src/main/resources/static/coin.html

@@ -1,9 +1,17 @@
-<!DOCTYPE html>
-<html lang="en">
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
 <head>
-    <meta charset="UTF-8">
-    <title>CRAWLER HOME</title>
-    <meta name="referrer" content="no-referrer"/>
+    <title>Coin主页</title>
+    <meta name="referrer" content="never">
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+    <meta http-equiv="pragma" content="no-cache">
+    <meta http-equiv="cache-control" content="no-cache">
+    <meta http-equiv="expires" content="0">
+    <meta name="renderer" content="webkit|ie-comp|ie-stand">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
+    <link rel="shortcut icon" href="cover/bitcoin.ico" type="image/x-icon">
+    <script src="js/jquery-3.6.0.min.js"></script>
+    <script type="text/javascript" src="js/my-coin.js"></script>
 </head>
 <style type="text/css">
     .font {
@@ -31,9 +39,39 @@
     <hr/>
     <div style="margin-right:20px;">
         <span class="font">获取全部合约仓位信息V2</span>
-        <form method="post" action="bg/coin/findAllPositionv2">
-            <input type="submit" value="提交">
-        </form>
+        <button id="findAllPositionv2-1">展开</button>
+        <button id="findAllPositionv2-2">实时启动</button>
+        <button id="findAllPositionv2-3">实时停止</button>
+    </div>
+    <div id="content" style="display: none;">
+        total:<span id="contentSPAN">0</span>
+        <table border="1" cellspacing="0">
+            <thead>
+                <tr id="contentTH">
+                    <th>币对名称</th>
+                    <th>保证金币种</th>
+                    <th>持仓方向</th>
+                    <th>当前委托待成交的数量</th>
+                    <th>保证金数量</th>
+                    <th>自动追加保证金</th>
+                    <th>仓位可用</th>
+                    <th>仓位冻结</th>
+                    <th>仓位总数量</th>
+                    <th>杠杆倍数</th>
+                    <th>已实现盈亏</th>
+                    <th>平均开仓价</th>
+                    <th>保证金模式</th>
+                    <th>持仓模式</th>
+                    <th>未实现盈亏</th>
+                    <th>预估强平价</th>
+                    <th>维持保证金率</th>
+                    <th>标记价格</th>
+                    <th>最近更新时间</th>
+                </tr>
+            </thead>
+            <tbody id="contentTD">
+            </tbody>
+        </table>
     </div>
 </div>
 </body>

二进制
src/main/resources/static/cover/bitcoin.ico


+ 115 - 0
src/main/resources/static/js/my-coin.js

@@ -0,0 +1,115 @@
+$(function () {
+    initOther();
+});
+
+/**
+ * 初始化其他操作
+ */
+function initOther() {
+    $("#findAllPositionv2-1").click(function () {
+        var display = $('#content');
+        if (display.css('display') == 'block') {
+            display.slideUp("slow");
+            $(this).html('展开');
+        } else {
+            display.slideDown("slow");
+            $(this).html('收起');
+        }
+    });
+
+    var findAllPositionv22Timer;
+    var actualFlag = false;
+    $("#findAllPositionv2-2").click(function () {
+        if (!actualFlag) {
+            findAllPositionv22Timer = setInterval("searchAllPositionv2()", "1000");
+            actualFlag = true;
+        }
+    });
+
+    $("#findAllPositionv2-3").click(function () {
+        if (actualFlag) {
+            clearInterval(findAllPositionv22Timer);
+            actualFlag = false;
+        }
+    });
+}
+
+/**
+ * 多条件搜索
+ * @param pageNo
+ */
+function searchAllPositionv2() {
+    $.ajax({
+        url: "coin/findAllPositionv2", //请求的url地址
+        dataType: "json", //返回格式为json
+        type: "post", //请求方式
+        contentType: "application/json;charset=utf-8",
+        async: true, //请求是否异步,默认为异步,这也是ajax重要特性
+        success: function (data) {
+            //请求成功时处理
+            if (data != null && $.trim(data) != "" && data.success) {
+
+                data = data.data;
+                $("#contentSPAN").html(data.length);
+                var str = '';
+                for (var i = 0; i < data.length; i++) {
+                    var dataDetail = data[i];
+
+                    //未实现盈亏
+                    var unrealizedPL = dataDetail.unrealizedPL;
+                    var unrealizedPLStyle = '';
+                    if (unrealizedPL < 0) {
+                        unrealizedPLStyle = ' style="color:red;"';
+                    } else {
+                        unrealizedPLStyle = ' style="color:green;"';
+                    }
+                    //币对名称
+                    var symbol = dataDetail.symbol;
+                    symbol = '<strong><font color="#808080">' + symbol.replace('USDT_UMCBL', '') + '</font></strong>' + 'USDT_UMCBL';
+
+                    str += '<tr>';
+                    str += '<td>' + symbol + '</td>';
+                    str += '<td>' + dataDetail.marginCoin + '</td>';
+                    str += '<td>' + dataDetail.holdSide + '</td>';
+                    str += '<td>' + dataDetail.openDelegateCount + '</td>';
+                    str += '<td>' + dataDetail.margin + '</td>';
+                    str += '<td>' + dataDetail.autoMargin + '</td>';
+                    str += '<td>' + dataDetail.available + '</td>';
+                    str += '<td>' + dataDetail.locked + '</td>';
+                    str += '<td>' + dataDetail.total + '</td>';
+                    str += '<td>' + dataDetail.leverage + '</td>';
+                    str += '<td>' + dataDetail.achievedProfits + '</td>';
+                    str += '<td>' + dataDetail.averageOpenPrice + '</td>';
+                    str += '<td>' + dataDetail.marginMode + '</td>';
+                    str += '<td>' + dataDetail.holdMode + '</td>';
+                    str += '<td' + unrealizedPLStyle + '>' + dataDetail.unrealizedPL + '</td>';
+                    str += '<td>' + dataDetail.liquidationPrice + '</td>';
+                    str += '<td>' + dataDetail.keepMarginRate + '</td>';
+                    str += '<td>' + dataDetail.marketPrice + '</td>';
+                    str += '<td>' + dataDetail.cTime + '</td>';
+                    str += '</tr>';
+                }
+                $("#contentTD").html(str);
+
+                initContentEvent();
+            } else {
+                alert(data.message);
+            }
+        },
+        beforeSend: function () {
+        },
+        complete: function () {
+        },
+        error: function (data) {
+            //请求出错处理
+            alert('error:' + data);
+        }
+    });
+}
+
+/**
+ * 初始化主内容事件
+ */
+function initContentEvent() {
+
+}