feat: 核心股历史前端 API 客户端

This commit is contained in:
Sakurasan
2026-08-10 20:30:28 +08:00
parent c58bd990fd
commit cd56f6c158
+47
View File
@@ -0,0 +1,47 @@
// 核心股历史数据获取工具
import { getApiBaseUrl } from "@/lib/api-client";
export interface ActiveCoreStock {
stockCode: string;
stockName: string;
dailyGains: Record<string, number>; // 日期 -> 当日涨幅
appearCount: number;
lastAppear: string | null;
}
export interface ActiveCoreStocksResponse {
dates: string[];
stocks: ActiveCoreStock[];
}
export interface CoreStockHistoryItem {
id: number;
trade_date: string;
stock_code: string;
stock_name: string;
f3: number | null;
cover_count: number | null;
rank: number;
themes: { theme_code: string; theme_name: string }[];
}
export interface CoreStockHistoryResponse {
date: string;
items: CoreStockHistoryItem[];
}
/** 获取活跃核心股 + 最近10日涨幅矩阵 */
export async function fetchActiveCoreStocks(): Promise<ActiveCoreStocksResponse> {
const baseUrl = getApiBaseUrl();
const resp = await fetch(`${baseUrl}/api/core-stocks/active`, { method: "GET", cache: "no-store" });
if (!resp.ok) return { dates: [], stocks: [] };
return resp.json();
}
/** 获取指定交易日核心股(含所属题材) */
export async function fetchCoreStockHistory(date: string): Promise<CoreStockHistoryResponse | null> {
const baseUrl = getApiBaseUrl();
const resp = await fetch(`${baseUrl}/api/core-stocks/history?date=${date}`, { method: "GET", cache: "no-store" });
if (!resp.ok) return null;
return resp.json();
}