tushare

Tushare Pro 金融大数据平台 - 提供A股、指数、基金、期货、债券、宏观数据,Token认证方式访问。

Safety Notice

This listing is from the official public ClawHub registry. Review SKILL.md and referenced scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "tushare" with this command: npx skills add coderwpf/tusharefree

Tushare Pro(大数据开放社区)

Tushare Pro is a widely used financial data platform in China, serving over 300,000 users. It provides a standardized Python API covering A-shares, indices, funds, futures, bonds, and macro data. All interfaces return pandas.DataFrame.

⚠️ Token Required: Register at https://tushare.pro and obtain your personal Token from the User Center. Some interfaces require a higher credit level. See the Credit System section below.

安装

pip install tushare --upgrade

初始化与基本用法

import tushare as ts

# Set Token (only needs to be set once per session)
ts.set_token('your_token_here')

# Initialize the Pro API
pro = ts.pro_api()

# Call any data interface
df = pro.daily(ts_code='000001.SZ', start_date='20240101', end_date='20240630')
print(df)

You can also pass the Token directly during initialization:

# Initialize with Token directly
pro = ts.pro_api('your_token_here')

股票代码格式(ts_code)

  • Shanghai: 600000.SH, 601398.SH
  • Shenzhen: 000001.SZ, 300750.SZ
  • Beijing: 430047.BJ
  • Indices: 000001.SH (SSE Composite Index), 399001.SZ (SZSE Component Index)

沪深股票数据

股票列表

# Get basic information for all currently listed stocks
df = pro.stock_basic(
    exchange='',
    list_status='L',      # L=Listed, D=Delisted, P=Suspended
    fields='ts_code,symbol,name,area,industry,list_date'
)

Credit requirement: 120

日K线数据

# Get daily market data for a specified stock
df = pro.daily(
    ts_code='000001.SZ',
    start_date='20240101',
    end_date='20240630'
)
# Returned fields: ts_code, trade_date, open, high, low, close, pre_close, change, pct_chg, vol, amount

Credit requirement: 120

周线/月线数据

# Get weekly data
df = pro.weekly(ts_code='000001.SZ', start_date='20240101', end_date='20240630')
# Get monthly data
df = pro.monthly(ts_code='000001.SZ', start_date='20240101', end_date='20240630')

分钟级K线数据

# Get minute-level K-line data
df = pro.stk_mins(
    ts_code='000001.SZ',
    freq='5min',           # Options: 1min, 5min, 15min, 30min, 60min
    start_date='2024-01-02 09:30:00',
    end_date='2024-01-02 15:00:00'
)

Credit requirement: 2000+

复权因子

# Get adjustment factors for calculating forward/backward adjusted prices
df = pro.adj_factor(ts_code='000001.SZ', trade_date='20240102')

每日指标

# Get daily market indicator data (PE ratio, PB ratio, turnover rate, market cap, etc.)
df = pro.daily_basic(
    ts_code='000001.SZ',
    trade_date='20240102',
    fields='ts_code,trade_date,turnover_rate,volume_ratio,pe,pe_ttm,pb,ps,ps_ttm,dv_ratio,dv_ttm,total_mv,circ_mv'
)

Credit requirement: 120

停复牌信息

# Get suspension & resumption info, S=Suspended
df = pro.suspend_d(ts_code='000001.SZ', suspend_type='S')

财务数据

利润表

# Get listed company income statement data
df = pro.income(ts_code='000001.SZ', period='20231231')

资产负债表

# Get listed company balance sheet data
df = pro.balancesheet(ts_code='000001.SZ', period='20231231')

现金流量表

# Get listed company cash flow statement data
df = pro.cashflow(ts_code='000001.SZ', period='20231231')

财务指标

# Get financial indicator data (ROE, EPS, revenue growth rate, net profit growth rate, etc.)
df = pro.fina_indicator(ts_code='000001.SZ', period='20231231')

业绩预告

# Get listed company earnings forecast data
df = pro.forecast(ts_code='000001.SZ', period='20231231')

业绩快报

# Get listed company earnings express report data
df = pro.express(ts_code='000001.SZ', period='20231231')

分红送股

# Get listed company dividend and share distribution data
df = pro.dividend(ts_code='000001.SZ')

