feat: 趋势过滤信号记录系统 + 实时涨跌方向判断

- 新增 TrendFilter 信号记录(enter/exit),按完整信号和高分信号两档分类
- 信号持久化到 data/trend_signals_cache.json,开机自动恢复
- 新增 /api/trend-signals API + SSE trend_signal 实时广播
- 前端新增完整信号卡片和高分信号卡片,移除旧趋势检测卡片
- 评分加入 1h 涨跌方向和实时 drift 惩罚,下跌币不触发信号
- OKX 交易所支持(累积变动、动量、趋势检测)
- 修复 trend_filter.go 编译错误

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
jackyu66git
2026-05-06 22:24:59 +08:00
co-authored by Claude Opus 4.6
parent 73dac50a36
commit 559d7bb870
14 changed files with 1316 additions and 260 deletions
+12 -3
View File
@@ -18,6 +18,7 @@ var momentumWindows = []momentumWindow{
{"t1s", 20, "1s"},
{"t5s", 100, "5s"},
{"t15s", 300, "15s"},
{"t60s", 1200, "60s"},
}
const maxMomentumRecords = 600
@@ -35,15 +36,19 @@ type MomentumEntry struct {
BG1s float64 `json:"bg_1s"`
BG5s float64 `json:"bg_5s"`
BG15s float64 `json:"bg_15s"`
BG60s float64 `json:"bg_60s"`
HL1s float64 `json:"hl_1s"`
HL5s float64 `json:"hl_5s"`
HL15s float64 `json:"hl_15s"`
HL60s float64 `json:"hl_60s"`
BN1s float64 `json:"bn_1s"`
BN5s float64 `json:"bn_5s"`
BN15s float64 `json:"bn_15s"`
BN60s float64 `json:"bn_60s"`
OKX1s float64 `json:"okx_1s"`
OKX5s float64 `json:"okx_5s"`
OKX15s float64 `json:"okx_15s"`
OKX60s float64 `json:"okx_60s"`
Score float64 `json:"score"` // max abs change across all windows
Direction string `json:"direction"` // "up", "down", "flat", "mixed"
}
@@ -105,6 +110,7 @@ func (mt *MomentumTracker) Snapshot(thresholdPct float64) []MomentumEntry {
entry.BG1s = changes[0]
entry.BG5s = changes[1]
entry.BG15s = changes[2]
entry.BG60s = changes[3]
allChanges = append(allChanges, changes[:]...)
}
if hasHL {
@@ -112,6 +118,7 @@ func (mt *MomentumTracker) Snapshot(thresholdPct float64) []MomentumEntry {
entry.HL1s = changes[0]
entry.HL5s = changes[1]
entry.HL15s = changes[2]
entry.HL60s = changes[3]
allChanges = append(allChanges, changes[:]...)
}
if hasBN {
@@ -119,6 +126,7 @@ func (mt *MomentumTracker) Snapshot(thresholdPct float64) []MomentumEntry {
entry.BN1s = changes[0]
entry.BN5s = changes[1]
entry.BN15s = changes[2]
entry.BN60s = changes[3]
allChanges = append(allChanges, changes[:]...)
}
if hasOK {
@@ -126,6 +134,7 @@ func (mt *MomentumTracker) Snapshot(thresholdPct float64) []MomentumEntry {
entry.OKX1s = changes[0]
entry.OKX5s = changes[1]
entry.OKX15s = changes[2]
entry.OKX60s = changes[3]
allChanges = append(allChanges, changes[:]...)
}
@@ -178,10 +187,10 @@ func (mt *MomentumTracker) Snapshot(thresholdPct float64) []MomentumEntry {
return result
}
// calcWindows computes change% for all 3 windows: (current - old) / old * 100.
// calcWindows computes change% for all windows: (current - old) / old * 100.
// Returns 0 for windows that don't have enough data yet.
func calcWindows(buf *momentumBuffer) [3]float64 {
var result [3]float64
func calcWindows(buf *momentumBuffer) [4]float64 {
var result [4]float64
for i, w := range momentumWindows {
if buf.count < w.Ticks+1 {
continue