tushare

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Tushare 数据获取

Tushare Data Retrieval

任务目标

Task Objectives

  • 本 Skill 用于:通过 Tushare 数据接口获取 A 股市场数据、财务指标和宏观数据
  • 能力包含:实时行情、历史K线、财务数据、指标数据、股票信息、宏观数据、指数数据
  • 触发条件:用户提及 Tushare 或需要获取 A 股数据、财务信息、宏观数据时
  • This Skill is used to: Obtain A-share market data, financial indicators and macroeconomic data through the Tushare data interface
  • Capabilities include: Real-time market quotes, historical K-lines, financial data, indicator data, stock information, macroeconomic data, index data
  • Trigger conditions: When users mention Tushare or need to obtain A-share data, financial information, or macroeconomic data

前置准备

Preparations

  • 依赖说明:安装 tushare 库(已包含在 dependency 中)
  • 凭证配置:需配置 Tushare Token(凭证名: TUSHARE_TOKEN,环境变量: TUSHARE_TOKEN)
  • 账号申请:访问 https://tushare.pro/ 注册账号并获取 API Token(详见 references/tushare_quickstart.md)
  • Dependency description: Install the tushare library (included in dependencies)
  • Credential configuration: Need to configure Tushare Token (credential name: TUSHARE_TOKEN, environment variable: TUSHARE_TOKEN)
  • Account application: Visit https://tushare.pro/ to register an account and obtain API Token (see references/tushare_quickstart.md for details)

操作步骤

Operation Steps

  • 标准流程:
    1. 确定数据需求 — 智能体理解用户意图(行情/K线/财务/宏观/指数等)
    2. 调用对应脚本 — 根据数据类型选择脚本
    3. 解析结果 — 智能体分析返回的 JSON 格式数据
  • 脚本调用映射:
    • 行情/K线/复权数据 →
      python scripts/market_data.py --type daily --ts_code 000001.SZ --start_date 20240101 --end_date 20240131
    • 财务数据/利润表/资产负债表 →
      python scripts/financial_data.py --type financial --ts_code 000001.SZ --period 2023
    • 股票列表/交易日历 →
      python scripts/stock_info.py --type stock_basic
    • 指数数据/宏观数据 →
      python scripts/macro_index_data.py --type index_daily --ts_code 000001.SH --start_date 20240101 --end_date 20240131
  • 可选分支:
    • 当需要多只股票数据:使用 --ts_code 参数逗号分隔
    • 当需要复权数据:使用 --type adj_factor 获取复权因子
    • 当需要指定报告期:使用 --period 参数(YYYY 或 YYYYMM)
  • Standard process:
    1. Determine data requirements — The agent understands the user's intent (market quotes/K-lines/finance/macro/index, etc.)
    2. Call the corresponding script — Select the script based on data type
    3. Parse results — The agent analyzes the returned JSON format data
  • Script call mapping:
    • Market quotes/K-lines/adjacent data →
      python scripts/market_data.py --type daily --ts_code 000001.SZ --start_date 20240101 --end_date 20240131
    • Financial data/income statement/balance sheet →
      python scripts/financial_data.py --type financial --ts_code 000001.SZ --period 2023
    • Stock list/trading calendar →
      python scripts/stock_info.py --type stock_basic
    • Index data/macroeconomic data →
      python scripts/macro_index_data.py --type index_daily --ts_code 000001.SH --start_date 20240101 --end_date 20240131
  • Optional branches:
    • When needing data for multiple stocks: Use the --ts_code parameter separated by commas
    • When needing adjusted data: Use the --type adj_factor to obtain adjustment factors
    • When needing to specify a reporting period: Use the --period parameter (YYYY or YYYYMM)

使用示例

