From 6a6af6f5e930fa919047267768648f4d080794ec Mon Sep 17 00:00:00 2001 From: WrBug Date: Wed, 29 Apr 2026 14:35:43 +0800 Subject: [PATCH] fix: handle neg_risk market in sellPosition Fixes #38 The sellPosition method was not checking if the market uses Neg Risk Exchange contract. For neg_risk markets, the order signing must use the Neg Risk Exchange address, otherwise the order will be rejected by Polymarket. The copy trading service already handles this correctly, but the manual sell position flow was missing this check. --- .../service/accounts/AccountService.kt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/backend/src/main/kotlin/com/wrbug/polymarketbot/service/accounts/AccountService.kt b/backend/src/main/kotlin/com/wrbug/polymarketbot/service/accounts/AccountService.kt index dd89010..a35511a 100644 --- a/backend/src/main/kotlin/com/wrbug/polymarketbot/service/accounts/AccountService.kt +++ b/backend/src/main/kotlin/com/wrbug/polymarketbot/service/accounts/AccountService.kt @@ -1247,7 +1247,14 @@ class AccountService( // 7. 解密私钥 val decryptedPrivateKey = decryptPrivateKey(account) - // 11. 创建并签名订单(使用计算后的卖出数量,按账户钱包类型使用对应 signatureType) + // 11. 检查市场是否为 Neg Risk 市场,获取正确的 Exchange 合约地址 + val negRisk = marketService.getNegRiskByConditionId(request.marketId) == true + val exchangeContract = orderSigningService.getExchangeContract(negRisk) + if (negRisk) { + logger.debug("市场为 Neg Risk,使用 Neg Risk Exchange 签约: conditionId=${request.marketId}") + } + + // 12. 创建并签名订单(使用计算后的卖出数量,按账户钱包类型使用对应 signatureType) val signedOrder = try { orderSigningService.createAndSignOrder( privateKey = decryptedPrivateKey, @@ -1256,14 +1263,15 @@ class AccountService( side = "SELL", price = sellPrice, size = sellQuantity.toPlainString(), // 使用计算后的卖出数量 - signatureType = orderSigningService.getSignatureTypeForWalletType(account.walletType) + signatureType = orderSigningService.getSignatureTypeForWalletType(account.walletType), + exchangeContract = exchangeContract ) } catch (e: Exception) { logger.error("创建并签名订单失败", e) return Result.failure(Exception("创建并签名订单失败: ${e.message}")) } - // 12. 构建订单请求 + // 13. 构建订单请求 val newOrderRequest = com.wrbug.polymarketbot.api.NewOrderRequest( order = signedOrder,