净值 / 档案 / 季报持仓 / 基金经理 / 排行 / 公告 / 分红 / 交易规则 / 评级 / 组合穿透 —— 19 个端点,免费端点无需 Key。
中文 · English
npm install @fundapi/sdk基金数据 API 的官方 Node.js / TypeScript SDK —— 19 个端点对应 19 个方法:鉴权、重试(含 429 自动退避)、错误映射、基金代码规范化、返回解析都由 SDK 处理,一行方法拿到结构化数据。
import { FundAPI } from "@fundapi/sdk";
const cli = new FundAPI({ key: "cf-你的Key" }); // 或环境变量 FUND_KEY
const data = await cli.fundProfile("110022");3 个端点无需 Key:fundSearch · fundProfile · fundScreenerOptions。
import { FundAPI } from "@fundapi/sdk";
const cli = new FundAPI(); // 免费端点,不用 Key
const found = await cli.fundSearch("易方达消费行业", 3); // 不知道代码时先搜
console.log(found.list);
const profile = await cli.fundProfile("110022"); // 基金档案付费端点:
const cli2 = new FundAPI({ key: "cf-你的Key" });
const nav = await cli2.fundNav("110022", { size: 5 });| 方法 | 端点 | 档位 |
|---|---|---|
fundSearch(q, limit=20) |
搜索基金 | 免费 |
fundProfile(code) |
基金档案 | 免费 |
fundScreenerOptions() |
筛选项字典 | 免费 |
fundNav(code, {page,size,start,end}) |
历史净值 | 专业版 |
fundHoldings(code, {year,quarter}) |
季报持仓 | 专业版 |
fundManagers(code) |
现任经理 | 专业版 |
fundRank({ft,sort,order,page,size}) |
全市场排行 | 专业版 |
fundNotices(code, {page,size}) |
基金公告 | 专业版 |
fundEstimate(code) |
当日估值 | 专业版 |
fundDividends(code) |
历史分红 | 专业版 |
fundTradeRule(code) |
交易规则 | 专业版 |
fundRating(code, {page,size}) |
评级 | 专业版 |
fundOverlap(codes) |
多基金持仓重叠 | 机构版 |
fundPortfolioXray(codes, weights) |
组合穿透到个股 | 机构版 |
fundHoldingChanges(code, {periods,top_n}) |
持仓变动 | 机构版 |
fundManagerHistory(code) |
基金经理历任 | 机构版 |
fundPortfolioDiagnose(codes, weights) |
组合诊断 | 机构版 |
fundScreener({...}) |
条件筛选全市场 | 机构版 |
fundCompare(codes) |
多基金对比 | 机构版 |
默认返回端点的 data 字段(结构因端点而异,见文档)。要完整信封(含 ok / tier / data 等):
const cli = new FundAPI({ raw: true });import { AuthError, RateLimitError, EmptyResultError, APIError } from "@fundapi/sdk";
try {
await cli.fundNav("110022");
} catch (e) {
if (e instanceof AuthError) { // Key 无效 / 档位不足
} else if (e instanceof RateLimitError) { // 超频,稍后再试
} else if (e instanceof EmptyResultError) { // 当前无数据(不扣次数)
} else if (e instanceof APIError) { // 其他错误,消息里带服务端原话
}
}仅在服务端使用 —— 浏览器里会暴露你的 API Key(本包刻意不提供浏览器构建)。
MIT