How to Access Chinese Stock Data with TuShare and AkShare

You can access Chinese stock data by initializing TuShare with a free token via ts.pro_api() for historical A-share prices, or using AkShare's token-free functions like ak.macro_china_monthly_cpi() for macro-economic indicators, with both libraries returning pandas DataFrames compatible with systematic trading pipelines.

The Awesome Systematic Trading repository provides curated resources to access Chinese stock data with TuShare and AkShare, two primary Python libraries for quantitative research. These packages wrap public market data endpoints to deliver historical price series, financial statements, and macro-economic indicators directly into your research environment. According to the paperswithbacktest/awesome-systematic-trading source code, the returned pandas DataFrames integrate seamlessly with strategy scripts located in static/strategies/ such as value-factor-effect-within-countries.py.

Configuring TuShare for Historical Equity Data

TuShare focuses on historical price and financial statement data for A-shares, B-shares, and Hong Kong stocks. As listed in README.md and README_zh.md, this library requires authentication but provides structured professional-grade equity data through its Pro interface.

Authentication and Client Initialization

TuShare requires a free API token obtained from the TuShare website to access its Pro interface. Initialize the client by importing the library and calling ts.set_token() followed by ts.pro_api(), which returns a client object for subsequent queries.


# ------------------------------

# Example 1 – Fetch daily A‑share price data with TuShare

# ------------------------------

import tushare as ts

# Obtain a free token from https://tushare.pro (replace 'YOUR_TOKEN')

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

# Query daily price for a specific stock (e.g., 600519.SH – Kweichow Moutai)

df = pro.daily(ts_code='600519.SH', start_date='20240101', end_date='20240430')
print(df.head())

Retrieving Daily Price Series

The pro.daily() method accepts parameters including ts_code, start_date, and end_date to return historical OHLCV data. This function outputs a pandas DataFrame with columns such as trade_date, open, high, low, close, and vol, suitable for direct ingestion by backtesting frameworks.

Accessing Market Data with AkShare

AkShare operates as a comprehensive financial data interface library that covers not only equity markets but also macro indicators, bond information, and fund flows. Unlike TuShare, most AkShare functions do not require a token, though some premium endpoints may need registration.

Token-Free Macro-Economic Indicators

AkShare provides extensive coverage of China-specific macro-economic data without authentication barriers. Use ak.macro_china_monthly_cpi() to retrieve consumer price index year-over-year data, or ak.macro_china_money_supply() for M2 statistics, both returning structured DataFrames indexed by date.


# ------------------------------

# Example 2 – Retrieve Chinese macro data with AkShare

# ------------------------------

import akshare as ak

# Get China macro‑economic indicators (e.g., CPI year‑over‑year)

cpi_df = ak.macro_china_monthly_cpi()
print(cpi_df.tail())

Accessing Broad Market Data

The library includes functions for real-time quotes, historical tick data, and derivatives markets. The consistent pandas DataFrame output allows immediate merging with TuShare equity data to create multi-factor datasets for research pipelines.

Combining TuShare and AkShare for Research Workflows

Integrate both libraries to enrich price data with macro variables. The following pattern demonstrates downloading multiple stock symbols from TuShare and merging them with money supply data from AkShare, creating a comprehensive dataset compatible with the static/strategies/ pipeline referenced in the repository.


# ------------------------------

# Example 3 – Combine TuShare and AkShare for a full research workflow

# ------------------------------

import tushare as ts
import akshare as ak
import pandas as pd

# 1️⃣ Initialize TuShare client

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

# 2️⃣ Download price data for a list of symbols

symbols = ['000001.SZ', '600000.SH']  # SZ index & Shanghai bank index

price_data = pd.concat(
    [pro.daily(ts_code=s, start_date='20240101', end_date='20240331')
     for s in symbols],
    ignore_index=True
)

# 3️⃣ Add macro variable (e.g., M2 money supply) from AkShare

m2 = ak.macro_china_money_supply()
price_data = price_data.merge(m2, how='left', left_on='trade_date', right_on='date')

print(price_data.head())

Feeding Data into Backtesting Frameworks

Both libraries output standard pandas DataFrames that require minimal transformation to work with example scripts in the repository. The value-factor-effect-within-countries.py file and other strategy implementations in static/strategies/ expect DataFrame inputs with datetime indices and OHLCV columns, which TuShare and AkShare provide directly. Map the trade_date columns to datetime objects and set them as the index before passing to Backtrader or Zipline cerebro engines.

Summary

  • TuShare requires a free token via ts.set_token() and provides the pro_api() interface for historical A-share, B-share, and Hong Kong stock prices.
  • AkShare operates without tokens for most endpoints and specializes in macro-economic indicators, bonds, and fund flows through functions like macro_china_monthly_cpi().
  • Both libraries return pandas DataFrames that integrate directly with the static/strategies/ scripts in the Awesome Systematic Trading repository.
  • Combine TuShare price data with AkShare macro variables by merging on date columns to create enriched datasets for systematic trading research.

Frequently Asked Questions

What is the difference between TuShare and AkShare for Chinese stock data?

TuShare focuses primarily on historical price data and financial statements for A-shares and Hong Kong stocks through a token-based Pro API, while AkShare offers broader coverage including macro-economic indicators, bond markets, and fund flows without requiring authentication for most functions. Both libraries return pandas DataFrames but cater to different data needs within quantitative finance workflows.

Do I need an API token to access data with TuShare and AkShare?

TuShare requires a free token obtained from tushare.pro to initialize the pro_api() client, whereas AkShare does not require a token for standard market data access, though some premium endpoints may need registration. This distinction makes AkShare more accessible for initial prototyping while TuShare provides structured professional-grade equity data.

How do I integrate TuShare and AkShare data into backtesting frameworks?

Both libraries output pandas DataFrames that align with the input requirements of strategy scripts found in static/strategies/ such as value-factor-effect-within-countries.py. Convert the trade_date columns to datetime objects and set them as the index before passing the DataFrame to engines like Backtrader or Zipline for systematic backtesting.

What types of Chinese market data can I retrieve with these libraries?

TuShare provides daily prices, fundamentals, and financial statements for individual securities, while AkShare delivers macro-economic indicators like CPI and M2 money supply, alongside bond and fund flow data. The combination enables comprehensive research covering both micro-level equity performance and macro-economic context.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →