"use client"; import { useEffect, useState } from "react"; import { HistoryPoint } from "@/lib/api"; import { LineChart, Line, XAxis, YAxis, Tooltip, Legend, ResponsiveContainer, ReferenceLine } from "recharts"; export default function HistoryPage() { const [btc, setBtc] = useState([]); const [eth, setEth] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { fetch("/api/history") .then((r) => r.json()) .then((d) => { setBtc(d.BTC ?? []); setEth(d.ETH ?? []); setLoading(false); }) .catch(() => setLoading(false)); }, []); const btcMap = new Map(btc.map((p) => [p.timestamp.slice(0, 13), p.fundingRate * 100])); const ethMap = new Map(eth.map((p) => [p.timestamp.slice(0, 13), p.fundingRate * 100])); const allTimes = Array.from(new Set([...btcMap.keys(), ...ethMap.keys()])).sort(); const chartData = allTimes.slice(-42).map((t) => ({ time: t.slice(5).replace("T", " "), BTC: btcMap.get(t) ?? null, ETH: ethMap.get(t) ?? null, })); const tableData = allTimes.slice().reverse().slice(0, 50).map((t) => ({ time: t.replace("T", " "), btc: btcMap.get(t), eth: ethMap.get(t), })); return (

历史费率

过去7天 BTC / ETH 资金费率记录

{loading ? (
加载中...
) : ( <>

费率走势(过去7天)

`${v.toFixed(3)}%`} width={60} /> typeof v === "number" ? `${v.toFixed(4)}%` : v} contentStyle={{ background: "#1e293b", border: "1px solid #475569", borderRadius: 8 }} />
{tableData.map((row, i) => ( ))}
时间 BTC 费率 ETH 费率
{row.time} = 0 ? "text-emerald-400" : "text-red-400"}`}> {row.btc != null ? `${row.btc.toFixed(4)}%` : "--"} = 0 ? "text-emerald-400" : "text-red-400"}`}> {row.eth != null ? `${row.eth.toFixed(4)}%` : "--"}
)}
); }