From 04063bcb7b9e9d8e0242c1313f54ccc1b71f0b6e Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Thu, 25 Jun 2026 22:46:56 +0800
Subject: [PATCH] fix(gateApi): 调整网格交易参数配置
---
src/main/java/com/xcong/excoin/modules/okxApi/OkxTradeExecutor.java | 44 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 44 insertions(+), 0 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 29874b6..9f1d7c2 100644
--- a/src/main/java/com/xcong/excoin/modules/okxApi/OkxTradeExecutor.java
+++ b/src/main/java/com/xcong/excoin/modules/okxApi/OkxTradeExecutor.java
@@ -330,6 +330,50 @@
}
/**
+ * 对外暴露的市价平仓接口(含回调),供策略层直接调用。
+ *
+ * @param size 平仓张数(正数)
+ * @param posSide 持仓方向(long=平多 / short=平空)
+ * @param onSuccess 成功回调(可为 null)
+ * @param onFailure 失败回调(可为 null)
+ */
+ public void marketClosePosition(String size, String posSide,
+ Runnable onSuccess, Runnable onFailure) {
+ executor.execute(() -> {
+ String side = "long".equals(posSide) ? "sell" : "buy";
+ try {
+ JSONObject body = new JSONObject();
+ body.put("instId", contract);
+ body.put("tdMode", "cross");
+ body.put("side", side);
+ body.put("posSide", posSide);
+ body.put("ordType", "market");
+ body.put("sz", size);
+
+ JSONObject resp = okPost("/api/v5/trade/order", body.toJSONString());
+ String code = resp.getString("code");
+ if (!"0".equals(code)) {
+ log.error("[TradeExec-OKX] 市价平仓失败, side:{}, posSide:{}, sz:{}, code:{}, msg:{}",
+ side, posSide, size, code, resp.getString("msg"));
+ if (onFailure != null) {
+ onFailure.run();
+ }
+ return;
+ }
+ log.info("[TradeExec-OKX] 市价平仓成功, side:{}, posSide:{}, sz:{}", side, posSide, size);
+ if (onSuccess != null) {
+ onSuccess.run();
+ }
+ } catch (Exception e) {
+ log.error("[TradeExec-OKX] 市价平仓失败, side:{}, posSide:{}, sz:{}", side, posSide, size, e);
+ if (onFailure != null) {
+ onFailure.run();
+ }
+ }
+ });
+ }
+
+ /**
* 指定方向的市价平仓。
*
* @param sz 平仓张数
--
Gitblit v1.9.1