市场参考数据

个股资金流向

# Get individual stock money flow data
df = pro.moneyflow(ts_code='000001.SZ', start_date='20240101', end_date='20240630')

Credit requirement: 2000+

龙虎榜

# 获取龙虎榜数据
df = pro.top_list(trade_date='20240102')

大宗交易

# Get block trade data
df = pro.block_trade(ts_code='000001.SZ', start_date='20240101', end_date='20240630')

融资融券

# Get margin trading detail data
df = pro.margin_detail(trade_date='20240102')

股东增减持

# Get shareholder increase/decrease in holdings data
df = pro.stk_holdertrade(ts_code='000001.SZ', start_date='20240101', end_date='20240630')

指数数据

指数日K线

# Get index daily market data
df = pro.index_daily(ts_code='000300.SH', start_date='20240101', end_date='20240630')

指数成分股

# Get index constituents and weights
df = pro.index_weight(index_code='000300.SH', start_date='20240101', end_date='20240630')

指数基本信息

# Get index basic information; market options: SSE (Shanghai Stock Exchange), SZSE (Shenzhen Stock Exchange), etc.
df = pro.index_basic(market='SSE')

基金数据

基金列表

# Get fund list; E=Exchange-traded, O=OTC (over-the-counter)
df = pro.fund_basic(market='E')

基金日行情

# Get exchange-traded fund daily market data
df = pro.fund_daily(ts_code='510300.SH', start_date='20240101', end_date='20240630')

基金净值

# Get OTC fund net asset value data
df = pro.fund_nav(ts_code='000001.OF')

期货数据

期货日行情

# Get futures daily market data
df = pro.fut_daily(ts_code='IF2401.CFX', start_date='20240101', end_date='20240131')

期货基本信息

# Get futures contract basic information
# exchange options: CFFEX (China Financial Futures Exchange), SHFE (Shanghai Futures Exchange), DCE (Dalian Commodity Exchange), CZCE (Zhengzhou Commodity Exchange), INE (Shanghai International Energy Exchange)
df = pro.fut_basic(exchange='CFFEX', fut_type='1')

债券数据

可转债列表

# Get convertible bond basic information
df = pro.cb_basic()

可转债日行情

# Get convertible bond daily market data
df = pro.cb_daily(ts_code='113009.SH', start_date='20240101', end_date='20240630')

宏观经济数据

Shibor利率

# Get Shanghai Interbank Offered Rate
df = pro.shibor(start_date='20240101', end_date='20240630')

GDP(国内生产总值)

# Get China GDP data
df = pro.cn_gdp()

CPI(居民消费价格指数)

# Get China Consumer Price Index
df = pro.cn_cpi(start_m='202401', end_m='202406')

PPI(生产者物价指数)

# Get China Producer Price Index
df = pro.cn_ppi(start_m='202401', end_m='202406')

货币供应量

# Get China money supply data (M0, M1, M2)
df = pro.cn_m(start_m='202401', end_m='202406')

交易日历

# Get trading calendar
df = pro.trade_cal(
    exchange='SSE',        # Exchange: SSE (Shanghai), SZSE (Shenzhen), BSE (Beijing)
    start_date='20240101',
    end_date='20241231',
    fields='exchange,cal_date,is_open,pretrade_date'
)

完整示例:下载股票数据并保存为CSV

import tushare as ts
import pandas as pd

ts.set_token('your_token_here')
pro = ts.pro_api()

# Get Kweichow Moutai daily K-line data
df = pro.daily(ts_code='600519.SH', start_date='20240101', end_date='20241231')

# Get adjustment factors and calculate forward-adjusted closing price
adj = pro.adj_factor(ts_code='600519.SH', start_date='20240101', end_date='20241231')
df = df.merge(adj[['trade_date', 'adj_factor']], on='trade_date')
df['adj_close'] = df['close'] * df['adj_factor']  # Calculate forward-adjusted price

# Save as CSV file
df.to_csv('moutai_2024.csv', index=False)
print(df.head())

积分系统

等级积分可用接口示例
基础120stock_basic, daily, weekly, monthly, trade_cal, daily_basic
中级2000stk_mins(分钟数据), moneyflow, margin_detail, fina_indicator
高级5000+Tick数据、大单数据、更高频率限制

