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.
This commit is contained in:
WrBug
2026-04-29 14:35:43 +08:00
parent 4b58b7cd46
commit 6a6af6f5e9
@@ -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,