Files
exchange-monitor-go/db/surge_event_repo.go
T
jackyu66gitandClaude Opus 4.6 d38782490c feat: 重构为三所价差异动监控系统
删除 HyperLiquid + 全部交易功能,构建自适应 surge 检测器。
- 新增 surge_detector.go: 每币独立滚动窗口基线,检测三所价差异常飙升
- 新增 SpreadCard/SurgeCard 前端组件
- 保留 momentum/trend/cumulative/trend_filter 扫描功能
- 更新文档和配置以反映新系统

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-08 02:01:18 +08:00

59 lines
2.3 KiB
Go

package db
import "time"
// SurgeEventRecord represents a persisted surge detection event.
type SurgeEventRecord struct {
ID int64 `json:"id"`
Coin string `json:"coin"`
Timestamp string `json:"timestamp"`
BnPrice float64 `json:"bn_price"`
OkxPrice float64 `json:"okx_price"`
BgPrice float64 `json:"bg_price"`
SpreadPct float64 `json:"spread_pct"`
BaselinePct float64 `json:"baseline_pct"`
ThresholdPct float64 `json:"threshold_pct"`
Ratio float64 `json:"ratio"`
Direction string `json:"direction"`
LeadingExchange string `json:"leading_exchange"`
MidPrice float64 `json:"mid_price"`
CreatedAt string `json:"created_at"`
}
// InsertSurgeEvent saves a surge event to the database.
func (d *DB) InsertSurgeEvent(coin string, ts time.Time, bnPrice, okxPrice, bgPrice, spreadPct, baselinePct, thresholdPct, ratio float64, direction, leadingExchange string, midPrice float64) error {
_, err := d.Exec(`
INSERT INTO surge_events (coin, timestamp, bn_price, okx_price, bg_price, spread_pct, baseline_pct, threshold_pct, ratio, direction, leading_exchange, mid_price, created_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
coin, ts.Format(time.RFC3339), bnPrice, okxPrice, bgPrice, spreadPct, baselinePct, thresholdPct, ratio, direction, leadingExchange, midPrice, Now().Format(time.RFC3339))
return err
}
// GetSurgeEvents returns surge events ordered by creation time descending.
func (d *DB) GetSurgeEvents(limit int) ([]SurgeEventRecord, error) {
if limit <= 0 {
limit = 100
}
rows, err := d.Query(`
SELECT id, coin, timestamp, bn_price, okx_price, bg_price, spread_pct, baseline_pct, threshold_pct, ratio, direction, leading_exchange, mid_price, created_at
FROM surge_events
ORDER BY created_at DESC
LIMIT ?`, limit)
if err != nil {
return nil, err
}
defer rows.Close()
var result []SurgeEventRecord
for rows.Next() {
var r SurgeEventRecord
if err := rows.Scan(&r.ID, &r.Coin, &r.Timestamp, &r.BnPrice, &r.OkxPrice, &r.BgPrice,
&r.SpreadPct, &r.BaselinePct, &r.ThresholdPct, &r.Ratio, &r.Direction,
&r.LeadingExchange, &r.MidPrice, &r.CreatedAt); err != nil {
return nil, err
}
result = append(result, r)
}
return result, rows.Err()
}