"use client"; import { useEffect, useState, useCallback } from "react"; import { authFetch } from "@/lib/auth"; import { useAuth } from "@/lib/auth"; import Link from "next/link"; import { ComposedChart, Area, Line, XAxis, YAxis, Tooltip, ResponsiveContainer, ReferenceLine, CartesianGrid, Legend } from "recharts"; type Symbol = "BTC" | "ETH" | "XRP" | "SOL"; interface IndicatorRow { ts: number; cvd_fast: number; cvd_mid: number; cvd_day: number; atr_5m: number; vwap_30m: number; price: number; score: number; signal: string | null; } interface LatestIndicator { ts: number; cvd_fast: number; cvd_mid: number; cvd_day: number; cvd_fast_slope: number; atr_5m: number; atr_percentile: number; vwap_30m: number; price: number; p95_qty: number; p99_qty: number; score: number; signal: string | null; tier?: "light" | "standard" | "heavy" | null; factors?: { direction?: { score?: number; max?: number }; crowding?: { score?: number; max?: number }; environment?: { score?: number; max?: number }; confirmation?: { score?: number; max?: number }; auxiliary?: { score?: number; max?: number }; funding_rate?: { score?: number; max?: number; value?: number }; liquidation?: { score?: number; max?: number; long_usd?: number; short_usd?: number }; } | null; } interface MarketIndicatorValue { value: Record; ts: number; } interface MarketIndicatorSet { long_short_ratio?: MarketIndicatorValue; top_trader_position?: MarketIndicatorValue; open_interest_hist?: MarketIndicatorValue; coinbase_premium?: MarketIndicatorValue; } const WINDOWS = [ { label: "1h", value: 60 }, { label: "4h", value: 240 }, { label: "12h", value: 720 }, { label: "24h", value: 1440 }, ]; function bjtStr(ms: number) { const d = new Date(ms + 8 * 3600 * 1000); return `${String(d.getUTCHours()).padStart(2, "0")}:${String(d.getUTCMinutes()).padStart(2, "0")}`; } function fmt(v: number, decimals = 1): string { if (Math.abs(v) >= 1000000) return `${(v / 1000000).toFixed(1)}M`; if (Math.abs(v) >= 1000) return `${(v / 1000).toFixed(1)}K`; return v.toFixed(decimals); } function LayerScore({ label, score, max, colorClass }: { label: string; score: number; max: number; colorClass: string }) { const ratio = Math.max(0, Math.min((score / max) * 100, 100)); return (
{label}
{score}/{max}
); } function MarketIndicatorsCards({ symbol }: { symbol: Symbol }) { const [data, setData] = useState(null); useEffect(() => { const fetch = async () => { try { const res = await authFetch("/api/signals/market-indicators"); if (!res.ok) return; const json = await res.json(); setData(json[symbol] || null); } catch {} }; fetch(); const iv = setInterval(fetch, 5000); return () => clearInterval(iv); }, [symbol]); if (!data) return
等待市场指标数据...
; // value可能是JSON字符串或对象,统一解析 const parseVal = (v: unknown): Record => { if (!v) return {}; if (typeof v === "string") { try { return JSON.parse(v); } catch { return {}; } } if (typeof v === "object") return v as Record; return {}; }; const lsVal = parseVal(data.long_short_ratio?.value); const topVal = parseVal(data.top_trader_position?.value); const oiVal = parseVal(data.open_interest_hist?.value); const premVal = parseVal(data.coinbase_premium?.value); const longPct = Number(lsVal?.longAccount ?? 0.5) * 100; const shortPct = Number(lsVal?.shortAccount ?? 0.5) * 100; const topLong = Number(topVal?.longAccount ?? 0.5) * 100; const topShort = Number(topVal?.shortAccount ?? 0.5) * 100; const oiValue = Number(oiVal?.sumOpenInterestValue ?? 0); const oiDisplay = oiValue >= 1e9 ? `$${(oiValue / 1e9).toFixed(2)}B` : oiValue >= 1e6 ? `$${(oiValue / 1e6).toFixed(0)}M` : `$${oiValue.toFixed(0)}`; const premium = Number(premVal?.premium_pct ?? 0); return (

多空比

L:{longPct.toFixed(1)}% S:{shortPct.toFixed(1)}%

大户持仓

多{topLong.toFixed(1)}% {topLong >= 55 ? "📈" : topLong <= 45 ? "📉" : "➖"}

OI

{oiDisplay}

CB Premium

= 0 ? "text-emerald-600" : "text-red-500"}`}>{premium >= 0 ? "+" : ""}{premium.toFixed(4)}%

); } // ─── 信号历史 ──────────────────────────────────────────────────── interface SignalRecord { ts: number; score: number; signal: string; } function bjtFull(ms: number) { const d = new Date(ms + 8 * 3600 * 1000); return `${String(d.getUTCMonth() + 1).padStart(2, "0")}-${String(d.getUTCDate()).padStart(2, "0")} ${String(d.getUTCHours()).padStart(2, "0")}:${String(d.getUTCMinutes()).padStart(2, "0")}:${String(d.getUTCSeconds()).padStart(2, "0")}`; } function SignalHistory({ symbol }: { symbol: Symbol }) { const [data, setData] = useState([]); useEffect(() => { const fetchData = async () => { try { const res = await authFetch(`/api/signals/signal-history?symbol=${symbol}&limit=20`); if (!res.ok) return; const json = await res.json(); setData(json.data || []); } catch {} }; fetchData(); const iv = setInterval(fetchData, 15000); return () => clearInterval(iv); }, [symbol]); if (data.length === 0) return null; return (

最近信号

{data.map((s, i) => (
{s.signal === "LONG" ? "🟢 LONG" : "🔴 SHORT"} {bjtFull(s.ts)}
{s.score} = 85 ? "bg-red-100 text-red-700" : s.score >= 75 ? "bg-blue-100 text-blue-700" : "bg-slate-100 text-slate-600" }`}> {s.score >= 85 ? "加仓" : s.score >= 75 ? "标准" : "不开仓"}
))}
); } // ─── 实时指标卡片 ──────────────────────────────────────────────── function IndicatorCards({ symbol }: { symbol: Symbol }) { const [data, setData] = useState(null); useEffect(() => { const fetch = async () => { try { const res = await authFetch("/api/signals/latest"); if (!res.ok) return; const json = await res.json(); setData(json[symbol] || null); } catch {} }; fetch(); const iv = setInterval(fetch, 5000); return () => clearInterval(iv); }, [symbol]); if (!data) return
等待指标数据...
; const cvdMidDir = data.cvd_mid > 0 ? "多" : "空"; const priceVsVwap = data.price > data.vwap_30m ? "上方" : "下方"; return (
{/* CVD三轨 - 紧凑一行 */}

CVD_fast (30m)

= 0 ? "text-emerald-600" : "text-red-500"}`}> {fmt(data.cvd_fast)}

斜率: = 0 ? "text-emerald-600" : "text-red-500"}> {data.cvd_fast_slope >= 0 ? "↑" : "↓"}{fmt(Math.abs(data.cvd_fast_slope))}

CVD_mid (4h)

= 0 ? "text-emerald-600" : "text-red-500"}`}> {fmt(data.cvd_mid)}

