From 8600449f69da76671e6bc98403139fd90c96f91c Mon Sep 17 00:00:00 2001 From: WrBug Date: Mon, 9 Feb 2026 02:38:47 +0800 Subject: [PATCH] =?UTF-8?q?fix(copytrading):=20=E8=B5=8E=E5=9B=9E=E5=90=8E?= =?UTF-8?q?=E6=8C=89=20copyTrading=20=E5=88=86=E5=88=AB=E7=94=9F=E6=88=90?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=8D=96=E5=87=BA=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- .../service/accounts/PositionCheckService.kt | 31 +++++++------------ 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/backend/src/main/kotlin/com/wrbug/polymarketbot/service/accounts/PositionCheckService.kt b/backend/src/main/kotlin/com/wrbug/polymarketbot/service/accounts/PositionCheckService.kt index 0c24a38..6641af3 100644 --- a/backend/src/main/kotlin/com/wrbug/polymarketbot/service/accounts/PositionCheckService.kt +++ b/backend/src/main/kotlin/com/wrbug/polymarketbot/service/accounts/PositionCheckService.kt @@ -430,27 +430,20 @@ class PositionCheckService( processedRedeemablePositions[positionKey] = now } - // 赎回成功后,再查找订单并更新订单状态 + // 赎回成功后,按每个跟单配置分别查找未卖出订单并更新状态 + // 同一账户同一市场可能同时跟多个 Leader,需按 copyTradingId 分别生成自动卖出记录(如 leader1 对应 20 share,leader2 对应 16 share) for (position in positionsToRedeem) { - // 查找相同仓位的未卖出订单(remaining_quantity > 0) - val unmatchedOrders = mutableListOf() - for (copyTrading in copyTradings) { - if (position.outcomeIndex != null) { - val orders = copyOrderTrackingRepository.findUnmatchedBuyOrdersByOutcomeIndex( - copyTrading.id!!, - position.marketId, - position.outcomeIndex - ) - unmatchedOrders.addAll(orders) - } + if (position.outcomeIndex == null) { + continue } - - // 如果有未卖出订单,更新订单状态 - if (unmatchedOrders.isNotEmpty()) { - // 从订单中获取 copyTradingId(所有订单应该有相同的 copyTradingId) - val copyTradingId = unmatchedOrders.firstOrNull()?.copyTradingId - if (copyTradingId != null) { - updateOrdersAsSoldAfterRedeem(unmatchedOrders, position, copyTradingId) + for (copyTrading in copyTradings) { + val orders = copyOrderTrackingRepository.findUnmatchedBuyOrdersByOutcomeIndex( + copyTrading.id!!, + position.marketId, + position.outcomeIndex + ) + if (orders.isNotEmpty()) { + updateOrdersAsSoldAfterRedeem(orders, position, copyTrading.id!!) } } }