agentleFS
Aias00Aias00/agent-skills/fund-query/SKILL.md

fund-query

Skill2 starsChanged 8 months agoApache-2.0View on GitHub

查询中国基金净值和涨跌幅的专用技能。使用天天基金网公开API,免费、实时、无需授权。 获取基金的净值、涨跌幅、更新时间等关键信息,用于投资决策和资产组合管理。

The file

Files
SKILL.md

Fund Query - 基金净值查询技能

查询中国基金净值和涨跌幅的专用技能。使用天天基金网公开API,免费、实时、无需授权。


功能说明

获取基金的净值、涨跌幅、更新时间等关键信息,用于投资决策和资产组合管理。

数据来源

  • API地址: http://fundgz.1234567.com.cn/js/{基金代码}.js
  • 提供商: 天天基金网(www.1234567.com.cn)
  • 授权: 公开免费API,无需API Key
  • 更新频率: 每交易日更新
    • 05:00: 估算净值更新
    • 15:00+: 官方净值确认

API特性

特性说明
成本免费
授权无需注册/授权
延迟实时(估算)+ 官方确认
限制无明确的请求限制
数据官方净值 + 实时估算净值

核心数据字段

字段英文key类型说明
基金代码fundcodestring基金代码
基金名称namestring基金全称
单位净值dwjzfloat官方确认净值(最准确)
净值日期jzrqstring官方净值日期(YYYY-MM-DD)
估算净值gszfloat实时估算净值(仅供参考)
涨跌幅gszzlstring涨跌幅百分比(格式: "+1.23" 或 "-0.45")
更新时间gztimestring数据更新时间

数据可信度

  • 单位净值(dwjz): 100%可信 - 官方确认净值
  • 估算净值(gsz): 90%可信 - 基于持仓实时计算
  • 涨跌幅(gszzl): 90%可信 - 基于估算净值计算

使用方法

1. 单只基金查询

Python示例:

import requests
import json
import re

def fetch_fund_data(fund_code):
    """获取单只基金的净值数据"""
    url = f"http://fundgz.1234567.com.cn/js/{fund_code}.js"
    headers = {"User-Agent": "Mozilla/5.0"}

    try:
        response = requests.get(url, headers=headers, timeout=10)
        response.raise_for_status()

        text = response.text

        # 检查是否有数据
        if 'jsonpgz()' in text or not 'jsonpgz(' in text:
            return None

        # 解析JSONP格式: jsonpgz({...});
        json_str = re.findall(r'jsonpgz\((.*?)\);', text)[0]
        data = json.loads(json_str)

        # 解析涨跌幅(字符串格式)
        change_str = data.get('gszzl', '0')
        try:
            change_pct = float(change_str)
        except:
            change_pct = 0.0

        return {
            'fund_code': fund_code,
            'fund_name': data.get('name', ''),
            'nav': float(data.get('dwjz', 0)),          # 单位净值
            'nav_date': data.get('jzrq', ''),            # 净值日期
            'estimated_nav': float(data.get('gsz', 0)),  # 估算净值
            'change_pct': change_pct,
            'update_time': data.get('gztime', '')
        }
    except Exception as e:
        print(f"获取基金 {fund_code} 数据失败: {e}")
        return None

# 使用示例
data = fetch_fund_data('016452')
if data:
    print(f"基金: {data['fund_name']}")
    print(f"官方净值: {data['nav']} (截至 {data['nav_date']})")
    print(f"估算净值: {data['estimated_nav']}")
    print(f"涨跌幅: {data['change_pct']:+.2f}%")
    print(f"更新时间: {data['update_time']}")

输出示例:

基金: 南方纳斯达克100指数发起(QDII)A
官方净值: 1.9997 (截至 2026-02-26)
估算净值: 1.9941
涨跌幅: -0.28%
更新时间: 2026-02-28 05:00

2. 批量查询多只基金

def fetch_multiple_funds(fund_codes):
    """批量获取多只基金的净值数据"""
    results = []
    for code in fund_codes:
        data = fetch_fund_data(code)
        if data:
            results.append(data)
    return results

# 使用示例
fund_codes = ['016452', '017641', '270023']
funds_data = fetch_multiple_funds(fund_codes)

for fund in funds_data:
    print(f"{fund['fund_code']} {fund['fund_name']}: {fund['change_pct']:+.2f}%")

3. 持仓盈亏计算

def calculate_profit_loss(fund_data, holding_amount):
    """计算持仓盈亏"""
    if not fund_data:
        return None

    nav = fund_data['nav']
    total_value = holding_amount * nav

    return {
        'fund_name': fund_data['fund_name'],
        'holding_amount': holding_amount,
        'current_nav': nav,
        'total_value': total_value,
        'change_pct': fund_data['change_pct']
    }

# 使用示例(持有1364.7份基金)
holding = calculate_profit_loss(data, 1364.7)
if holding:
    print(f"基金: {holding['fund_name']}")
    print(f"持有份额: {holding['holding_amount']:.2f}")
    print(f"当前净值: {holding['current_nav']:.4f}")
    print(f"总价值: ¥{holding['total_value']:,.2f}")
    print(f"涨跌幅: {holding['change_pct']:+.2f}%")

4. Bash命令行查询

curl示例:

# 查询单只基金
curl -s "http://fundgz.1234567.com.cn/js/016452.js"

# 格式化输出(使用jq)
curl -s "http://fundgz.1234567.com.cn/js/016452.js" | \
  grep -oP 'jsonpgz\(\K.*(?=\);)' | jq .

# 批量查询(循环)
for code in 016452 017641 270023; do
  echo "=== $code ==="
  curl -s "http://fundgz.1234567.com.cn/js/${code}.js"
  echo ""
done

5. 常用基金代码参考

QDII基金(美国/海外市场)

基金代码基金名称跟踪指数
016452南方纳指100A纳斯达克100
017641摩根标普500A标普500
270023广发全球精选A全球股票
118001易方达亚洲精选亚洲市场
013328嘉实全球价值全球价值股
001092广发生物科技A生物科技

A股指数基金

基金代码基金名称跟踪指数
000300华夏沪深300ETF联接A沪深300
000950易方达沪深300ETF联接A沪深300
110022易方达创业板ETF联接A创业板

债券基金

基金代码基金名称类型
110027易方达安心回报债券A混合债
000003中海可转债A可转债

时间窗口和更新逻辑

基金净值更新时间表

时间段(北京时间)数据类型说明
交易日 05:00-14:59估算净值实时计算,仅供参考
交易日 15:00+官方净值确认净值,最准确
周末/节假日不更新使用上一个交易日数据

何时查询最适合

场景建议时间数据类型
日常跟踪09:00-14:00估算净值
购买决策15:30之后官方净值
申购/赎回15:00之前当天净值生效
周末复盘周五15:30后最新官方净值

重要提示: 基金申购/赎回必须在15:00前完成,才能享受当天净值。


错误处理和异常情况

常见错误及处理

错误原因处理方法
返回 jsonpgz();基金代码错误或暂停交易检查基金代码
请求超时网络问题或API故障增加超时时间或重试
gszzl解析失败涨跌幅格式异常使用默认值0
净值为0基金成立初期无净值使用估算净值

容错代码示例

def safe_fetch_fund(fund_code, max_retries=3):
    """带重试和安全处理的基金查询"""
    for attempt in range(max_retries):
        try:
            data = fetch_fund_data(fund_code)

            if not data:
                print(f"基金 {fund_code} 暂无数据")
                return None

            # 检查数据有效性
            if data['nav'] <= 0:
                print(f"基金 {fund_code} 官方净值无效,使用估算净值")
                data['nav'] = data['estimated_nav']

            return data

        except requests.exceptions.Timeout:
            if attempt < max_retries - 1:
                print(f"超时,重试 {attempt + 1}/{max_retries}...")
                time.sleep(2)
            else:
                print(f"基金 {fund_code} 请求失败")
                return None

        except Exception as e:
            print(f"基金 {fund_code} 查询异常: {e}")
            return None

    return None

完整集成示例

示例1: 每日自动化监控

#!/usr/bin/env python3
"""每日基金净值监控脚本"""

import requests
import json
import re
from datetime import datetime

# 基金配置
FUNDS_TO_MONITOR = {
    "016452": {"name": "南方纳指100A", "amount": 2729.37},
    "017641": {"name": "摩根标普500A", "amount": 690.91},
    "270023": {"name": "广发全球精选A", "amount": 441.69},
}

