净值 / 档案 / 季报持仓 / 基金经理 / 排行 / 公告 / 分红 / 交易规则 / 评级 / 组合穿透 —— 19 个端点,免费端点无需 Key。
中文 · English
pip install fundapi基金数据 API 的官方 Python SDK —— 19 个端点对应 19 个方法:鉴权、重试(含 429 自动退避)、错误映射、基金代码规范化、返回解析都由 SDK 处理,一行方法拿到结构化数据。
from fundapi import FundAPI
api = FundAPI(key="cf-你的Key") # 或用环境变量 FUND_KEY
print(api.fund_profile("110022")) # 基金档案3 个端点无需 Key(装上就能调):fund_search · fund_profile · fund_screener_options。其余需要 Key(获取)。
from fundapi import FundAPI
api = FundAPI() # 免费端点,不用 Key
# 按名字搜基金(不知道代码时先搜)
for f in api.fund_search("易方达消费行业", limit=3)["list"]:
print(f["code"], f["name"])
# 基金档案
print(api.fund_profile("110022"))付费端点:
api = FundAPI(key="cf-你的Key")
print(api.fund_nav("110022", size=5)) # 历史净值
print(api.fund_rating("110022")) # 评级| 方法 | 端点 | 档位 |
|---|---|---|
fund_search(q, limit=20) |
搜索基金 | 免费 |
fund_profile(code) |
基金档案 | 免费 |
fund_screener_options() |
筛选项字典 | 免费 |
fund_nav(code, page=1, size=20, start="", end="") |
历史净值 | 专业版 |
fund_holdings(code, year="", quarter="") |
季报持仓 | 专业版 |
fund_managers(code) |
现任经理 | 专业版 |
fund_rank(ft="all", sort="1y", order="desc", page=1, size=50) |
全市场排行 | 专业版 |
fund_notices(code, page=1, size=20) |
基金公告 | 专业版 |
fund_estimate(code) |
当日估值 | 专业版 |
fund_dividends(code) |
历史分红 | 专业版 |
fund_trade_rule(code) |
交易规则 | 专业版 |
fund_rating(code, page=1, size=20) |
评级 | 专业版 |
fund_overlap(codes) |
多基金持仓重叠 | 机构版 |
fund_portfolio_xray(codes, weights) |
组合穿透到个股 | 机构版 |
fund_holding_changes(code, periods=4, top_n=10) |
持仓变动 | 机构版 |
fund_manager_history(code) |
基金经理历任 | 机构版 |
fund_portfolio_diagnose(codes, weights) |
组合诊断 | 机构版 |
fund_screener(...) |
条件筛选全市场 | 机构版 |
fund_compare(codes) |
多基金对比 | 机构版 |
默认返回端点的 data 字段(结构因端点而异,见文档)。要完整信封(含 ok / tier / data 等):
api = FundAPI(raw=True)from fundapi import AuthError, RateLimitError, EmptyResultError, APIError
try:
api.fund_nav("110022")
except AuthError:
... # Key 无效 / 档位不足(去 https://fundapi.cn/pricing 升级)
except RateLimitError:
... # 超频,稍后再试
except EmptyResultError:
... # 当前无数据(不扣次数)
except APIError:
... # 其他错误,消息里带服务端原话- Python 3.9+
- 依赖:
requests
MIT