SuperAPI AI Directory

shanxi-securities-tushare

Data & analytics

View repository

Updated 10-16 05:57

About this skill

Shanxi Securities Tushare Data Skill

Convert natural language financial data requests into executable Tushare workflows:Environment check → Understand task → Parse target → Select interface → Validate parameters → Fetch data → Organize → Explain → Deliver。

Typical scenarios

This skill is only responsible fordata fetching and data delivery; if the user requests analysis/evaluation/comparison/in-depth research on a target, use sxsc-tushare-analysis skill。

  • Obtain quotes, valuation, and activity data for a single stock/index/ETF
  • Batch data fetching for multiple targets (performance, valuation, price change, ROE, and other fields)
  • Obtain financial data (profit trends, ROE, gross margin, cash flow)
  • Obtain capital flow data (northbound, main force, dragon-tiger list, sector capital inflow)
  • Obtain sector rotation and index constituent stock data
  • Obtain macroeconomic data (CPI / PPI / GDP / PMI / interest rates / money supply)
  • Data export (CSV / Parquet) for backtesting or subsequent analysis

Core workflow

Execute in this order each time:

  1. Environment check — Check whether scripts/env_check.json cache exists:
    • Yes → read directly, take the mode field (sdk/http) to determine the data fetching method.
    • No → first run python scripts/check_env.py to generate the cache, then read it.
    • Exit code non-zero (token missing) → stop, first prompt the user to configure SXSC_TUSHARE_TOKEN,must not proceed to data fetching。
  2. Understand task — Identify what problem the user wants to solve (see "Task classification" below).
  3. Parse target — Name/code → standard ts_code(e.g., 600519.SH); market, time window, and fields are filled in with default values.
  4. Look up table to select interface — First check references/API接口对应表.md to get pro.api_name and the corresponding document path,writing interfaces from memory is prohibited。
  5. Validate parameters — Date YYYYMMDD, start/end order, conflict resolution, future date trimming (rules see "Key defaults" lines 71–73 below).
  6. Data fetching execution — According to step 1's mode choose the method:
    • sdk: refer to the SDK functions of the templates under scripts/ (stock_data_demo.py、fund_data_demo.py、index_sector_demo.py、fin_report_demo.py、moneyflow_demo.py), follow the Python SDK section of references/调取数据.md .
    • http: refer to the HTTP function in the template (http_call), follow the HTTP protocol section of references/调取数据.md (no SDK dependency).
  7. Structured delivery — One-sentence conclusion → scope → key metrics/tables → risks/limitations → file path.

Key principles: First think "what task is this, which workflow to follow", then think "which interface to use".Never start by looking up interface names。Confirm the environment is ready before fetching data(step 1); when the token is missing, any data fetching is meaningless.

Task classification

Task type Typical expression
Market/trend data Fetch recent market data, price changes, candlestick charts, volume data
Basic information What company, when listed, industry
Financial data Pull financial reports, profit, ROE, cash flow
Valuation data Fetch PE/PB, dividend yield data
Capital flow/market behavior data Fetch northbound, main force, dragon-tiger list, sector capital inflow data
Sector/index/theme data Fetch sector constituent stocks, index constituents, concept data
Limit up/down/sentiment data Fetch limit-up ladder, consecutive limit-ups, activity data
Announcements/news/research reports Announcements, catalysts, news aspects (restricted: only inform of boundaries + alternative paths)
Macro/cross-market CPI, PMI, interest rates, Hong Kong stocks, US stocks
Data export/research preparation Pull CSV, backtest data tables, Parquet

If the user requests toanalyze/evaluate/compare/in-depth researchthe target, switch to sxsc-tushare-analysis skill。

Key defaults

Vague Chinese Default interpretation
"recent"/"recently" Last 20 trading days
"recent period"/"last three months" Last 60 trading days
"this year" From January 1 of the current year to now
"financial report"/"performance" Last 8 quarters + most recent fiscal year
"how has capital flow been recently" Last 5–20 trading days
"how has macro been recently" Last 6–12 periods
Industry classification Shenwan/CITIC (more stable)
Concept classification Hithink RoyalFlush/East Money (themes are hotter)
Security code 600519.SH / 000001.SZ standard format

Bare code (e.g. 000001) should be completed according to rules if possible and explained; if it cannot be completed, minimally clarify.
Date conflict (trade_date and start_date/end_date given together) should be adjudicated before calling.
Future dates are automatically trimmed to the nearest available date and the user is notified.

What this skill is NOT for

  • Buy/sell advice, acting as an investment advisor
  • Automatic order placement or trade execution
  • Real-time market data (only T-1 day data)
  • Implementation of backtesting engines and portfolio optimization systems
  • Fabricating data when there is no token / no permission

Environment check

Before executing any data-fetching task, first check whether the environment is available (results are cached to scripts/env_check.json, to avoid repeated checks each time):

python scripts/check_env.py          # token_set=true 则直接复用缓存,否则实时检测
python scripts/check_env.py --force  # 强制重新校验并覆盖缓存
python scripts/check_env.py --check  # 只校验不写缓存

Check items:

Item Required Consequence if missing
SXSC_TUSHARE_TOKEN is set Yes Cannot execute skill, returns non-zero exit code, environment variable must be configured first
sxsc_tushare library is installed No If yes → use SDK method (sxsc_tushare); if none → use the HTTP protocol method
  • A non-zero exit code indicates the token is missing,Fix the environment first, then fetch data。
  • The cache only stores the token_set status and SDK installation information; it does not save the token itself or its hash; when token_set=true, reuse the cache directly.
  • The data fetching method is based on the validation result mode field selection:sdk use the references/调取数据.md Python SDK section,http use the HTTP protocol section.

References Quick Index

Purpose Path
Interface name ↔ documentation mapping references/API接口对应表.md
Installation and HTTP retrieval references/调取数据.md
Stock call template scripts/stock_data_demo.py
Fund call template scripts/fund_data_demo.py
Index/industry call template scripts/index_sector_demo.py
Three financial statements call template scripts/fin_report_demo.py
Capital flow/dragon-tiger list call template scripts/moneyflow_demo.py

Code Examples

Initialization and daily bars

import sxsc_tushare as sx
import os

token = os.getenv('SXSC_TUSHARE_TOKEN') or 'YOUR_TOKEN_HERE'
sx.set_token(token)
pro = sx.get_api(env='prd')  # 'prd' 仿真, 'qa' 生产

# 股票列表
pro.stock_basic(exchange='', list_status='L',
                fields='ts_code,symbol,name,area,industry,list_date')

# 日线行情(ah_vol/ah_amount 为盘后成交量/额,2026-07-06 起有数据,需显式用 fields 指定)
pro.daily(ts_code='600519.SH', start_date='20250101', end_date='20251231')
# 取盘后数据示例:
# pro.daily(trade_date='20260707', fields='ts_code,open,close,ah_vol,ah_amount')

Error handling

try:
    df = pro.daily(ts_code='600519.SH', start_date='20250101', end_date='20251231')
except Exception as e:
    print(f"获取数据失败:{e}")

An empty result is not necessarily a failure: it could be a non-trading day, an unlisted security, incorrect parameters, or insufficient permissions — distinguish clearly before drawing conclusions.