Files
Auto-Trader/agent/src/skills/tushare/scripts/fund_data_example.py
T
shadowinlife 8c2fd3e127 fix: complete env-var migration — CI gate exit 0, 9 schema fields, noqa mechanism
- Add 9 missing env vars to EnvConfig schema (QVERIS_API_KEY,
  VIBE_TRADING_API_URL, OPENAI_MODEL, FUTU_TRADE_PWD_MD5, etc.)
- Migrate 26 os.getenv calls to get_env_config() accessor across 17 files
- Add # noqa: env-gate inline suppression to ci_env_var_gate.py (21 lines)
- Refactor security.py _env_flag_enabled to direct schema access
- Wire CI gate into .github/workflows/test.yml
- Fix api_server.py import of deleted constants
- Restore _legacy.py timeout positive-value validation
- Add reset_env_config() to test_security_auth_api.py for singleton freshness

CI gate: exit 0 (was exit 1 with 54 violations)
Tests: 4953 passed, 4 pre-existing tushare failures, 0 regressions

Co-Authored-By: OpenCode <noreply@opencode.ai>
AI-Model: qwen3.7-max
Co-Authored-By: opencode <noreply@ai-tool.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
AI-Contributed/Feature: 188/188
AI-Contributed/UT: 39/39
2026-07-08 22:42:14 +08:00

90 lines
2.3 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
基金数据获取示例脚本
"""
import tushare as ts
import pandas as pd
import os
# 读取环境变量中的token, 或者读取本地记录的token
from src.config.accessor import get_env_config
token = get_env_config().data.tushare_token or ts.get_token()
# 初始化pro接口
pro = ts.pro_api(token)
def get_fund_list():
"""
获取基金列表
"""
try:
data = pro.fund_basic(market='E', status='L', fields='ts_code,fund_name,fund_type,found_date,issue_date,delist_date')
print("基金列表获取成功:")
print(data.head())
return data
except Exception as e:
print(f"获取基金列表失败:{e}")
return None
def get_fund_nav(ts_code, start_date, end_date):
"""
获取基金净值数据
"""
try:
data = pro.fund_nav(ts_code=ts_code, start_date=start_date, end_date=end_date)
print(f"{ts_code}基金净值数据获取成功:")
print(data.head())
return data
except Exception as e:
print(f"获取基金净值数据失败:{e}")
return None
def get_fund_manager():
"""
获取基金经理数据
"""
try:
data = pro.fund_manager(limit=10, fields='ts_code,fund_name,manager_name,begin_date,end_date')
print("基金经理数据获取成功:")
print(data.head())
return data
except Exception as e:
print(f"获取基金经理数据失败:{e}")
return None
def main():
"""
主函数
"""
print("===== tushare 基金数据获取示例 =====")
# 获取基金列表
fund_list = get_fund_list()
if fund_list is not None:
# 获取第一只基金的代码
ts_code = fund_list['ts_code'].iloc[0]
print(f"\n使用基金代码:{ts_code}")
# 获取基金净值数据(最近30天)
import datetime
end_date = datetime.datetime.now().strftime('%Y%m%d')
start_date = (datetime.datetime.now() - datetime.timedelta(days=30)).strftime('%Y%m%d')
print(f"\n获取基金净值数据:{start_date} 至 {end_date}")
get_fund_nav(ts_code, start_date, end_date)
# 获取基金经理数据
print("\n获取基金经理数据:")
get_fund_manager()
if __name__ == "__main__":
main()