From cd56f6c1588f628ab48e8adcc3ec14609b515d1f Mon Sep 17 00:00:00 2001 From: Sakurasan <26715255+Sakurasan@users.noreply.github.com> Date: Mon, 10 Aug 2026 20:30:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=A0=B8=E5=BF=83=E8=82=A1=E5=8E=86?= =?UTF-8?q?=E5=8F=B2=E5=89=8D=E7=AB=AF=20API=20=E5=AE=A2=E6=88=B7=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/core-stock-api.ts | 47 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/lib/core-stock-api.ts 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(); +}