fix: 修复最大仓位金额未生效和交易receipt解析问题
1. 修复 CopyTradingFilterService 中最大仓位金额(maxPositionValue)未生效的问题
- 当只配置了最大仓位金额但未配置 maxSpread 或 minOrderDepth 时,
仓位检查被跳过导致过滤失效
- 将仓位检查移到 needOrderbook 判断之前,确保始终执行仓位检查
2. 修复 OnChainWsService 中交易 receipt 为 JsonNull 时的空指针问题
- 添加 JsonNull 检查,防止解析失败时出现异常
This commit is contained in:
+11
-3
@@ -71,12 +71,20 @@ class CopyTradingFilterService(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. 检查是否需要获取订单簿
|
// 3. 检查是否需要获取订单簿或需要执行仓位检查
|
||||||
// 只有在配置了需要订单簿的过滤条件时才获取
|
// 只有在配置了需要订单簿的过滤条件时才获取订单簿
|
||||||
val needOrderbook = copyTrading.maxSpread != null || copyTrading.minOrderDepth != null
|
val needOrderbook = copyTrading.maxSpread != null || copyTrading.minOrderDepth != null
|
||||||
|
|
||||||
|
// 3.5. 如果不需要订单簿,则跳过订单簿相关的检查,但仍然需要检查仓位限制
|
||||||
if (!needOrderbook) {
|
if (!needOrderbook) {
|
||||||
// 不需要订单簿,直接通过
|
// 仓位检查(如果配置了最大仓位限制且提供了跟单金额和市场ID)
|
||||||
|
if (copyOrderAmount != null && marketId != null) {
|
||||||
|
val positionCheck = checkPositionLimits(copyTrading, copyOrderAmount, marketId)
|
||||||
|
if (!positionCheck.isPassed) {
|
||||||
|
return positionCheck
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 通过所有检查
|
||||||
return FilterResult.passed()
|
return FilterResult.passed()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+8
-2
@@ -1,5 +1,6 @@
|
|||||||
package com.wrbug.polymarketbot.service.copytrading.monitor
|
package com.wrbug.polymarketbot.service.copytrading.monitor
|
||||||
|
|
||||||
|
import com.google.gson.JsonNull
|
||||||
import com.wrbug.polymarketbot.api.*
|
import com.wrbug.polymarketbot.api.*
|
||||||
import com.wrbug.polymarketbot.entity.Leader
|
import com.wrbug.polymarketbot.entity.Leader
|
||||||
import com.wrbug.polymarketbot.repository.LeaderRepository
|
import com.wrbug.polymarketbot.repository.LeaderRepository
|
||||||
@@ -86,7 +87,12 @@ class OnChainWsService(
|
|||||||
/**
|
/**
|
||||||
* 处理 Leader 的交易
|
* 处理 Leader 的交易
|
||||||
*/
|
*/
|
||||||
private suspend fun handleLeaderTransaction(leaderId: Long, txHash: String, httpClient: OkHttpClient, rpcApi: EthereumRpcApi) {
|
private suspend fun handleLeaderTransaction(
|
||||||
|
leaderId: Long,
|
||||||
|
txHash: String,
|
||||||
|
httpClient: OkHttpClient,
|
||||||
|
rpcApi: EthereumRpcApi
|
||||||
|
) {
|
||||||
val leader = monitoredLeaders[leaderId] ?: return
|
val leader = monitoredLeaders[leaderId] ?: return
|
||||||
|
|
||||||
logger.debug("开始处理 Leader 交易: leaderId=$leaderId, txHash=$txHash, leaderAddress=${leader.leaderAddress}")
|
logger.debug("开始处理 Leader 交易: leaderId=$leaderId, txHash=$txHash, leaderAddress=${leader.leaderAddress}")
|
||||||
@@ -105,7 +111,7 @@ class OnChainWsService(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val receiptRpcResponse = receiptResponse.body()!!
|
val receiptRpcResponse = receiptResponse.body()!!
|
||||||
if (receiptRpcResponse.error != null || receiptRpcResponse.result == null) {
|
if (receiptRpcResponse.error != null || receiptRpcResponse.result == null || receiptRpcResponse.result is JsonNull) {
|
||||||
logger.warn("交易 receipt 错误: leaderId=$leaderId, txHash=$txHash, error=${receiptRpcResponse.error}")
|
logger.warn("交易 receipt 错误: leaderId=$leaderId, txHash=$txHash, error=${receiptRpcResponse.error}")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user