fix(cryptotail): 尾盘策略下单取消重试并打印完整报错信息
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+18
-24
@@ -18,7 +18,6 @@ import com.wrbug.polymarketbot.util.CryptoUtils
|
|||||||
import com.wrbug.polymarketbot.util.RetrofitFactory
|
import com.wrbug.polymarketbot.util.RetrofitFactory
|
||||||
import com.wrbug.polymarketbot.util.fromJson
|
import com.wrbug.polymarketbot.util.fromJson
|
||||||
import com.wrbug.polymarketbot.util.toSafeBigDecimal
|
import com.wrbug.polymarketbot.util.toSafeBigDecimal
|
||||||
import kotlinx.coroutines.delay
|
|
||||||
import kotlinx.coroutines.sync.Mutex
|
import kotlinx.coroutines.sync.Mutex
|
||||||
import kotlinx.coroutines.sync.withLock
|
import kotlinx.coroutines.sync.withLock
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
@@ -72,9 +71,6 @@ class CryptoTailStrategyExecutionService(
|
|||||||
|
|
||||||
private val logger = LoggerFactory.getLogger(CryptoTailStrategyExecutionService::class.java)
|
private val logger = LoggerFactory.getLogger(CryptoTailStrategyExecutionService::class.java)
|
||||||
|
|
||||||
private val maxRetryAttempts = 3
|
|
||||||
private val retryDelayMs = 2000L
|
|
||||||
|
|
||||||
/** 按 (strategyId, periodStartUnix) 加锁,避免同一周期被调度器与 WebSocket 等多路并发重复下单 */
|
/** 按 (strategyId, periodStartUnix) 加锁,避免同一周期被调度器与 WebSocket 等多路并发重复下单 */
|
||||||
private val triggerMutexMap = ConcurrentHashMap<String, Mutex>()
|
private val triggerMutexMap = ConcurrentHashMap<String, Mutex>()
|
||||||
|
|
||||||
@@ -267,29 +263,27 @@ class CryptoTailStrategyExecutionService(
|
|||||||
amountUsdc: BigDecimal,
|
amountUsdc: BigDecimal,
|
||||||
orderRequest: NewOrderRequest
|
orderRequest: NewOrderRequest
|
||||||
) {
|
) {
|
||||||
var lastError: String? = null
|
var failReason: String? = null
|
||||||
for (attempt in 1..maxRetryAttempts) {
|
try {
|
||||||
try {
|
val response = clobApi.createOrder(orderRequest)
|
||||||
val response = clobApi.createOrder(orderRequest)
|
if (response.isSuccessful && response.body() != null) {
|
||||||
if (response.isSuccessful && response.body() != null) {
|
val body = response.body()!!
|
||||||
val body = response.body()!!
|
if (body.success && body.orderId != null) {
|
||||||
if (body.success && body.orderId != null) {
|
saveTriggerRecord(strategy, periodStartUnix, marketTitle, outcomeIndex, triggerPrice, amountUsdc, body.orderId, "success", null)
|
||||||
saveTriggerRecord(strategy, periodStartUnix, marketTitle, outcomeIndex, triggerPrice, amountUsdc, body.orderId, "success", null)
|
logger.info("尾盘策略下单成功: strategyId=${strategy.id}, periodStartUnix=$periodStartUnix, outcomeIndex=$outcomeIndex, orderId=${body.orderId}")
|
||||||
logger.info("尾盘策略下单成功: strategyId=${strategy.id}, periodStartUnix=$periodStartUnix, outcomeIndex=$outcomeIndex, orderId=${body.orderId}")
|
return
|
||||||
return
|
|
||||||
}
|
|
||||||
lastError = body.errorMsg ?: "unknown"
|
|
||||||
} else {
|
|
||||||
lastError = "HTTP ${response.code()} ${response.errorBody()?.string()?.take(200)}"
|
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
failReason = body.errorMsg ?: "unknown"
|
||||||
lastError = e.message ?: "exception"
|
} else {
|
||||||
logger.warn("尾盘策略下单异常 (attempt $attempt/$maxRetryAttempts): strategyId=${strategy.id}, error=$lastError")
|
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)
|
saveTriggerRecord(strategy, periodStartUnix, marketTitle, outcomeIndex, triggerPrice, amountUsdc, null, "fail", failReason)
|
||||||
logger.warn("尾盘策略下单失败(已重试${maxRetryAttempts}次): strategyId=${strategy.id}, periodStartUnix=$periodStartUnix, reason=$lastError")
|
logger.error("尾盘策略下单失败: strategyId=${strategy.id}, periodStartUnix=$periodStartUnix, reason=$failReason")
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 无预置上下文时的完整流程:固定价格 0.99,账户/解密/费率/签名在触发时执行 */
|
/** 无预置上下文时的完整流程:固定价格 0.99,账户/解密/费率/签名在触发时执行 */
|
||||||
|
|||||||
Reference in New Issue
Block a user