如何免费获取积分

  1. 注册并完善个人信息 → 获得120积分
  2. 每日在tushare.pro签到
  3. 社区贡献(分享、回答问题)
  4. 邀请好友注册

使用技巧

  • 需要Token — 在 https://tushare.pro 免费注册获取(用户中心)。
  • 日期格式YYYYMMDD(无连字符),所有日期参数使用此格式。
  • ts_code格式{code}.{exchange} — 如 000001.SZ600519.SH
  • 所有接口返回 pandas DataFrame
  • 频率限制取决于积分等级 — 积分越高,每分钟调用次数越多。
  • 使用 fields 参数仅选择需要的字段,提升查询性能。
  • 本地缓存参考数据(股票列表、交易日历)以避免重复调用。
  • Documentation: https://tushare.pro/document/2

进阶示例

批量下载多只股票

import tushare as ts
import pandas as pd
import time

ts.set_token('your_token_here')
pro = ts.pro_api()

# 定义要下载的股票列表
stock_list = ['000001.SZ', '600519.SH', '300750.SZ', '601318.SH', '000858.SZ']

all_data = []
for ts_code in stock_list:
    # Get daily K-line data
    df = pro.daily(ts_code=ts_code, start_date='20240101', end_date='20240630')
    all_data.append(df)
    print(f"Downloaded {ts_code}, {len(df)} records")
    time.sleep(0.3)  # Throttle request frequency to avoid rate limiting

# Combine all data
combined = pd.concat(all_data, ignore_index=True)
combined.to_csv("multi_stock_tushare.csv", index=False)
print(f"合并总计: {len(combined)} 条记录")

计算前复权价格

import tushare as ts
import pandas as pd

ts.set_token('your_token_here')
pro = ts.pro_api()

ts_code = '600519.SH'

# Get daily K-line and adjustment factors
df = pro.daily(ts_code=ts_code, start_date='20240101', end_date='20241231')
adj = pro.adj_factor(ts_code=ts_code, start_date='20240101', end_date='20241231')

# Merge data
df = df.merge(adj[['trade_date', 'adj_factor']], on='trade_date')

# Calculate forward-adjusted prices (using the latest date's adjustment factor as the base)
latest_factor = df['adj_factor'].iloc[0]  # Latest adjustment factor
df['adj_open'] = df['open'] * df['adj_factor'] / latest_factor
df['adj_high'] = df['high'] * df['adj_factor'] / latest_factor
df['adj_low'] = df['low'] * df['adj_factor'] / latest_factor
df['adj_close'] = df['close'] * df['adj_factor'] / latest_factor

print(df[['trade_date', 'close', 'adj_factor', 'adj_close']].head(10))

获取全市场每日指标并筛选

import tushare as ts
import pandas as pd

ts.set_token('your_token_here')
pro = ts.pro_api()

# Get market-wide daily indicators for a given date
df = pro.daily_basic(trade_date='20240628',
    fields='ts_code,trade_date,close,turnover_rate,pe_ttm,pb,ps_ttm,dv_ratio,total_mv,circ_mv')

# Filter criteria: PE between 5-20, PB between 0.5-3, dividend yield above 2%
filtered = df[
    (df['pe_ttm'] > 5) & (df['pe_ttm'] < 20) &
    (df['pb'] > 0.5) & (df['pb'] < 3) &
    (df['dv_ratio'] > 2)
].sort_values('pe_ttm')

print(f"Filtered {len(filtered)} stocks")
print(filtered[['ts_code', 'close', 'pe_ttm', 'pb', 'dv_ratio', 'total_mv']].head(20))

获取财务数据并分析

import tushare as ts
import pandas as pd

ts.set_token('your_token_here')
pro = ts.pro_api()

# 获取沪深300成分股
hs300 = pro.index_weight(index_code='000300.SH', start_date='20240601', end_date='20240630')
stock_codes = hs300['con_code'].unique().tolist()

# Get financial indicators (first 10 stocks as example)
fin_data = []
for code in stock_codes[:10]:
    df = pro.fina_indicator(ts_code=code, period='20231231',
        fields='ts_code,ann_date,roe,roa,grossprofit_margin,netprofit_yoy,or_yoy')
    if not df.empty:
        fin_data.append(df.iloc[0])

