"use client"; import { useEffect, useState, useCallback } from "react"; import { LineChart, Line, XAxis, YAxis, Tooltip, Legend, ResponsiveContainer, ReferenceLine, CartesianGrid } from "recharts"; interface Snapshot { ts: number; btc_rate: number; eth_rate: number; btc_price: number; eth_price: number; } interface ChartPoint { time: string; btcRate: number; ethRate: number; btcPrice: number; ethPrice: number; } export default function LivePage() { const [data, setData] = useState([]); const [count, setCount] = useState(0); const [loading, setLoading] = useState(true); const [hours, setHours] = useState(2); const fetchSnapshots = useCallback(async () => { try { const r = await fetch(`/api/snapshots?hours=${hours}&limit=3600`); const json = await r.json(); const rows: Snapshot[] = json.data || []; setCount(json.count || 0); // 降采样:每30条取1条,避免图表过密 const step = Math.max(1, Math.floor(rows.length / 300)); const sampled = rows.filter((_, i) => i % step === 0); setData(sampled.map(row => ({ time: new Date(row.ts * 1000).toLocaleTimeString("zh-CN", { hour: "2-digit", minute: "2-digit" }), btcRate: parseFloat((row.btc_rate * 100).toFixed(5)), ethRate: parseFloat((row.eth_rate * 100).toFixed(5)), btcPrice: row.btc_price, ethPrice: row.eth_price, }))); } catch { /* ignore */ } finally { setLoading(false); } }, [hours]); useEffect(() => { fetchSnapshots(); const iv = setInterval(fetchSnapshots, 10_000); return () => clearInterval(iv); }, [fetchSnapshots]); return (

实时费率变动

8小时结算周期内的实时费率曲线 · 已记录 {count.toLocaleString()} 条快照

{[1, 2, 6, 12, 24].map(h => ( ))}
{loading ? (
加载中...
) : data.length === 0 ? (
暂无数据(后端刚启动,2秒后开始积累)
) : ( <> {/* 费率图 */}

资金费率实时变动

正值=多头付空头,负值=空头付多头。费率上升=多头情绪加热

`${v.toFixed(3)}%`} width={60} /> [`${Number(v).toFixed(5)}%`]} contentStyle={{ background: "#fff", border: "1px solid #e2e8f0", borderRadius: 8, fontSize: 12 }} />
{/* 价格图 */}

标记价格走势

与费率对比观察:价格快速拉升时,资金费率通常同步上涨(多头加杠杆)

`$${(v/1000).toFixed(0)}k`} width={55} /> `$${v.toFixed(0)}`} width={55} /> [name?.toString().includes("BTC") ? `$${Number(v).toLocaleString()}` : `$${Number(v).toFixed(2)}`, name]} contentStyle={{ background: "#fff", border: "1px solid #e2e8f0", borderRadius: 8, fontSize: 12 }} />
{/* 说明 */}
数据说明: 每2秒从Binance拉取实时溢价指数,本地永久存储。这是8小时结算周期内费率变动的原始数据,不在任何公开数据源中提供。
)}
); }