From d663147264d0fc97e9e7ddbd4aeee69e833ad025 Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Tue, 02 Jun 2026 15:14:02 +0800
Subject: [PATCH] fix(okxNewPrice): 修复合约面值配置错误并更新文档
---
src/main/java/com/xcong/excoin/modules/okxNewPrice/OkxWebSocketClientManager.java | 57 +++++++++++++++++++++++++++++++++++++--------------------
1 files changed, 37 insertions(+), 20 deletions(-)
diff --git a/src/main/java/com/xcong/excoin/modules/okxNewPrice/OkxWebSocketClientManager.java b/src/main/java/com/xcong/excoin/modules/okxNewPrice/OkxWebSocketClientManager.java
index 10fcdd3..bea1228 100644
--- a/src/main/java/com/xcong/excoin/modules/okxNewPrice/OkxWebSocketClientManager.java
+++ b/src/main/java/com/xcong/excoin/modules/okxNewPrice/OkxWebSocketClientManager.java
@@ -2,6 +2,7 @@
import com.xcong.excoin.modules.okxNewPrice.gridWs.OkxAlgoOrdersChannelHandler;
import com.xcong.excoin.modules.okxNewPrice.gridWs.OkxKlineChannelHandler;
+import com.xcong.excoin.modules.okxNewPrice.gridWs.OkxOrdersChannelHandler;
import com.xcong.excoin.modules.okxNewPrice.gridWs.OkxPositionsChannelHandler;
import com.xcong.excoin.modules.okxNewPrice.okxpi.config.OKXAccount;
import com.xcong.excoin.modules.okxNewPrice.okxpi.config.enums.DefaultUrls;
@@ -44,8 +45,10 @@
@ConditionalOnProperty(prefix = "app", name = "quant", havingValue = "true")
public class OkxWebSocketClientManager {
- /** 网格交易 WS 客户端 */
- private OkxGridWsClient gridWsClient;
+ /** 网格交易公共 WS 客户端(candle1m) */
+ private OkxGridWsClient gridWsClientPublic;
+ /** 网格交易私有 WS 客户端(positions / orders-algo) */
+ private OkxGridWsClient gridWsClientPrivate;
/** 网格交易策略服务 */
private OkxGridTradeService gridTradeService;
/** 统一配置 */
@@ -83,16 +86,16 @@
.apiKey(primaryAccount.getApiKey())
.secretKey(primaryAccount.getSecretKey())
.passphrase(primaryAccount.getPassphrase())
- .instId("ETH-USDT-SWAP")
+ .instId("BTC-USDT-SWAP")
.leverage("100")
.tdMode("cross")
- .gridRate(new BigDecimal("0.0025"))
- .expectedProfit(new BigDecimal("2"))
- .maxLoss(new BigDecimal("15"))
+ .gridRate(new BigDecimal("0.001"))
+ .expectedProfit(new BigDecimal("20"))
+ .maxLoss(new BigDecimal("30"))
.quantity("1")
.baseQuantity("10")
.priceScale(2)
- .ctVal(new BigDecimal("0.1"))
+ .ctVal(new BigDecimal("0.01"))
.isSimulate(!primaryAccount.isAccountType())
.gridQueueSize(300)
.marginRatioLimit(new BigDecimal("0.2"))
@@ -102,13 +105,19 @@
gridTradeService = new OkxGridTradeService(okxConfig, okxAccount);
gridTradeService.init();
- // 4. 创建 WS 客户端并注册 3 个频道处理器
- gridWsClient = new OkxGridWsClient(primaryAccount);
- gridWsClient.addChannelHandler(new OkxKlineChannelHandler(okxConfig.getInstId(), gridTradeService));
- gridWsClient.addChannelHandler(new OkxPositionsChannelHandler(okxConfig.getInstId(), gridTradeService));
- gridWsClient.addChannelHandler(new OkxAlgoOrdersChannelHandler(okxConfig.getInstId(), gridTradeService));
- gridWsClient.init();
- log.info("[OKX-Manager] WS已连接, 已注册 3 个频道处理器: candle1m/positions/orders-algo");
+ // 4. 创建 WS 客户端并注册频道处理器
+ // 业务 WS(/v5/business):candle1m
+ gridWsClientPublic = new OkxGridWsClient(primaryAccount, true);
+ gridWsClientPublic.addChannelHandler(new OkxKlineChannelHandler(okxConfig.getInstId(), gridTradeService));
+ gridWsClientPublic.init();
+
+ // 私有 WS(/v5/private):positions + orders(algo触发后订单fill带algoId可匹配)
+ gridWsClientPrivate = new OkxGridWsClient(primaryAccount, false);
+ gridWsClientPrivate.addChannelHandler(new OkxPositionsChannelHandler(okxConfig.getInstId(), gridTradeService));
+ gridWsClientPrivate.addChannelHandler(new OkxOrdersChannelHandler(okxConfig.getInstId(), gridTradeService));
+ gridWsClientPrivate.init();
+
+ log.info("[OKX-Manager] WS已连接, business: candle1m, private: positions/orders");
// 5. 激活策略,等待首根 K 线触发基底双开
gridTradeService.startGrid();
@@ -133,11 +142,18 @@
log.error("[OKX-Manager] 停止策略失败", e);
}
}
- if (gridWsClient != null) {
+ if (gridWsClientPublic != null) {
try {
- gridWsClient.destroy();
+ gridWsClientPublic.destroy();
} catch (Exception e) {
- log.error("[OKX-Manager] 销毁WS客户端失败", e);
+ log.error("[OKX-Manager] 销毁公共WS客户端失败", e);
+ }
+ }
+ if (gridWsClientPrivate != null) {
+ try {
+ gridWsClientPrivate.destroy();
+ } catch (Exception e) {
+ log.error("[OKX-Manager] 销毁私有WS客户端失败", e);
}
}
@@ -146,8 +162,9 @@
/** @return 网格交易策略服务实例 */
public OkxGridTradeService getGridTradeService() { return gridTradeService; }
- /** @return 网格交易 WS 客户端实例 */
- public OkxGridWsClient getGridWsClient() { return gridWsClient; }
- /** @return 统一配置实例 */
+ /** @return 网格交易公共 WS 客户端实例 */
+ public OkxGridWsClient getGridWsClientPublic() { return gridWsClientPublic; }
+ /** @return 网格交易私有 WS 客户端实例 */
+ public OkxGridWsClient getGridWsClientPrivate() { return gridWsClientPrivate; }
public OkxConfig getOkxConfig() { return okxConfig; }
}
--
Gitblit v1.9.1