From bc398bdacba71477d3da7c51829828795697eafe Mon Sep 17 00:00:00 2001
From: Administrator <15274802129@163.com>
Date: Tue, 09 Dec 2025 22:34:54 +0800
Subject: [PATCH] refactor(okxNewPrice): 优化仓位价格获取逻辑

---
 src/main/java/com/xcong/excoin/modules/okxNewPrice/celue/CaoZuoServiceImpl.java |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/main/java/com/xcong/excoin/modules/okxNewPrice/celue/CaoZuoServiceImpl.java b/src/main/java/com/xcong/excoin/modules/okxNewPrice/celue/CaoZuoServiceImpl.java
index a1c0775..0a80524 100644
--- a/src/main/java/com/xcong/excoin/modules/okxNewPrice/celue/CaoZuoServiceImpl.java
+++ b/src/main/java/com/xcong/excoin/modules/okxNewPrice/celue/CaoZuoServiceImpl.java
@@ -1,5 +1,6 @@
 package com.xcong.excoin.modules.okxNewPrice.celue;
 
+import cn.hutool.core.util.StrUtil;
 import com.xcong.excoin.modules.okxNewPrice.okxWs.InstrumentsWs;
 import com.xcong.excoin.modules.okxNewPrice.okxWs.PositionsWs;
 import com.xcong.excoin.modules.okxNewPrice.okxWs.enums.CoinEnums;
@@ -60,16 +61,16 @@
         log.info(OrderParamEnums.getNameByValue(state));
 
         // 获取标记价格和平均持仓价格
-        Object markPxObj = redisUtils.get(positionsMarkPxKey);
-        Object avgPxObj = redisUtils.get(positionsAvgPxKey);
+        String markPxObj = (String) redisUtils.get(positionsMarkPxKey);
+        String avgPxObj = (String) redisUtils.get(positionsAvgPxKey);
 
-        if (markPxObj == null || avgPxObj == null) {
+        if (StrUtil.isBlank(markPxObj)  || StrUtil.isBlank(avgPxObj)) {
             return OrderParamEnums.INIT.getValue();
         }
 
         try {
-            BigDecimal markPx = new BigDecimal((String) markPxObj);
-            BigDecimal avgPx = new BigDecimal((String) avgPxObj);
+            BigDecimal markPx = new BigDecimal( markPxObj);
+            BigDecimal avgPx = new BigDecimal( avgPxObj);
 
             log.info("开仓价格: {}, 当前价格:{},匹配队列中......", avgPx, markPx);
 
@@ -109,6 +110,7 @@
                         if (realizedPnlValue.compareTo(BigDecimal.ZERO) <= 0) {
                             if (uplValue.compareTo(realizedPnlValue) < 0) {
                                 log.info("当前未实现盈亏:{}没有大于已实现收益>{},等待中", uplValue, realizedPnlValue);
+                                redisUtils.set(positionsOrderPriceKey, String.valueOf(pingCang.getValue()), 0);
                                 return OrderParamEnums.HOLDING.getValue();
                             }else if (uplValue.compareTo(realizedPnlValue) > 0 && uplValue.compareTo(imrValue)  >= 0) {
                                 log.info("当前未实现盈亏:{}大于预计收益>{},赚钱咯", uplValue, imrValue);
@@ -116,6 +118,7 @@
                                 return OrderParamEnums.SELL.getValue();
                             }else{
                                 log.info("当前未实现盈亏:{}没有大于预计收益>{},钱在路上了", uplValue, imrValue);
+                                redisUtils.set(positionsOrderPriceKey, String.valueOf(pingCang.getValue()), 0);
                                 return OrderParamEnums.HOLDING.getValue();
                             }
                         }else {
@@ -125,6 +128,7 @@
                                 return OrderParamEnums.SELL.getValue();
                             }else{
                                 log.info("当前未实现盈亏:{}没有大于预计收益>{},钱在路上了", uplValue, imrValue);
+                                redisUtils.set(positionsOrderPriceKey, String.valueOf(pingCang.getValue()), 0);
                                 return OrderParamEnums.HOLDING.getValue();
                             }
                          }

--
Gitblit v1.9.1