{cvdMidDir}头占优

CVD_day

= 0 ? "text-emerald-600" : "text-red-500"}`}> {fmt(data.cvd_day)}

盘中基线

{/* ATR + VWAP + 大单 - 4列紧凑 */}

ATR

${fmt(data.atr_5m, 2)}

60 ? "text-amber-600 font-semibold" : "text-slate-400"}> {data.atr_percentile.toFixed(0)}%{data.atr_percentile > 60 ? "🔥" : ""}

VWAP

${data.vwap_30m.toLocaleString("en-US", { maximumFractionDigits: 1 })}

价格在 data.vwap_30m ? "text-emerald-600" : "text-red-500"}>{priceVsVwap}

P95

{data.p95_qty.toFixed(4)}

大单阈值

P99

{data.p99_qty.toFixed(4)}

超大单

{/* 信号状态(V5.2)- 七层 */}

当前信号

{data.signal === "LONG" ? "🟢 做多" : data.signal === "SHORT" ? "🔴 做空" : "⚪ 无信号"}

{data.score}/100

{data.tier === "heavy" ? "加仓" : data.tier === "standard" ? "标准" : "不开仓"}

); } // ─── CVD三轨图 ────────────────────────────────────────────────── function CVDChart({ symbol, minutes }: { symbol: Symbol; minutes: number }) { const [data, setData] = useState([]); const [loading, setLoading] = useState(true); const fetchData = useCallback(async (silent = false) => { try { const res = await authFetch(`/api/signals/indicators?symbol=${symbol}&minutes=${minutes}`); if (!res.ok) return; const json = await res.json(); setData(json.data || []); if (!silent) setLoading(false); } catch {} }, [symbol, minutes]); useEffect(() => { setLoading(true); fetchData(); const iv = setInterval(() => fetchData(true), 30000); return () => clearInterval(iv); }, [fetchData]); const chartData = data.map(d => ({ time: bjtStr(d.ts), fast: parseFloat(d.cvd_fast?.toFixed(2) || "0"), mid: parseFloat(d.cvd_mid?.toFixed(2) || "0"), price: d.price, })); // 价格轴自适应 const prices = chartData.map(d => d.price).filter(v => v > 0); const pMin = prices.length ? Math.min(...prices) : 0; const pMax = prices.length ? Math.max(...prices) : 0; const pPad = (pMax - pMin) * 0.3 || pMax * 0.001; if (loading) return
加载指标数据...
; if (data.length === 0) return
暂无指标数据,signal-engine需运行积累
; return ( v >= 1000 ? `$${(v / 1000).toFixed(1)}k` : `$${v.toFixed(0)}`} /> { if (name === "price") return [`$${Number(v).toLocaleString()}`, "币价"]; if (name === "fast") return [fmt(Number(v)), "CVD_fast(30m)"]; return [fmt(Number(v)), "CVD_mid(4h)"]; }} contentStyle={{ background: "#fff", border: "1px solid #e2e8f0", borderRadius: 8, fontSize: 11 }} /> ); } // ─── 主页面 ────────────────────────────────────────────────────── export default function SignalsV52Page() { const { isLoggedIn, loading } = useAuth(); const [symbol, setSymbol] = useState("BTC"); const [minutes, setMinutes] = useState(240); if (loading) return
加载中...
; if (!isLoggedIn) return (
🔒

请先登录查看信号数据

登录 注册
); return (
{/* 标题 */}

⚡ 信号引擎 V5.2

七层信号评分 · 包含 Funding Rate / Liquidation 维度

{(["BTC", "ETH", "XRP", "SOL"] as Symbol[]).map(s => ( ))}
{/* 实时指标卡片 */} {/* Market Indicators */}

Market Indicators

{/* 信号历史 */} {/* CVD三轨图 */}

CVD三轨 + 币价

蓝=fast(30m) · 紫=mid(4h) · 橙=价格

{WINDOWS.map(w => ( ))}
{/* 说明 */}

📖 七层信号源说明(V5.2)

1️⃣ 方向层(40分) — 钱往哪流?

CVD三轨(30m/4h资金流向)+ P99大单流(鲸鱼动向)+ 加速度奖励。两条CVD同向+大单配合 = 高分。

2️⃣ 拥挤层(20分) — 散户在干嘛?反着来

多空比(散户仓位)+ 大户持仓比。散户疯狂做多→做空加分,跟大户同向加分。

3️⃣ FR层(5分) — 费率拥挤是否极端?

Funding Rate偏离越极端,反向信号权重越高;用于过滤高拥挤下的追涨杀跌。

4️⃣ 环境层(15分) — 有没有新钱进场?

OI变化率(未平仓合约)。OI上涨=新资金进场=趋势延续;OI下降=资金撤离。

5️⃣ 确认层(15分) — 多周期共振吗?

CVD_fast(30m)和CVD_mid(4h)方向一致=高确信度满分15;方向矛盾=0分。

6️⃣ 清算层(5分) — 清算热点是否共振?

多空清算金额不对称时为反向提供弹性加权,帮助识别踩踏与挤空/挤多机会。

7️⃣ 辅助层(5分) — 美国机构在干嘛?

Coinbase Premium(CB vs 币安价差)。正溢价=机构买入=做多加分;负溢价=机构卖出。

档位:<75不开仓 · 75-84标准 · ≥85加仓 · 冷却10分钟
); }