Official Introduction
Real-time stock market data API for Chinese A-shares, with the simplest encapsulation. Includes daily lines, intraday minute-level data, all formatted into DataFrame, suitable for research, quantitative analysis, and automated trading systems.
The market data system integrates dual-core support from Sina Finance and Tencent Finance, with automatic failover between them. This greatly reduces the workload for quantitative researchers, allowing greater focus on strategy and model development.
Features
-
Lightweight core library: The entire project consists of just one file,
Ashare.py. No installation or configuration required. You can freely customize it and use it instantly viafrom Ashare import *. -
Dual-engine encapsulation: Provides real-time market data from both Sina Finance and Tencent Finance, including any historical daily, weekly, monthly, minute, and hourly data. Has been running stably for years.
-
Primary + backup dual-core design: Automatic hot standby and seamless switching. Suitable even as a live trading data source in quantitative systems.
-
All data cleaned and standardized into DataFrame format, making it extremely convenient to analyze and process using pandas.
-
What advantages does Ashare have over other market data libraries (e.g., tushare)? — Simplicity, lightweight, portability, and open-source transparency.
-
Complex data fetching, splitting, and integration logic is fully encapsulated into a single function:
get_price(). Just review the examples below and you’ll understand how easy it is. -
Can be used in any scenario requiring quantitative research or analysis.
First, a Simple Example Demo1.py
from Ashare import *
# Stock codes support multiple formats: Tongdaxin, Tonghuashun, JoinQuant
# sh000001 (000001.XSHG) sz399006 (399006.XSHE) sh600519 (600519.XSHG)
df = get_price('sh000001', frequency='1d', count=5) # Default: get last 5 days of daily data up to today
print('SSE Index Daily Data\n', df)
df = get_price('000001.XSHG', frequency='1d', count=5, end_date='2021-04-30') # Specify end date for historical data
print('SSE Index Historical Data\n', df)
df = get_price('000001.XSHG', frequency='1w', count=5, end_date='2018-06-15') # Supports '1d' (daily), '1w' (weekly), '1M' (monthly)
print('SSE Index Weekly Historical Data\n', df)
df = get_price('sh600519', frequency='15m', count=5) # Intraday minute data: supports '1m','5m','15m','30m','60m'
print('Kweichow Moutai 15-Minute Data\n', df)
df = get_price('600519.XSHG', frequency='60m', count=6) # Minute-level real-time data
print('Kweichow Moutai 60-Minute Data\n', df)
# SSE Index Daily Data ----------------------------------------------------
open close high low volume
2021-06-07 3597.14 3599.54 3600.38 3581.90 303718677.0
2021-06-08 3598.75 3580.11 3621.52 3563.25 304491470.0
2021-06-09 3576.80 3591.40 3598.71 3572.64 298323296.0
2021-06-10 3587.53 3610.86 3624.34 3584.13 318174808.0
2021-06-11 3614.11 3589.75 3614.40 3587.15 360554970.0
# Kweichow Moutai 60-Minute Data ----------------------------------------------------
open close high low volume
2021-06-10 14:00:00 2237.00 2224.16 2245.00 2222.00 4541.53
2021-06-10 15:00:00 2222.21 2238.48 2240.34 2222.21 4146.88
2021-06-11 10:30:00 2239.00 2220.00 2244.00 2197.86 12030.00
2021-06-11 11:30:00 2220.01 2210.18 2231.80 2200.18 4868.00
2021-06-11 14:00:00 2210.10 2223.35 2224.48 2206.01 4544.00
2021-06-11 15:00:00 2223.33 2178.81 2226.80 2178.81 12529.00
Another Example Using MyTT Demo2.py
# Stock Market Data Fetching and Visualization - 2
from Ashare import * # Stock data library https://github.com/mpquant/Ashare
from MyTT import * # MyTT technical indicator library (based on Tongdaxin/Mai language) https://github.com/mpquant/MyTT
# Multiple code formats supported: Tongdaxin, Tonghuashun, JoinQuant
# sh000001 (000001.XSHG) sz399006 (399006.XSHE) sh600519 (600519.XSHG)
df = get_price('000001.XSHG', frequency='1d', count=120) # Get last 120 days of daily data
print('SSE Index Daily Data\n', df.tail(5))
# ------- Now that we have the data, let's proceed -------
CLOSE = df.close.values; OPEN = df.open.values # Define base data sequences (any sequence input works)
HIGH = df.high.values; LOW = df.low.values # e.g., CLOSE=list(df.close) would work the same
MA5 = MA(CLOSE, 5) # 5-day moving average
MA10 = MA(CLOSE, 10) # 10-day moving average
up, mid, lower = BOLL(CLOSE) # Bollinger Bands
# ------------------------- Plotting -------------------------
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator
plt.figure(figsize=(15, 8))
plt.plot(CLOSE, label='SHZS')
plt.plot(up, label='UP')
plt.plot(mid, label='MID')
plt.plot(lower, label='LOW')
plt.plot(MA10, label='MA10', linewidth=0.5, alpha=0.7)
plt.legend()
plt.show()
Other Open-Source Projects by Our Team — If this project helps you, please click ★Star in the top-right corner to support us!
-
MyTT: Python implementation of Tongdaxin, Tonghuashun formulas, and Wenhua Mai language indicators
-
Ashare: Minimalist stock market data API, fully open-source and free for A-shares

Large group for algorithmic trading enthusiasts – Quant experts share strategies
Content-rich, no spam – Like-minded individuals gathering together to exchange insights and spark innovative thinking!