Administrator
2026-09-10 b136b5256ce488fc9f0f8c8eef9a6dd1bc520fec
src/main/java/com/xcong/excoin/modules/gateApi/GateTradeExecutor.java
@@ -54,6 +54,11 @@
    private static final String SETTLE = "usdt";
    /** 止盈/止损条件单创建失败后的重试次数 */
    private static final int TRIGGER_ORDER_RETRY_MAX_ATTEMPTS = 3;
    /** 止盈/止损条件单创建失败后的重试间隔(毫秒) */
    private static final long TRIGGER_ORDER_RETRY_DELAY_MS = 500L;
    /** Gate U 本位合约 REST API */
    private final FuturesApi futuresApi;
    /** 合约名称(如 ETH_USDT) */
@@ -179,17 +184,32 @@
                                Consumer<String> onSuccess) {
        executor.execute(() -> {
            FuturesPriceTriggeredOrder order = buildTriggeredOrder(triggerPrice, rule, orderType, size);
            try {
                TriggerOrderResponse response = futuresApi.createPriceTriggeredOrder(SETTLE, order);
                log.info("[TradeExec] 止盈单已创建, 触发价:{}, 类型:{}, size:{}, id:{},idstr:{}",
                        triggerPrice, orderType, size, response.getId(), response.getIdString());
                String orderId = String.valueOf(response.getId());
                if (onSuccess != null) {
                    onSuccess.accept(orderId);
            for (int attempt = 1; attempt <= TRIGGER_ORDER_RETRY_MAX_ATTEMPTS; attempt++) {
                try {
                    TriggerOrderResponse response = futuresApi.createPriceTriggeredOrder(SETTLE, order);
                    log.info("[TradeExec] 止盈单已创建, 触发价:{}, 类型:{}, size:{}, id:{},idstr:{}",
                            triggerPrice, orderType, size, response.getId(), response.getIdString());
                    String orderId = String.valueOf(response.getId());
                    if (onSuccess != null) {
                        onSuccess.accept(orderId);
                    }
                    return;
                } catch (Exception e) {
                    if (attempt < TRIGGER_ORDER_RETRY_MAX_ATTEMPTS) {
                        log.warn("[TradeExec] 止盈单创建失败, 触发价:{}, size:{}, 第{}次尝试失败, {}ms后重试, err:{}",
                                triggerPrice, size, attempt, TRIGGER_ORDER_RETRY_DELAY_MS, e.getMessage());
                        try {
                            Thread.sleep(TRIGGER_ORDER_RETRY_DELAY_MS);
                        } catch (InterruptedException ie) {
                            Thread.currentThread().interrupt();
                            marketClose(size);
                            return;
                        }
                    } else {
                        log.error("[TradeExec] 止盈单创建失败, 触发价:{}, size:{}, 立即市价止盈", triggerPrice, size, e);
                        marketClose(size);
                    }
                }
            } catch (Exception e) {
                log.error("[TradeExec] 止盈单创建失败, 触发价:{}, size:{}, 立即市价止盈", triggerPrice, size, e);
                marketClose(size);
            }
        });
    }