From 951009a204ec2d9e9caa813e67ea9adb1fb03818 Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Wed, 24 Jun 2026 15:14:37 +0800
Subject: [PATCH] fix(okx): 修复本金计算逻辑和条件单取消功能
---
src/main/java/com/xcong/excoin/modules/okxApi/OkxTradeExecutor.java | 56 +++++++++++++++++++++++++++++---------------------------
1 files changed, 29 insertions(+), 27 deletions(-)
diff --git a/src/main/java/com/xcong/excoin/modules/okxApi/OkxTradeExecutor.java b/src/main/java/com/xcong/excoin/modules/okxApi/OkxTradeExecutor.java
index 2eb5ed0..8c971f9 100644
--- a/src/main/java/com/xcong/excoin/modules/okxApi/OkxTradeExecutor.java
+++ b/src/main/java/com/xcong/excoin/modules/okxApi/OkxTradeExecutor.java
@@ -448,39 +448,41 @@
public void cancelAllPriceTriggeredOrders() {
executor.execute(() -> {
try {
- // 1. 查询所有待处理的算法订单
- String queryPath = "/api/v5/trade/orders-algo-pending?instId=" + contract;
- JSONObject queryResp = okGet(queryPath);
- String code = queryResp.getString("code");
- if (!"0".equals(code)) {
- log.warn("[TradeExec-OKX] 查询待处理条件单失败, code:{}, msg:{}",
- code, queryResp.getString("msg"));
- return;
+ // ordType 是 orders-algo-pending 的必填参数,需分别查询 conditional 和 trigger
+ JSONArray cancelBody = new JSONArray();
+ for (String ordType : new String[]{"conditional", "trigger"}) {
+ String queryPath = "/api/v5/trade/orders-algo-pending?instId=" + contract
+ + "&ordType=" + ordType;
+ try {
+ JSONObject queryResp = okGet(queryPath);
+ if (!"0".equals(queryResp.getString("code"))) {
+ log.warn("[TradeExec-OKX] 查询 pending ordType={} 失败, code:{}, msg:{}",
+ ordType, queryResp.getString("code"), queryResp.getString("msg"));
+ continue;
+ }
+ JSONArray data = queryResp.getJSONArray("data");
+ if (data != null) {
+ for (int i = 0; i < data.size(); i++) {
+ JSONObject order = data.getJSONObject(i);
+ String algoId = order.getString("algoId");
+ if (algoId == null) continue;
+ JSONObject item = new JSONObject();
+ item.put("algoId", algoId);
+ item.put("instId", contract);
+ cancelBody.add(item);
+ }
+ }
+ } catch (Exception e) {
+ log.warn("[TradeExec-OKX] 查询待处理条件单失败, ordType:{}", ordType, e);
+ }
}
- JSONArray data = queryResp.getJSONArray("data");
- if (data == null || data.isEmpty()) {
+ if (cancelBody.isEmpty()) {
log.info("[TradeExec-OKX] 无待处理条件单");
return;
}
- // 2. 收集所有 algoId
- JSONArray cancelBody = new JSONArray();
- for (int i = 0; i < data.size(); i++) {
- JSONObject order = data.getJSONObject(i);
- String algoId = order.getString("algoId");
- if (algoId == null) continue;
- JSONObject item = new JSONObject();
- item.put("algoId", algoId);
- item.put("instId", contract);
- cancelBody.add(item);
- }
-
- if (cancelBody.isEmpty()) {
- return;
- }
-
- // 3. 批量取消
+ // 批量取消
JSONObject cancelResp = okPost("/api/v5/trade/cancel-algos", cancelBody.toJSONString());
String cancelCode = cancelResp.getString("code");
if (!"0".equals(cancelCode)) {
--
Gitblit v1.9.1