From a10ffc2318f2b69fe34eca82829493f86ed8400e Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Wed, 24 Jun 2026 17:21:12 +0800
Subject: [PATCH] fix(okx): 修复基底交易订单状态标记逻辑

---
 src/main/java/com/xcong/excoin/modules/okxApi/OkxGridTradeService.java |   20 +++++++++-----------
 1 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/src/main/java/com/xcong/excoin/modules/okxApi/OkxGridTradeService.java b/src/main/java/com/xcong/excoin/modules/okxApi/OkxGridTradeService.java
index f7c7666..703ba16 100644
--- a/src/main/java/com/xcong/excoin/modules/okxApi/OkxGridTradeService.java
+++ b/src/main/java/com/xcong/excoin/modules/okxApi/OkxGridTradeService.java
@@ -288,21 +288,19 @@
                         .entryOrderId(orderId)
                         .build();
                 config.setBaseLongTraderParam(baseLongTp);
+                baseLongOpened = true;
             }, null);
             executor.openShort(size, (orderId) -> {
                 TraderParam baseShortTp = TraderParam.builder()
                         .entryOrderId(orderId)
                         .build();
                 config.setBaseShortTraderParam(baseShortTp);
+                baseShortOpened = true;
             }, null);
             return;
         }
 
-        // OPENING 状态下若 WS 仓位已确认但 REST 回调尚未完成,等标记价格推送时重试队列生成
-        if (state == StrategyState.OPENING &&
-                baseLongOpened && baseShortOpened) {
-            tryGenerateQueues();
-        }
+
 
         if (state == StrategyState.ACTIVE &&
                 !longActive &&
@@ -333,20 +331,19 @@
         boolean isLong = (direction == TraderParam.Direction.LONG);
 
         if (state == StrategyState.OPENING) {
-            if (isLong && hasPosition && !baseLongOpened) {
+            // 基底成交通知仅记录价格/数量,flag 在 REST 回调中设置
+            if (isLong && hasPosition) {
                 longActive = true;
                 longPositionSize = size;
                 longEntryPrice = entryPrice;
                 longBaseEntryPrice = entryPrice;
-                baseLongOpened = true;
                 log.info("[OKX] 基底多成交价: {}", longBaseEntryPrice);
                 tryGenerateQueues();
-            } else if (!isLong && hasPosition && !baseShortOpened) {
+            } else if (!isLong && hasPosition) {
                 shortActive = true;
                 shortPositionSize = size.abs();
                 shortEntryPrice = entryPrice;
                 shortBaseEntryPrice = entryPrice;
-                baseShortOpened = true;
                 log.info("[OKX] 基底空成交价: {}", shortBaseEntryPrice);
                 tryGenerateQueues();
             }
@@ -416,7 +413,7 @@
     // ---- 自动订单(条件单)状态变更回调 ----
 
     /**
-     * 自动订单状态变更回调。由 OrderAlgoOkxChannelHandler 调用。
+     * 自动订单状态变更回调。由 OrdersOkxChannelHandler 调用。
      */
     public void onAutoOrder(String orderId, String status, String reason, String orderType, String tradeId) {
         if (state == StrategyState.STOPPED) {
@@ -595,7 +592,8 @@
     // ---- 网格队列处理 ----
 
     private void tryGenerateQueues() {
-        if (baseLongOpened && baseShortOpened) {
+        // OPENING 状态下若 WS 仓位已确认但 REST 回调尚未完成,等标记价格推送时重试队列生成
+        if (state == StrategyState.OPENING && baseLongOpened && baseShortOpened) {
             // 确保 openLong/openShort 的 REST 回调已完成(WS 推送可能比回调更快到达)
             if (config.getBaseLongTraderParam() == null || config.getBaseShortTraderParam() == null) {
                 log.warn("[OKX] 基底REST回调尚未完成, 延后队列生成");

--
Gitblit v1.9.1