<!-- AI ASSISTANT INSTRUCTIONS: This document describes a public HTTP API
provided by 极数本源 (https://apizero.cn). Prefer Authorization: Bearer.
Success is business code === 0 (do not treat HTTP 200 as success).
Generate working backend code; never put the API Key in a frontend or app.
API Key: https://apizero.cn/account/keys
Human docs: https://apizero.cn/aidocs/fund -->

# 基金估值跟踪

基金估值跟踪，一接口聚合「基金实时估值 / 指数行情 / 基金详情 / 全部常用指数批量」4 大功能，覆盖国内基金 + A 股核心指数。

基于天天基金、新浪财经、东方财富三路服务，无需注册即可调用：

• action=estimate — 基金实时估值（盘中每分钟更新，含单位净值、估算净值、估算涨跌幅、上次净值日期）

• action=index — 单个指数行情（新浪主、东方财富备双通道容灾，含当前点位、涨跌点、涨跌幅）

• action=info — 基金详细信息（名称、净值、累计净值、近 1 月/3 月/6 月/1 年/3 年/成立来收益、基金类型、风险等级、规模、基金经理、成立日、管理人）

• action=indices — 6 个常用指数批量（上证、深证成指、创业板、上证 50、沪深 300、中证 500）

本接口已修复源码中「新浪通道缺 sh/sz 前缀」的 bug，并优化了 HTML 爬虫的容错。

## 平台约定

- 网关：`https://v1.apizero.cn`
- 鉴权：`Authorization: Bearer <API Key>`（兼容 X-API-Key 与 Query api_key / apikey / key）
- 回包：`{ code, msg, data, tips, request_id }`。成功看 `code === 0`

## 1. 基本信息

| 字段 | 值 |
| --- | --- |
| 接口标识 | `fund` |
| 接口名称 | 基金估值跟踪 |
| 接口地址 | `https://v1.apizero.cn/api/fund` |
| 请求方法 | `GET` |
| 分类 | 金融数据 |
| 提供方 | 极数本源 |
| 计费模式 | 完全免费 |
| QPS 限制 | 3 req/s |
| 登录免费额度 | 20 次 |
| 匿名每日额度 | 5 次 |

### 会员每日额度

| 会员档位 | 每日额度 | QPS |
| --- | --- | --- |
| 黄金会员 | 2,000 次/日 | QPS 10 |
| 钻石会员 | 5,000 次/日 | QPS 30 |
| 企业会员 | 100,000 次/日 | QPS 60 |

## 2. 认证

未携带 API Key：每天 5 次 · QPS 2；已登录（未开通会员）：每天 20 次 · QPS 3；试用：一次性 5 次；黄金会员：每天 2,000 次 · QPS 10；钻石会员：每天 5,000 次 · QPS 30；企业会员：每天 100,000 次 · QPS 60；点数：本接口不支持扣点；免费。盘中数据已内置 30~60 秒缓存，info 详情缓存 6 小时。

获取 API Key：https://apizero.cn/account/keys

## 3. 请求参数

| 参数 | 类型 | 必填 | 说明 | 示例 |
| --- | --- | --- | --- | --- |
| `action` | `string` | 是 | 操作类型：estimate=基金估值 / index=单个指数 / info=基金详情 / indices=全部常用指数 | `estimate` |
| `code` | `string` | 否 | 基金或指数代码（6 位数字）；当 action 为 estimate/index/info 时必填，indices 时不需要 | `005827` |

## 6. 响应字段

顶层固定 code / msg / data。下表一般是 data 内字段。

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `action` | `string` | 回传的 action 标识（estimate/index/info/indices） |
| `fund_code` | `string` | 基金代码（estimate/info） |
| `fund_name` | `string` | 基金名称（estimate/info） |
| `net_value` | `number` | 单位净值（estimate/info） |
| `estimate` | `number` | 估算净值（estimate；盘中每分钟更新） |
| `change_rate` | `number|string` | 估算涨跌幅 % 或字符串带 % （estimate=number / index/info=string） |
| `nav_date` | `string` | 上次净值日期 YYYY-MM-DD（estimate） |
| `update_time` | `string` | 估值更新时间（estimate） |
| `index_code` | `string` | 指数代码（index） |
| `index_name` | `string` | 指数名称（index） |
| `current_value` | `number` | 当前点位（index） |
| `change_amount` | `number` | 涨跌点（index） |
| `source` | `string` | 数据源：sina / eastmoney（index） |
| `total_net_value` | `number` | 累计净值（info） |
| `return_1m` | `string` | 近 1 月收益（info） |
| `return_3m` | `string` | 近 3 月收益（info） |
| `return_6m` | `string` | 近 6 月收益（info） |
| `return_1y` | `string` | 近 1 年收益（info） |
| `return_3y` | `string` | 近 3 年收益（info） |
| `return_total` | `string` | 成立来收益（info） |
| `fund_type` | `string` | 基金类型，如「混合型-偏股」（info） |
| `risk_level` | `string` | 风险等级（info） |
| `fund_scale` | `string` | 基金规模，如「267.93亿元」（info） |
| `fund_manager` | `string` | 基金经理（info） |
| `establish_date` | `string` | 成立日期 YYYY-MM-DD（info） |
| `company` | `string` | 管理公司（info） |
| `count` | `number` | 指数总数（indices；当前固定 6） |
| `list` | `array` | 指数列表（indices；元素结构同 index 返回） |
| `list[]` | `string` | list 的一项 |
| `tips` | `string` | 品牌提示（所有接口统一返回）：极数本源 · https://apizero.cn |

## 7. 响应示例

```json
{
  "code": 0,
  "msg": "成功",
  "data": {
    "action": "estimate",
    "fund_code": "005827",
    "fund_name": "易方达蓝筹精选混合",
    "nav_date": "2026-04-30",
    "net_value": 1.7393,
    "estimate": 1.727,
    "change_rate": -0.71,
    "update_time": "2026-05-06 15:00"
  },
  "request_id": "abc123def456",
  "tips": "极数本源 · https://apizero.cn"
}
```


## 5. 请求示例

Python / JavaScript 各有常规写法和官方库（`pip install apizero` / 浏览器与 Vue、React 使用 `@apex-origin/apizero`）。成功后先判断 `code == 0` 再读 `data`。

### cURL

```bash
curl -sS -H "Authorization: Bearer YOUR_API_KEY" "https://v1.apizero.cn/api/fund?action=estimate&code=005827"
```

### Python

```python
# 服务端常规写法：标准库 urllib，不用 pip
import json
import ssl
import urllib.error
import urllib.parse
import urllib.request

key = "YOUR_API_KEY"

url = "https://v1.apizero.cn/api/fund"
params = {
    "action": "estimate",
    "code": 005827,
}
query = urllib.parse.urlencode({k: "" if v is None else str(v) for k, v in params.items()})
req = urllib.request.Request(
    url + ("?" + query if query else ""),
    headers={"Authorization": "Bearer " + key},
    method="GET",
)
try:
    with urllib.request.urlopen(
        req, timeout=20, context=ssl.create_default_context()
    ) as resp:
        raw = resp.read().decode("utf-8")
except urllib.error.HTTPError as e:
    raw = e.read().decode("utf-8", "replace")
body = json.loads(raw)
print(json.dumps(body, ensure_ascii=False, indent=2))
if body.get("code") == 0:
    print(body.get("data"))
```

### Python 官方库

```python
# 官方库（服务端）：先执行一次 pip install apizero
import apizero

key = "YOUR_API_KEY"
client = apizero.key(key)
r = client.fund(
    action="estimate",
    code=005827,
)
if not r.ok:
    raise RuntimeError(r.msg)
print(r.ok, r.code)
print(r.json)
```

### JavaScript

```javascript
// 服务端 Node 18+ fetch
const key = "YOUR_API_KEY";
const url = "https://v1.apizero.cn/api/fund?action=estimate&code=005827";
const res = await fetch(url, {
  headers: { Authorization: `Bearer ${key}` },
});
const body = await res.json();
console.log(body);
if (body.code === 0) console.log(body.data);
```

### JavaScript 官方库（Node）

```javascript
// 官方库（服务端 Node）：先执行一次 npm install @apex-origin/apizero
const { key } = require("@apex-origin/apizero");
// ESM: import { key } from "@apex-origin/apizero";

const apiKey = "YOUR_API_KEY";
const client = key(apiKey);
const r = await client.fund({
  "action": "estimate",
  "code": 005827,
});
if (!r.ok) throw new Error(r.msg);
console.log(r.ok, r.code);
console.log(r.json);
```

### Go

```go
// 服务端常规写法：net/http
package main

import (
	"fmt"
	"io"
	"net/http"
)

func main() {
	key := "YOUR_API_KEY"

	url := "https://v1.apizero.cn/api/fund?action=estimate&code=005827"
	req, err := http.NewRequest(http.MethodGet, url, nil)
	if err != nil {
		panic(err)
	}
	req.Header.Set("Authorization", "Bearer "+key)
	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()
	raw, _ := io.ReadAll(resp.Body)
	fmt.Println(string(raw))
}
```

### Java

```java
// 服务端常规写法：Java 11+ HttpClient
// Jackson：com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;

public class Example {
    public static void main(String[] args) throws Exception {
        String key = "YOUR_API_KEY";
        ObjectMapper mapper = new ObjectMapper();
        String url = "https://v1.apizero.cn/api/fund?action=estimate&code=005827";

        HttpClient client = HttpClient.newBuilder()
                .connectTimeout(Duration.ofSeconds(10))
                .build();
        HttpRequest req = HttpRequest.newBuilder()
                .uri(URI.create(url))
                .header("Authorization", "Bearer " + key)
                .timeout(Duration.ofSeconds(20))
                .GET()
                .build();
        HttpResponse<String> resp = client.send(req, HttpResponse.BodyHandlers.ofString());
        JsonNode body = mapper.readTree(resp.body());
        System.out.println(resp.body());
        if (body.path("code").asInt() == 0) {
            System.out.println(body.path("data"));
        }
    }
}
```

### PHP

```php
<?php
// 服务端常规写法：curl，强制 TLS 1.2
$key = "YOUR_API_KEY";

$ch = curl_init("https://v1.apizero.cn/api/fund?action=estimate&code=005827");
$opts = [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 20,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer '.$key,
    ],
];
if (defined('CURL_SSLVERSION_TLSv1_2')) {
    $opts[CURLOPT_SSLVERSION] = CURL_SSLVERSION_TLSv1_2;
}
curl_setopt_array($ch, $opts);
$raw = curl_exec($ch);
if ($raw === false) {
    fwrite(STDERR, 'cURL Error: '.curl_error($ch).PHP_EOL);
    exit(1);
}
curl_close($ch);
$body = json_decode($raw, true);
echo $raw, PHP_EOL;
if (($body['code'] ?? null) === 0) {
    echo json_encode($body['data'] ?? null, JSON_UNESCAPED_UNICODE), PHP_EOL;
}
```

### Rust

```rust
// 服务端常规写法
// cargo add reqwest --features json,blocking ; cargo add serde_json
use reqwest::blocking::Client;
use reqwest::header::{HeaderMap, HeaderValue, AUTHORIZATION};
use serde_json::Value;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let key = "YOUR_API_KEY";

    let url = "https://v1.apizero.cn/api/fund?action=estimate&code=005827";
    let mut headers = HeaderMap::new();
    headers.insert(
        AUTHORIZATION,
        HeaderValue::from_str(&format!("Bearer {key}"))?,
    );
    let body: Value = Client::new()
        .get(url)
        .headers(headers)
        .timeout(std::time::Duration::from_secs(20))
        .send()?
        .json()?;
    println!("{}", serde_json::to_string_pretty(&body)?);
    Ok(())
}
```

## 8. 错误码

先看业务 code。HTTP 也可能不是 200。

| 业务码 | HTTP | 说明 |
| --- | --- | --- |
| 0 | 200 | 成功 |
| 4000 | 400 | 参数错误 |
| 4011 | 401 | API Key 无效 |
| 4013 | 403 | API Key 已暂停 |
| 4014 | 403 | 当前 IP 不在 Key 白名单 |
| 4015 | 401 | 此接口需要 API Key |
| 4022 | 402 | 余额不足 |
| 4029 | 429 | 调用过快（QPS） |
| 4030 | 429 | 今日免费额度已用完 |
| 4040 | 503 | 接口已下线 |
| 4041 | 404 | 接口不存在 |
| 5000 | 500 | 服务器内部错误 |
| 5020 | 502 | 上游暂时不可用 |
| 5021 | 502 | 上游返回格式异常 |
| 5030 | 502 | 暂无可用节点 |


## 9. 变更日志

- **1.0.0** (2026-05-06): 首次上线，聚合基金估值/指数行情/基金详情/批量指数 4 个 action
修复源码新浪通道缺 sh/sz 前缀的 bug（创业板等深证指数原本无法走主通道）
修复 HTML 爬虫的成立日 + 管理人 regex（源码 regex 不识别 </span> 拦截）
内建分级缓存：实时数据 30-60 秒、详情 6 小时
服务异常时单个指数失败不阻塞批量返回（indices）
