diff --git a/backend/src/main/kotlin/com/wrbug/polymarketbot/service/cryptotail/CryptoTailMonitorService.kt b/backend/src/main/kotlin/com/wrbug/polymarketbot/service/cryptotail/CryptoTailMonitorService.kt index ed903cd..cece207 100644 --- a/backend/src/main/kotlin/com/wrbug/polymarketbot/service/cryptotail/CryptoTailMonitorService.kt +++ b/backend/src/main/kotlin/com/wrbug/polymarketbot/service/cryptotail/CryptoTailMonitorService.kt @@ -97,6 +97,10 @@ class CryptoTailMonitorService( private val strategyHistoryPeriod = ConcurrentHashMap() private val maxHistorySize = 300 + /** price_change 推送节流:每策略最近一次推送时间,1s 内不重复推送 */ + private val lastPriceChangePushTime = ConcurrentHashMap() + private val priceChangePushThrottleMs = 1_000L + data class MonitorEntry( val strategyId: Long, val strategy: CryptoTailStrategy, @@ -652,8 +656,13 @@ class CryptoTailMonitorService( strategyPriceData[strategy.id!!] = newPriceData - val pushData = buildPushData(strategy, newPriceData) - addToHistoryAndPush(strategy.id!!, pushData) + val now = System.currentTimeMillis() + val last = lastPriceChangePushTime[strategy.id!!] ?: 0L + if (now - last >= priceChangePushThrottleMs) { + lastPriceChangePushTime[strategy.id!!] = now + val pushData = buildPushData(strategy, newPriceData) + addToHistoryAndPush(strategy.id!!, pushData) + } } } diff --git a/frontend/src/pages/CryptoTailMonitor.tsx b/frontend/src/pages/CryptoTailMonitor.tsx index ccd5916..69ad8f2 100644 --- a/frontend/src/pages/CryptoTailMonitor.tsx +++ b/frontend/src/pages/CryptoTailMonitor.tsx @@ -159,15 +159,19 @@ const CryptoTailMonitor: React.FC = () => { setInitData(prev => prev ? { ...prev, periodStartUnix: pushPeriod } : null) setPriceHistory([newPoint]) } else { - // 同周期:追加数据 - // 记录首次数据时间(仅在中途进入且未切换过周期时记录) + // 同周期:追加数据(同周期内至少间隔 1s 才追加一点,避免 1s 内多条推送导致点过密) setFirstDataTime(prev => { if (prev == null) { return newPoint.time } return prev }) + const minIntervalMs = 1_000 setPriceHistory(prev => { + const lastTime = prev.length > 0 ? prev[prev.length - 1].time : 0 + if (prev.length > 0 && newPoint.time - lastTime < minIntervalMs) { + return prev + } const maxPoints = 300 const newHistory = [...prev, newPoint] return newHistory.slice(-maxPoints)