From 1278ee2bd43b401489b4377b0eee5259b3d5bbbb Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Wed, 13 May 2026 18:17:19 +0800
Subject: [PATCH] refactor(okxNewPrice): 账户配置
---
src/main/java/com/xcong/excoin/modules/okxApi/OkxRestClient.java | 61 ++++++++++++++++++++++++++++++
1 files changed, 60 insertions(+), 1 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 5c04970..35f9a9f 100644
--- a/src/main/java/com/xcong/excoin/modules/okxApi/OkxRestClient.java
+++ b/src/main/java/com/xcong/excoin/modules/okxApi/OkxRestClient.java
@@ -44,6 +44,63 @@
return isSuccess(result, "设置杠杆");
}
+ public String 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"))) {
+ log.error("[REST] 获取instIdCode失败, code:{}, msg:{}",
+ result != null ? result.getString("code") : "null",
+ result != null ? result.getString("msg") : "no response");
+ return null;
+ }
+ com.alibaba.fastjson.JSONArray data = result.getJSONArray("data");
+ if (data == null || data.isEmpty()) {
+ log.error("[REST] 获取instIdCode失败: data为空");
+ return null;
+ }
+ JSONObject first = data.getJSONObject(0);
+ String instIdCode = first.getString("instIdCode");
+ log.info("[REST] 获取instIdCode成功, instId:{}, instIdCode:{}", instId, instIdCode);
+ return instIdCode;
+ }
+
+ private JSONObject get(String path) {
+ HttpURLConnection conn = null;
+ try {
+ String timestamp = OkxWsUtil.getIso8601Timestamp();
+ String sign = OkxWsUtil.signRest(timestamp, "GET", path, "", secretKey);
+
+ URL url = new URL(baseUrl + path);
+ conn = (HttpURLConnection) url.openConnection();
+ conn.setRequestMethod("GET");
+ conn.setConnectTimeout(15000);
+ conn.setReadTimeout(15000);
+ conn.setRequestProperty("Content-Type", "application/json");
+ conn.setRequestProperty("OK-ACCESS-KEY", apiKey);
+ conn.setRequestProperty("OK-ACCESS-SIGN", sign);
+ conn.setRequestProperty("OK-ACCESS-TIMESTAMP", timestamp);
+ conn.setRequestProperty("OK-ACCESS-PASSPHRASE", passphrase);
+ if (isSimulate) {
+ conn.setRequestProperty("x-simulated-trading", "1");
+ }
+
+ int code = conn.getResponseCode();
+ String response = readResponse(conn);
+ if (code < 200 || code >= 300) {
+ log.error("[REST] GET {} → HTTP {} body:{}", path, code, response);
+ }
+
+ return JSON.parseObject(response);
+ } catch (Exception e) {
+ log.error("[REST] GET {} 失败: {}", path, e.getMessage());
+ return null;
+ } finally {
+ if (conn != null) {
+ conn.disconnect();
+ }
+ }
+ }
+
private JSONObject post(String path, JSONObject body) {
HttpURLConnection conn = null;
try {
@@ -73,7 +130,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