def generate_daily_report():
    """生成每日报告"""
    timestamp = datetime.now()
    print(f"\n📊 基金净值报告 - {timestamp.strftime('%Y-%m-%d %H:%M:%S')}")
    print(f"{'='*80}")

    total_value = 0
    total_change = 0

    for fund_code, info in FUNDS_TO_MONITOR.items():
        data = fetch_fund_data(fund_code)

        if not data:
            print(f"⚠️  {fund_code} {info['name']}: 暂无数据")
            continue

        # 计算当前价值
        shares = info['amount'] / info['amount']  # 这里假设amount是持仓金额
        current_value = shares * data['estimated_nav']
        daily_change = current_value * data['change_pct'] / 100

        total_value += current_value
        total_change += daily_change

        print(f"✅ {fund_code} {info['name']}")
        print(f"   官方净值: {data['nav']:.4f}")
        print(f"   估算净值: {data['estimated_nav']:.4f}")
        print(f"   涨跌幅: {data['change_pct']:+.2f}%")
        print(f"   当前价值: ¥{current_value:,.2f}")
        print()

    print(f"{'='*80}")
    print(f"总持仓价值: ¥{total_value:,.2f}")
    print(f"当日盈亏: ¥{total_change:,.2f} ({total_change/total_value*100:.2f}%)")

if __name__ == '__main__':
    generate_daily_report()

示例2: 购买时机分析

def analyze_buy_timing(fund_codes):
    """分析购买时机"""
    funds_data = [fetch_fund_data(code) for code in fund_codes]
    funds_data = [f for f in funds_data if f is not None]

    if not funds_data:
        return "数据不足,无法分析"

    # 计算平均涨跌幅
    avg_change = sum(f['change_pct'] for f in funds_data) / len(funds_data)

    # 判断市场情绪
    if avg_change < -1.0:
        return f"市场回调中(平均{avg_change:.2f}%),可能适合低吸 ✅"
    elif avg_change > 1.0:
        return f"市场上涨中(平均{avg_change:.2f}%),追高风险 ⚠️"
    else:
        return f"市场震荡中(平均{avg_change:.2f}%),可考虑分批买入 🟡"

# 使用示例
timing = analyze_buy_timing(['016452', '017641', '270023'])
print(timing)

注意事项和限制

⚠️ 重要限制

  1. 估算净值不等于官方净值
    • 估算净值基于持仓实时计算
    • 官方净值在15:00后才确认
    • 投资决策应以官方净值为准
  2. 不支持所有基金
    • 部分新基金可能暂无数据
    • 短期开放期基金可能无估算
    • 部分ETF可能不支持
  3. API无保证
    • 这是公开API,不承诺稳定性
    • 未来可能变更或停止服务
    • 建议定期测试API可用性
  4. 仅限中国基金
    • API只支持中国境内公募基金
    • 不支持海外基金直接查询
    • 不支持私募基金

扩展和优化建议

1. 数据缓存

import time
from datetime import timedelta

CACHE = {}

def fetch_with_cache(fund_code, cache_minutes=60):
    """带缓存的基金查询"""
    now = time.time()

    if fund_code in CACHE:
        cached_data, cached_time = CACHE[fund_code]
        if now - cached_time < cache_minutes * 60:
            return cached_data

    data = fetch_fund_data(fund_code)
    if data:
        CACHE[fund_code] = (data, now)

    return data

2. 历史数据存储

def save_to_history(fund_data, history_file='fund_history.jsonl'):
    """保存历史数据"""
    record = {
        **fund_data,
        'timestamp': datetime.now().isoformat()
    }

    with open(history_file, 'a') as f:
        json.dump(record, f)
        f.write('\n')

3. 告警系统

def check_alerts(fund_data, threshold=2.0):
    """检查涨跌幅告警"""
    if abs(fund_data['change_pct']) >= threshold:
        direction = "暴涨" if fund_data['change_pct'] > 0 else "暴跌"
        return f"⚠️ {fund_data['fund_name']} {direction} {abs(fund_data['change_pct']):.2f}%"
    return None

技术支持

API来源: 天天基金网(www.1234567.com.cn) 官方文档: 无公开文档(通过反向工程获得) 最后测试: 2026-03-01

备用数据源

如果天天基金网API不可用,可以考虑:

  1. 支付宝/淘宝基金
    • 需要登录授权
    • 数据准确但集成复杂
  2. 东方财富Choice
    • 商业数据服务
    • 需要付费订阅
  3. 同花顺iFinD
    • 专业金融数据
    • 企业级解决方案

相关技能

  • portfolio-manager: 投资组合管理
  • portfolio-watcher: 投资组合监控
  • stock-analysis: 股票分析
  • us-stock-analysis: 美股分析

版本历史

  • 1.0.0 (2026-03-01): 初始版本,基于天天基金网API

Skill位置: skills/fund-query/SKILL.md 创建时间: 2026-03-01 作者: AI Assistant 许可: OpenClaw专用

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.