Usage Examples

  • 示例1:获取股票日K线数据
    • 场景/输入:用户说"查看平安银行最近一个月的K线数据"
    • 预期产出:返回日期、开盘价、最高价、最低价、收盘价、成交量等OHLCV数据
    • 关键要点:调用
      python scripts/market_data.py --type daily --ts_code 000001.SZ --start_date 20240301 --end_date 20240331
  • 示例2:查询财务数据
    • 场景/输入:用户说"获取招商银行2023年的财务指标"
    • 预期产出:返回ROE、ROA、毛利率、净利率等财务指标
    • 关键要点:调用
      python scripts/financial_data.py --type fina_indicator --ts_code 600036.SH --period 2023
  • 示例3:获取指数数据
    • 场景/输入:用户说"查询上证指数最近的走势"
    • 预期产出:返回上证指数的日期、收盘价、成交量等数据
    • 关键要点:调用
      python scripts/macro_index_data.py --type index_daily --ts_code 000001.SH --start_date 20240301 --end_date 20240331
  • Example 1: Obtain daily K-line data of stocks
    • Scenario/Input: User says "Check the K-line data of Ping An Bank in the last month"
    • Expected output: Return OHLCV data such as date, opening price, highest price, lowest price, closing price, trading volume, etc.
    • Key points: Call
      python scripts/market_data.py --type daily --ts_code 000001.SZ --start_date 20240301 --end_date 20240331
  • Example 2: Query financial data
    • Scenario/Input: User says "Obtain the financial indicators of China Merchants Bank in 2023"
    • Expected output: Return financial indicators such as ROE, ROA, gross profit margin, net profit margin, etc.
    • Key points: Call
      python scripts/financial_data.py --type fina_indicator --ts_code 600036.SH --period 2023
  • Example 3: Obtain index data
    • Scenario/Input: User says "Query the recent trend of the Shanghai Composite Index"
    • Expected output: Return data such as date, closing price, trading volume of the Shanghai Composite Index
    • Key points: Call
      python scripts/macro_index_data.py --type index_daily --ts_code 000001.SH --start_date 20240301 --end_date 20240331

资源索引

Resource Index

  • 脚本:
    • scripts/market_data.py (用途与参数:获取行情/K线/复权数据,支持 --type/--ts_code/--start_date/--end_date)
    • scripts/financial_data.py (用途与参数:获取财务数据/利润表/资产负债表/现金流量表/指标,支持 --type/--ts_code/--period)
    • scripts/stock_info.py (用途与参数:获取股票列表/交易日历/名称变更,支持 --type/--ts_code/--start_date/--end_date)
    • scripts/macro_index_data.py (用途与参数:获取指数数据/宏观数据/Shibor,支持 --type/--ts_code/--start_date/--end_date)
  • 参考:
    • references/tushare_quickstart.md (何时读取:首次配置或认证失败时)
    • references/api_reference.md (何时读取:需要查看详细API参数说明时)
  • Scripts:
    • scripts/market_data.py (Purpose and parameters: Obtain market quotes/K-lines/adjusted data, supports --type/--ts_code/--start_date/--end_date)
    • scripts/financial_data.py (Purpose and parameters: Obtain financial data/income statement/balance sheet/cash flow statement/indicators, supports --type/--ts_code/--period)
    • scripts/stock_info.py (Purpose and parameters: Obtain stock list/trading calendar/name changes, supports --type/--ts_code/--start_date/--end_date)
    • scripts/macro_index_data.py (Purpose and parameters: Obtain index data/macroeconomic data/Shibor, supports --type/--ts_code/--start_date/--end_date)
  • References:
    • references/tushare_quickstart.md (When to read: During initial configuration or authentication failure)
    • references/api_reference.md (When to read: When needing to view detailed API parameter descriptions)

注意事项

Notes

  • 脚本执行需配置 Tushare Token,首次使用需先完成凭证配置
  • Tushare 股票代码格式:上海市场为 XXXXXX.SH,深圳市场为 XXXXXX.SZ
  • 部分数据(如财务数据)可能有延迟,建议在交易日9:30-15:00之外获取
  • 脚本返回 JSON 格式数据,智能体负责解析并转换为用户友好的展示
  • 调用频率有限制,免费账户每分钟最多120次调用(详见 Tushare 官方文档)
  • 首次使用建议先读取 tushare_quickstart.md 完成认证配置
  • Script execution requires configuring Tushare Token, complete credential configuration first for initial use
  • Tushare stock code format: Shanghai market is XXXXXX.SH, Shenzhen market is XXXXXX.SZ
  • Some data (such as financial data) may have delays, it is recommended to obtain it outside the trading hours of 9:30-15:00 on trading days
  • Scripts return data in JSON format, the agent is responsible for parsing and converting it into user-friendly display
  • There are call frequency limits, free accounts can make up to 120 calls per minute (see Tushare official documentation for details)
  • It is recommended to read tushare_quickstart.md first to complete authentication configuration for initial use