From 8302a0d3a49e25b9c2aa5f68000b29210b4fd556 Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Mon, 15 Dec 2025 20:46:33 +0800
Subject: [PATCH] feat(okx): 调整下单参数配置
---
src/main/java/com/xcong/excoin/modules/okxNewPrice/okxWs/PositionsWs.java | 107 +++++++++++++++++++++++++++++------------------------
1 files changed, 58 insertions(+), 49 deletions(-)
diff --git a/src/main/java/com/xcong/excoin/modules/okxNewPrice/okxWs/PositionsWs.java b/src/main/java/com/xcong/excoin/modules/okxNewPrice/okxWs/PositionsWs.java
index 0af1d7d..3b08fde 100644
--- a/src/main/java/com/xcong/excoin/modules/okxNewPrice/okxWs/PositionsWs.java
+++ b/src/main/java/com/xcong/excoin/modules/okxNewPrice/okxWs/PositionsWs.java
@@ -19,7 +19,13 @@
@Slf4j
public class PositionsWs {
- public static final Map<String,BigDecimal> POSITIONSWSMAP = new ConcurrentHashMap<>();
+ // 使用双层Map,第一层key为账号名称,第二层key为数据key
+ public static final Map<String, Map<String, BigDecimal>> POSITIONSWSMAP = new ConcurrentHashMap<>();
+
+ // 获取指定账号的Map,如果不存在则创建
+ public static Map<String, BigDecimal> getAccountMap(String accountName) {
+ return POSITIONSWSMAP.computeIfAbsent(accountName, k -> new ConcurrentHashMap<>());
+ }
public static final String POSITIONSWS_CHANNEL = "positions";
@@ -41,13 +47,13 @@
}
}
- public static void initEvent(JSONObject response) {
+ public static void initEvent(JSONObject response, String accountName) {
// log.info("订阅成功,数据初始化: {}", response.getJSONObject("arg"));
JSONObject arg = response.getJSONObject("arg");
- initParam(arg);
+ initParam(arg, accountName);
}
- public static void handleEvent(JSONObject response) {
+ public static void handleEvent(JSONObject response, String accountName) {
// log.info("开始执行PositionsWs......");
@@ -56,7 +62,7 @@
if (dataArray == null || dataArray.isEmpty()) {
// log.info("账户持仓频道数据为空,已当前价买入,并且初始化网格");
JSONObject posData = new JSONObject();
- initParam(posData);
+ initParam(posData, accountName);
return;
}
@@ -65,39 +71,41 @@
String instId = posData.getString("instId");
if (CoinEnums.HE_YUE.getCode().equals(instId)) {
// log.info("查询到账户{}持仓数据",CoinEnums.HE_YUE.getCode());
-// String mgnMode = posData.getString("mgnMode");
-// String posSide = posData.getString("posSide");
-// String pos = posData.getString("pos");
-// String avgPx = posData.getString("avgPx");
-// String upl = posData.getString("upl");
-// String uplRatio = posData.getString("uplRatio");
-// String lever = posData.getString("lever");
-// String liqPx = posData.getString("liqPx");
-// String markPx = posData.getString("markPx");
-// String imr = posData.getString("imr");
-// String mgnRatio = posData.getString("mgnRatio");
-// String mmr = posData.getString("mmr");
-// String notionalUsd = posData.getString("notionalUsd");
-// String ccy = posData.getString("ccy");
-// String last = posData.getString("last");
-// String idxPx = posData.getString("idxPx");
-// String bePx = posData.getString("bePx");
-// String realizedPnl = posData.getString("realizedPnl");
-// String settledPnl = posData.getString("settledPnl");
-// log.info(
-// "账户持仓频道-产品类型: {}, 保证金模式: {}, 持仓方向: {}, 持仓数量: {}, 开仓平均价: {}, "
-// + "未实现收益: {}, 未实现收益率: {}, 杠杆倍数: {}, 预估强平价: {}, 初始保证金: {}, "
-// + "维持保证金率: {}, 维持保证金: {}, 以美金价值为单位的持仓数量: {}, 占用保证金的币种: {}, "
-// + "最新成交价: {}, 最新指数价格: {}, 盈亏平衡价: {}, 已实现收益: {}, 累计已结算收益: {}"
-// + "最新标记价格: {}",
-// instId, mgnMode, posSide, pos, avgPx,
-// upl, uplRatio, lever, liqPx, imr,
-// mgnRatio, mmr, notionalUsd, ccy,
-// last, idxPx, bePx, realizedPnl, settledPnl,
-// markPx
-// );
+ String mgnMode = posData.getString("mgnMode");
+ String posSide = posData.getString("posSide");
+ String pos = posData.getString("pos");
+ String avgPx = posData.getString("avgPx");
+ String upl = posData.getString("upl");
+ String uplRatio = posData.getString("uplRatio");
+ String lever = posData.getString("lever");
+ String liqPx = posData.getString("liqPx");
+ String markPx = posData.getString("markPx");
+ String imr = posData.getString("imr");
+ String mgnRatio = posData.getString("mgnRatio");
+ String mmr = posData.getString("mmr");
+ String notionalUsd = posData.getString("notionalUsd");
+ String ccy = posData.getString("ccy");
+ String last = posData.getString("last");
+ String idxPx = posData.getString("idxPx");
+ String bePx = posData.getString("bePx");
+ String realizedPnl = posData.getString("realizedPnl");
+ String settledPnl = posData.getString("settledPnl");
+ String fee = posData.getString("fee");
+ String fundingFee = posData.getString("fundingFee");
+ log.info(
+ "{}: 账户持仓频道-产品类型: {}, 保证金模式: {}, 持仓方向: {}, 持仓数量: {}, 开仓平均价: {}, "
+ + "未实现收益: {}, 未实现收益率: {}, 杠杆倍数: {}, 预估强平价: {}, 初始保证金: {}, "
+ + "维持保证金率: {}, 维持保证金: {}, 以美金价值为单位的持仓数量: {}, 占用保证金的币种: {}, "
+ + "最新成交价: {}, 最新指数价格: {}, 盈亏平衡价: {}, 已实现收益: {}, 累计已结算收益: {}"
+ + "最新标记价格: {},累计手续费: {},累计持仓费: {},",
+ accountName, instId, mgnMode, posSide, pos, avgPx,
+ upl, uplRatio, lever, liqPx, imr,
+ mgnRatio, mmr, notionalUsd, ccy,
+ last, idxPx, bePx, realizedPnl, settledPnl,
+ markPx,fee,fundingFee
+ );
- initParam(posData);
+ initParam(posData, accountName);
}
}
} catch (Exception e) {
@@ -105,18 +113,19 @@
}
}
- private static void initParam(JSONObject posData) {
- WsMapBuild.saveBigDecimalToMap(POSITIONSWSMAP, "avgPx", WsMapBuild.parseBigDecimalSafe(posData.getString("avgPx")));
- WsMapBuild.saveBigDecimalToMap(POSITIONSWSMAP, "pos", WsMapBuild.parseBigDecimalSafe(posData.getString("pos")));
- WsMapBuild.saveBigDecimalToMap(POSITIONSWSMAP, "upl", WsMapBuild.parseBigDecimalSafe(posData.getString("upl")));
- WsMapBuild.saveBigDecimalToMap(POSITIONSWSMAP, "imr", WsMapBuild.parseBigDecimalSafe(posData.getString("imr")));
- WsMapBuild.saveBigDecimalToMap(POSITIONSWSMAP, "mgnRatio", WsMapBuild.parseBigDecimalSafe(posData.getString("mgnRatio")));
- WsMapBuild.saveBigDecimalToMap(POSITIONSWSMAP, "markPx", WsMapBuild.parseBigDecimalSafe(posData.getString("markPx")));
- WsMapBuild.saveBigDecimalToMap(POSITIONSWSMAP, "bePx", WsMapBuild.parseBigDecimalSafe(posData.getString("bePx")));
- WsMapBuild.saveBigDecimalToMap(POSITIONSWSMAP, "realizedPnl", WsMapBuild.parseBigDecimalSafe(posData.getString("realizedPnl")));
- WsMapBuild.saveBigDecimalToMap(POSITIONSWSMAP, "fee", WsMapBuild.parseBigDecimalSafe(posData.getString("fee")));
- WsMapBuild.saveBigDecimalToMap(POSITIONSWSMAP, "fundingFee", WsMapBuild.parseBigDecimalSafe(posData.getString("fundingFee")));
+ private static void initParam(JSONObject posData, String accountName) {
+ Map<String, BigDecimal> accountMap = getAccountMap(accountName);
+ WsMapBuild.saveBigDecimalToMap(accountMap, "avgPx", WsMapBuild.parseBigDecimalSafe(posData.getString("avgPx")));
+ WsMapBuild.saveBigDecimalToMap(accountMap, "pos", WsMapBuild.parseBigDecimalSafe(posData.getString("pos")));
+ WsMapBuild.saveBigDecimalToMap(accountMap, "upl", WsMapBuild.parseBigDecimalSafe(posData.getString("upl")));
+ WsMapBuild.saveBigDecimalToMap(accountMap, "imr", WsMapBuild.parseBigDecimalSafe(posData.getString("imr")));
+ WsMapBuild.saveBigDecimalToMap(accountMap, "mgnRatio", WsMapBuild.parseBigDecimalSafe(posData.getString("mgnRatio")));
+ WsMapBuild.saveBigDecimalToMap(accountMap, "markPx", WsMapBuild.parseBigDecimalSafe(posData.getString("markPx")));
+ WsMapBuild.saveBigDecimalToMap(accountMap, "bePx", WsMapBuild.parseBigDecimalSafe(posData.getString("bePx")));
+ WsMapBuild.saveBigDecimalToMap(accountMap, "realizedPnl", WsMapBuild.parseBigDecimalSafe(posData.getString("realizedPnl")));
+ WsMapBuild.saveBigDecimalToMap(accountMap, "fee", WsMapBuild.parseBigDecimalSafe(posData.getString("fee")));
+ WsMapBuild.saveBigDecimalToMap(accountMap, "fundingFee", WsMapBuild.parseBigDecimalSafe(posData.getString("fundingFee")));
- WsMapBuild.saveBigDecimalToMap(POSITIONSWSMAP, CoinEnums.READY_STATE.name(), WsMapBuild.parseBigDecimalSafe(CoinEnums.READY_STATE_YES.getCode()));
+ WsMapBuild.saveBigDecimalToMap(accountMap, CoinEnums.READY_STATE.name(), WsMapBuild.parseBigDecimalSafe(CoinEnums.READY_STATE_YES.getCode()));
}
}
--
Gitblit v1.9.1