"use client"; import { useEffect, useState, useCallback } from "react"; import { authFetch } from "@/lib/auth"; import { ComposedChart, Area, Line, XAxis, YAxis, Tooltip, ResponsiveContainer, ReferenceLine, CartesianGrid, Legend } from "recharts"; 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; gate_passed?: boolean; factors?: { gate_passed?: boolean; gate_block?: string; block_reason?: string; obi_raw?: number; spot_perp_div?: number; whale_cvd_ratio?: number; atr_pct_price?: number; direction?: { score?: number; max?: number }; crowding?: { score?: number; max?: number }; environment?: { score?: number; max?: number }; auxiliary?: { score?: number; max?: number }; } | null; } interface SignalRecord { ts: number; score: number; signal: string; } interface Gates { obi_threshold: number; whale_usd_threshold: number; whale_flow_pct: number; vol_atr_pct_min: number; spot_perp_threshold: number; } interface Weights { direction: number; env: number; aux: number; momentum: number; } interface Props { strategyId: string; symbol: string; cvdFastWindow: string; cvdSlowWindow: string; weights: Weights; gates: Gates; } 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 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 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 (
🔒 Gate-Control
{passed ? "✅ Gate通过" : "❌ 否决"}波动率
{((factors.atr_pct_price ?? 0) * 100).toFixed(3)}%
需 ≥{(gates.vol_atr_pct_min * 100).toFixed(2)}%
OBI
= 0 ? "text-emerald-600" : "text-red-500"}`}> {((factors.obi_raw ?? 0) * 100).toFixed(2)}%
否决±{gates.obi_threshold}
期现背离
= 0 ? "text-emerald-600" : "text-red-500"}`}> {((factors.spot_perp_div ?? 0) * 10000).toFixed(2)}bps
否决±{(gates.spot_perp_threshold * 100).toFixed(1)}%
鲸鱼
${(gates.whale_usd_threshold / 1000).toFixed(0)}k
{">"}{(gates.whale_flow_pct * 100).toFixed(0)}%占比
否决原因: {blockReason}
)}CVD_fast ({cvdFastWindow})
= 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_slow ({cvdSlowWindow})
= 0 ? "text-emerald-600" : "text-red-500"}`}> {fmt(data.cvd_mid)}
{data.cvd_mid > 0 ? "多" : "空"}头占优
CVD共振
= 0 && data.cvd_mid >= 0 ? "text-emerald-600" : data.cvd_fast < 0 && data.cvd_mid < 0 ? "text-red-500" : "text-slate-400"}`}> {data.cvd_fast >= 0 && data.cvd_mid >= 0 ? "✅ 多头共振" : data.cvd_fast < 0 && data.cvd_mid < 0 ? "✅ 空头共振" : "⚠️ 分歧"}
双周期共振
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) ?? "-"}
超大单
四层评分 · {coin}
{data.signal === "LONG" ? "🟢 做多" : data.signal === "SHORT" ? "🔴 做空" : "⚪ 无信号"}
{data.score}/{totalWeight}
{data.tier === "heavy" ? "加仓" : data.tier === "standard" ? "标准" : "不开仓"}
CVD {cvdFastWindow}/{cvdSlowWindow} · 权重 {weights.direction}/{weights.env}/{weights.aux}/{weights.momentum} · {coin}
蓝=fast({cvdFastWindow}) · 紫=slow({cvdSlowWindow}) · 橙=价格