diff --git a/src/lib/core-stock-api.ts b/src/lib/core-stock-api.ts new file mode 100644 index 0000000..11b661e --- /dev/null +++ b/src/lib/core-stock-api.ts @@ -0,0 +1,47 @@ +// 核心股历史数据获取工具 +import { getApiBaseUrl } from "@/lib/api-client"; + +export interface ActiveCoreStock { + stockCode: string; + stockName: string; + dailyGains: Record; // 日期 -> 当日涨幅 + 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 { + 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 { + 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(); +}