fix: add SignalHistoryItem and snapshots types to api.ts
This commit is contained in:
parent
f8201b3d8e
commit
c6801e061c
@ -1,19 +1,12 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState, useCallback } from "react";
|
||||
import { api } from "@/lib/api";
|
||||
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;
|
||||
@ -30,9 +23,8 @@ export default function LivePage() {
|
||||
|
||||
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 || [];
|
||||
const json = await api.snapshots(hours, 3600);
|
||||
const rows = json.data || [];
|
||||
setCount(json.count || 0);
|
||||
// 降采样:每30条取1条,避免图表过密
|
||||
const step = Math.max(1, Math.floor(rows.length / 300));
|
||||
|
||||
@ -37,6 +37,33 @@ export interface StatsResponse {
|
||||
combo: { mean7d: number; annualized: number };
|
||||
}
|
||||
|
||||
export interface SignalHistoryItem {
|
||||
id: number;
|
||||
symbol: string;
|
||||
rate: number;
|
||||
annualized: number;
|
||||
sent_at: string;
|
||||
message: string;
|
||||
}
|
||||
|
||||
export interface SignalsHistoryResponse {
|
||||
items: SignalHistoryItem[];
|
||||
}
|
||||
|
||||
export interface SnapshotItem {
|
||||
ts: number;
|
||||
btc_rate: number;
|
||||
eth_rate: number;
|
||||
btc_price: number;
|
||||
eth_price: number;
|
||||
}
|
||||
|
||||
export interface SnapshotsResponse {
|
||||
count: number;
|
||||
hours: number;
|
||||
data: SnapshotItem[];
|
||||
}
|
||||
|
||||
async function fetchAPI<T>(path: string): Promise<T> {
|
||||
const res = await fetch(`${API_BASE}${path}`, { cache: "no-store" });
|
||||
if (!res.ok) throw new Error(`API error ${res.status}`);
|
||||
@ -48,4 +75,7 @@ export const api = {
|
||||
history: () => fetchAPI<HistoryResponse>("/api/history"),
|
||||
stats: () => fetchAPI<StatsResponse>("/api/stats"),
|
||||
health: () => fetchAPI<{ status: string }>("/api/health"),
|
||||
signalsHistory: () => fetchAPI<SignalsHistoryResponse>("/api/signals/history"),
|
||||
snapshots: (hours = 24, limit = 5000) =>
|
||||
fetchAPI<SnapshotsResponse>(`/api/snapshots?hours=${hours}&limit=${limit}`),
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user