From ca2b1acbb9d30f9caf26d6b7dd54ef314a285731 Mon Sep 17 00:00:00 2001 From: WrBug Date: Sat, 14 Feb 2026 20:34:27 +0800 Subject: [PATCH] =?UTF-8?q?fix(cryptotail):=20=E5=B0=BE=E7=9B=98=E7=AD=96?= =?UTF-8?q?=E7=95=A5=E4=B8=8B=E5=8D=95=E5=8F=96=E6=B6=88=E9=87=8D=E8=AF=95?= =?UTF-8?q?=E5=B9=B6=E6=89=93=E5=8D=B0=E5=AE=8C=E6=95=B4=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- .../CryptoTailStrategyExecutionService.kt | 42 ++++++++----------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/backend/src/main/kotlin/com/wrbug/polymarketbot/service/cryptotail/CryptoTailStrategyExecutionService.kt b/backend/src/main/kotlin/com/wrbug/polymarketbot/service/cryptotail/CryptoTailStrategyExecutionService.kt index c11d56d..395d1f5 100644 --- a/backend/src/main/kotlin/com/wrbug/polymarketbot/service/cryptotail/CryptoTailStrategyExecutionService.kt +++ b/backend/src/main/kotlin/com/wrbug/polymarketbot/service/cryptotail/CryptoTailStrategyExecutionService.kt @@ -18,7 +18,6 @@ import com.wrbug.polymarketbot.util.CryptoUtils import com.wrbug.polymarketbot.util.RetrofitFactory import com.wrbug.polymarketbot.util.fromJson import com.wrbug.polymarketbot.util.toSafeBigDecimal -import kotlinx.coroutines.delay import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import org.slf4j.LoggerFactory @@ -72,9 +71,6 @@ class CryptoTailStrategyExecutionService( private val logger = LoggerFactory.getLogger(CryptoTailStrategyExecutionService::class.java) - private val maxRetryAttempts = 3 - private val retryDelayMs = 2000L - /** 按 (strategyId, periodStartUnix) 加锁,避免同一周期被调度器与 WebSocket 等多路并发重复下单 */ private val triggerMutexMap = ConcurrentHashMap() @@ -267,29 +263,27 @@ class CryptoTailStrategyExecutionService( amountUsdc: BigDecimal, orderRequest: NewOrderRequest ) { - var lastError: String? = null - for (attempt in 1..maxRetryAttempts) { - try { - val response = clobApi.createOrder(orderRequest) - if (response.isSuccessful && response.body() != null) { - val body = response.body()!! - if (body.success && body.orderId != null) { - saveTriggerRecord(strategy, periodStartUnix, marketTitle, outcomeIndex, triggerPrice, amountUsdc, body.orderId, "success", null) - logger.info("尾盘策略下单成功: strategyId=${strategy.id}, periodStartUnix=$periodStartUnix, outcomeIndex=$outcomeIndex, orderId=${body.orderId}") - return - } - lastError = body.errorMsg ?: "unknown" - } else { - lastError = "HTTP ${response.code()} ${response.errorBody()?.string()?.take(200)}" + var failReason: String? = null + try { + val response = clobApi.createOrder(orderRequest) + if (response.isSuccessful && response.body() != null) { + val body = response.body()!! + if (body.success && body.orderId != null) { + saveTriggerRecord(strategy, periodStartUnix, marketTitle, outcomeIndex, triggerPrice, amountUsdc, body.orderId, "success", null) + logger.info("尾盘策略下单成功: strategyId=${strategy.id}, periodStartUnix=$periodStartUnix, outcomeIndex=$outcomeIndex, orderId=${body.orderId}") + return } - } catch (e: Exception) { - lastError = e.message ?: "exception" - logger.warn("尾盘策略下单异常 (attempt $attempt/$maxRetryAttempts): strategyId=${strategy.id}, error=$lastError") + failReason = body.errorMsg ?: "unknown" + } else { + val errorBody = response.errorBody()?.string().orEmpty() + failReason = "HTTP ${response.code()} $errorBody" } - if (attempt < maxRetryAttempts) delay(retryDelayMs) + } catch (e: Exception) { + failReason = e.message ?: e.toString() + logger.error("尾盘策略下单异常: strategyId=${strategy.id}, periodStartUnix=$periodStartUnix", e) } - saveTriggerRecord(strategy, periodStartUnix, marketTitle, outcomeIndex, triggerPrice, amountUsdc, null, "fail", lastError) - logger.warn("尾盘策略下单失败(已重试${maxRetryAttempts}次): strategyId=${strategy.id}, periodStartUnix=$periodStartUnix, reason=$lastError") + saveTriggerRecord(strategy, periodStartUnix, marketTitle, outcomeIndex, triggerPrice, amountUsdc, null, "fail", failReason) + logger.error("尾盘策略下单失败: strategyId=${strategy.id}, periodStartUnix=$periodStartUnix, reason=$failReason") } /** 无预置上下文时的完整流程:固定价格 0.99,账户/解密/费率/签名在触发时执行 */