Files
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

119 lines
4.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 三所价差异动监控
Binance + OKX + Bitget 三交易所价差异动实时检测系统。通过追踪不同交易所之间的价差异常,捕捉币价「启动」的瞬间。
## 功能特点
- **三所价差扫描** — 实时计算 Binance/OKX/Bitget 之间的最大价差,按价差排序展示
- **自适应 Surge 检测** — 每个币维护独立的滚动窗口基线,检测价差异常飙升
- **方向判断** — 根据领先交易所判断上涨/下跌启动方向
- **动量扫描** — 多时间窗口 (1s/5s/15s/60s) 价格变动率追踪
- **趋势检测** — 跨交易所一致性确认的趋势状态机 (idle→alert→confirmed→exhausting)
- **累积变动** — 1m/5m/1h 多交易所共识变动追踪
- **趋势过滤** — K 线数据 + EMA52 趋势过滤,识别安静后的异动
- **Web 仪表盘** — Go 内置 HTTP Server + Vite React 前端,SSE 实时推送
- **SQLite 持久化** — Surge 事件、累积变动事件全量存储
## 架构
```
┌─────────────────────────────────────────────────┐
│ Exchange WS (Bitget + Binance + OKX) │
│ ↓ 价格推送 │
│ PriceStore ← 内存价格存储 │
│ ↓ │
│ scanner.go ← 三所价差扫描 │
│ ↓ │
│ surge_detector.go ← 自适应Surge检测 │
│ momentum.go ← 动量扫描 │
│ trend.go ← 趋势检测 │
│ cumulative.go ← 累积变动追踪 │
│ trend_filter.go ← K线趋势过滤 │
│ ↓ SSE 推送 │
│ dashboard.go ← HTTP Server :8888 │
│ ↓ │
│ frontend/ ← Vite + React 仪表盘 │
└─────────────────────────────────────────────────┘
```
## 快速开始
### 1. 配置
编辑 `config.json`
```json
{
"arb_threshold": 0.3,
"scan_interval_ms": 200,
"alert_cooldown_sec": 300,
"surge_enabled": true,
"surge_window_size": 600,
"surge_baseline_multiplier": 3.0,
"surge_min_abs_spread_pct": 0.05,
"surge_cooldown_sec": 60,
"momentum_enabled": true,
"momentum_threshold_pct": 0.25,
"trend_enabled": true,
"trend_baseline_window": 600,
"trend_anomaly_mul": 3.0,
"trend_confirm_ticks": 3,
"trend_alert_cooldown_ms": 60000
}
```
环境变量 (`.env`):
- `BITGET_API_KEY`, `BITGET_API_SECRET`, `BITGET_PASSPHRASE` — Bitget API
- `BINANCE_API_KEY`, `BINANCE_API_SECRET` — Binance API (可选,用于K线)
- `HTTPS_PROXY` — 网络代理 (国内环境需要)
### 2. 启动
```bash
# 一键启动(自动清理旧进程 + 编译 + 运行)
bash start.sh
# 清空数据库 + 启动
bash start.sh --clean
# 强制重新编译 + 启动
bash start.sh --rebuild
```
仪表盘地址:http://localhost:8888
### 3. 前端开发
```bash
cd frontend
npm install
npm run dev # 开发模式 (Vite HMR :5173)
npm run build # 构建生产版本
```
## 配置参数
| 参数 | 说明 | 默认 |
|------|------|------|
| `surge_enabled` | 启用 Surge 检测 | true |
| `surge_window_size` | 滚动窗口样本数 | 600 |
| `surge_baseline_multiplier` | 基线倍数(阈值 = 基线 × N) | 3.0 |
| `surge_min_abs_spread_pct` | 最小绝对价差 % | 0.05 |
| `surge_cooldown_sec` | 同币冷却秒数 | 60 |
| `momentum_enabled` | 启用动量扫描 | true |
| `trend_enabled` | 启用趋势检测 | true |
| `trend_baseline_window` | 趋势基线窗口 | 600 |
| `trend_anomaly_mul` | 异常检测倍数 | 3.0 |
| `trend_confirm_ticks` | 确认所需次数 | 3 |
## 数据库
SQLite (`data/trades.db`),核心表:
| 表 | 说明 |
|----|------|
| `surge_events` | Surge 异动事件 — 币种、价格、价差、方向、领先交易所 |
| `cm_events` | 累积变动事件 — 1m/5m/1h 多所共识变动 |
| `trend_events` | 趋势状态变迁 — idle→alert→confirmed→exhausting 全生命周期 |
| `trend_signals` | 趋势过滤信号 — K 线安静 + EMA 异动信号记录 |