fin_df = pd.DataFrame(fin_data)
print("CSI 300 Selected Constituent Financial Indicators:")
print(fin_df[['ts_code', 'roe', 'roa', 'grossprofit_margin', 'netprofit_yoy']].to_string())

获取资金流向数据

import tushare as ts

ts.set_token('your_token_here')
pro = ts.pro_api()

# Get individual stock money flow (requires 2000+ credits)
df = pro.moneyflow(ts_code='000001.SZ', start_date='20240601', end_date='20240630')
# Fields include: buy_sm_vol (small order buy volume), sell_sm_vol (small order sell volume),
#                 buy_md_vol (medium order buy volume), buy_lg_vol (large order buy volume),
#                 buy_elg_vol (extra-large order buy volume), etc.
print(df.head())

完整示例:简单回测框架

import tushare as ts
import pandas as pd
import numpy as np

ts.set_token('your_token_here')
pro = ts.pro_api()

# 获取平安银行日K线数据
df = pro.daily(ts_code='000001.SZ', start_date='20230101', end_date='20231231')
df = df.sort_values('trade_date').reset_index(drop=True)  # Sort by date ascending

# Get adjustment factors and calculate forward-adjusted closing price
adj = pro.adj_factor(ts_code='000001.SZ', start_date='20230101', end_date='20231231')
df = df.merge(adj[['trade_date', 'adj_factor']], on='trade_date')
latest_factor = df['adj_factor'].iloc[-1]
df['adj_close'] = df['close'] * df['adj_factor'] / latest_factor

# Calculate dual moving averages
df['MA5'] = df['adj_close'].rolling(5).mean()
df['MA20'] = df['adj_close'].rolling(20).mean()

# Simple backtest
initial_cash = 100000
cash = initial_cash
shares = 0
trades = []

for i in range(20, len(df)):
    # 金叉 — buy signal
    if df['MA5'].iloc[i] > df['MA20'].iloc[i] and df['MA5'].iloc[i-1] <= df['MA20'].iloc[i-1]:
        if cash > 0:
            price = df['adj_close'].iloc[i]
            shares = int(cash / price / 100) * 100
            cash -= shares * price
            trades.append(f"{df['trade_date'].iloc[i]} BUY {shares} shares @ {price:.2f}")
    # 死叉 — sell signal
    elif df['MA5'].iloc[i] < df['MA20'].iloc[i] and df['MA5'].iloc[i-1] >= df['MA20'].iloc[i-1]:
        if shares > 0:
            price = df['adj_close'].iloc[i]
            cash += shares * price
            trades.append(f"{df['trade_date'].iloc[i]} SELL {shares} shares @ {price:.2f}")
            shares = 0

final_value = cash + shares * df['adj_close'].iloc[-1]
print(f"初始资金: {initial_cash:.2f}")
print(f"最终组合价值: {final_value:.2f}")
print(f"Return: {(final_value/initial_cash - 1)*100:.2f}%")
for t in trades:
    print(f"  {t}")

社区与支持

大佬量化 (BossQuant) 维护 — 量化交易教学与策略研发团队。

微信客服: bossquant1 · Bilibili · 搜索 大佬量化 — 微信公众号 / Bilibili / 抖音

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

Leads

Leads - command-line tool for everyday use

Registry SourceRecently Updated
General

Bmi Calculator

BMI计算器。BMI计算、理想体重、健康计划、体重追踪、儿童BMI、结果解读。BMI calculator with ideal weight, health plan. BMI、体重、健康。

Registry SourceRecently Updated
General

Blood

Blood — a fast health & wellness tool. Log anything, find it later, export when needed.

Registry SourceRecently Updated
General

Better Genshin Impact

📦BetterGI · 更好的原神 - 自动拾取 | 自动剧情 | 全自动钓鱼(AI) | 全自动七圣召唤 | 自动伐木 | 自动刷本 | 自动采集/挖矿/锄地 | 一条龙 | 全连音游 - UI A better genshin impact, c#, auto-play-game, automatic, g...

Registry SourceRecently Updated