From afc858458cbdde1d5f3f2cfce6d056656bf75c16 Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Wed, 13 May 2026 21:39:39 +0800
Subject: [PATCH] refactor(okxNewPrice): 账户配置
---
src/main/java/com/xcong/excoin/modules/okxApi/OkxRestClient.java | 29 +++++++++++++++++++++++++----
1 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/src/main/java/com/xcong/excoin/modules/okxApi/OkxRestClient.java b/src/main/java/com/xcong/excoin/modules/okxApi/OkxRestClient.java
index 43bdecf..9bc24f5 100644
--- a/src/main/java/com/xcong/excoin/modules/okxApi/OkxRestClient.java
+++ b/src/main/java/com/xcong/excoin/modules/okxApi/OkxRestClient.java
@@ -44,7 +44,24 @@
return isSuccess(result, "设置杠杆");
}
- public String fetchInstIdCode(String instType, String instId) {
+ public boolean cancelAllOrders(String instId) {
+ JSONObject params = new JSONObject();
+ params.put("instType", "SWAP");
+ params.put("instId", instId);
+ JSONObject result = post("/api/v5/trade/cancel-all-orders", params);
+ return isSuccess(result, "撤销所有委托单");
+ }
+
+ public boolean closeAllPositions(String instId, String mgnMode) {
+ JSONObject params = new JSONObject();
+ params.put("instType", "SWAP");
+ params.put("instId", instId);
+ params.put("mgnMode", mgnMode);
+ JSONObject result = post("/api/v5/trade/close-all-positions", params);
+ return isSuccess(result, "平仓ETH");
+ }
+
+ public Long fetchInstIdCode(String instType, String instId) {
String path = "/api/v5/account/instruments?instType=" + instType + "&instId=" + instId;
JSONObject result = get(path);
if (result == null || !"0".equals(result.getString("code"))) {
@@ -59,7 +76,7 @@
return null;
}
JSONObject first = data.getJSONObject(0);
- String instIdCode = first.getString("instIdCode");
+ Long instIdCode = first.getLong("instIdCode");
log.info("[REST] 获取instIdCode成功, instId:{}, instIdCode:{}", instId, instIdCode);
return instIdCode;
}
@@ -86,7 +103,9 @@
int code = conn.getResponseCode();
String response = readResponse(conn);
- log.info("[REST] GET {} → HTTP {} body:{}", path, code, response);
+ if (code < 200 || code >= 300) {
+ log.error("[REST] GET {} → HTTP {} body:{}", path, code, response);
+ }
return JSON.parseObject(response);
} catch (Exception e) {
@@ -128,7 +147,9 @@
int code = conn.getResponseCode();
String response = readResponse(conn);
- log.info("[REST] POST {} → HTTP {} body:{}", path, code, response);
+ if (code < 200 || code >= 300) {
+ log.error("[REST] POST {} → HTTP {} body:{}", path, code, response);
+ }
return JSON.parseObject(response);
} catch (Exception e) {
--
Gitblit v1.9.1