akshare
AKShare is an elegant and simple financial data interface library for Python, built for human beings! 开源财经数据接口库
Top Related Projects
Quick Overview
AKShare is an open-source Python financial data interface library, designed to help users easily obtain financial market data. It provides a wide range of data sources, including stock markets, bonds, commodities, currencies, and macroeconomic indicators, making it a comprehensive tool for financial analysis and research.
Pros
- Extensive data coverage across various financial markets and instruments
- Regular updates to ensure data accuracy and relevance
- Easy-to-use API with consistent function naming conventions
- Well-documented with examples for each data interface
Cons
- Primarily focused on Chinese financial markets, which may limit its usefulness for global investors
- Dependency on external data sources may lead to occasional data availability issues
- Learning curve for users unfamiliar with Python or financial data structures
- Some functions may require additional parameters or authentication for certain data sources
Code Examples
Fetching stock data:
import akshare as ak
stock_zh_a_hist_df = ak.stock_zh_a_hist(symbol="000001", period="daily", start_date="20220101", end_date="20220331", adjust="")
print(stock_zh_a_hist_df)
Getting currency exchange rates:
import akshare as ak
currency_latest_df = ak.currency_latest()
print(currency_latest_df)
Retrieving macroeconomic data:
import akshare as ak
macro_china_gdp_yearly_df = ak.macro_china_gdp_yearly()
print(macro_china_gdp_yearly_df)
Getting Started
To get started with AKShare, follow these steps:
-
Install AKShare using pip:
pip install akshare
-
Import the library in your Python script:
import akshare as ak
-
Use the desired function to fetch data:
# Example: Get stock data stock_data = ak.stock_zh_a_hist(symbol="000001", period="daily", start_date="20220101", end_date="20220331", adjust="") print(stock_data)
For more detailed information and examples, refer to the official documentation at https://akshare.akfamily.xyz/.
Competitor Comparisons
AKShare is an elegant and simple financial data interface library for Python, built for human beings! 开源财经数据接口库
Pros of AKShare
- More comprehensive documentation and examples
- Larger community and more frequent updates
- Broader range of financial data sources supported
Cons of AKShare
- Potentially more complex API due to wider feature set
- May have higher resource requirements for full functionality
- Steeper learning curve for new users
Code Comparison
AKShare:
import akshare as ak
stock_zh_a_spot_df = ak.stock_zh_a_spot()
print(stock_zh_a_spot_df)
AKShare>:
import akshare as ak
stock_zh_a_spot_df = ak.stock_zh_a_spot()
print(stock_zh_a_spot_df.head())
The code snippets are nearly identical, with AKShare> using the head()
method to display only the first few rows of data, which can be more manageable for large datasets.
Both libraries provide similar functionality for accessing Chinese A-share stock data, but AKShare offers a more extensive set of features and data sources. AKShare> may be more suitable for users who prefer a simpler interface or have more limited requirements. The choice between the two depends on the specific needs of the project and the user's familiarity with financial data analysis.
TuShare is a utility for crawling historical data of China stocks
Pros of Tushare
- More established and mature project with a longer history
- Offers a wider range of data sources, including financial and economic data
- Provides both free and premium data services
Cons of Tushare
- Some features require a paid subscription
- Documentation is primarily in Chinese, which may be challenging for non-Chinese speakers
- Less frequent updates compared to AKShare
Code Comparison
Tushare:
import tushare as ts
# Get stock data
df = ts.get_hist_data('000001')
print(df.head())
AKShare:
import akshare as ak
# Get stock data
stock_zh_a_hist_df = ak.stock_zh_a_hist(symbol="000001", period="daily", start_date="20200101", end_date="20210101", adjust="")
print(stock_zh_a_hist_df.head())
Both libraries offer similar functionality for retrieving stock data, but AKShare's method includes more parameters for customization. Tushare's syntax is slightly more concise, while AKShare provides more flexibility in specifying date ranges and adjustments.
开源的金融投资数据提取工具,专注在各类网站上爬取数据,并通过简单易用的API方式使用
Pros of OpenData
- More focused on specific Chinese financial data sources
- Provides detailed documentation for each data source
- Includes some unique datasets not available in AKShare
Cons of OpenData
- Less frequently updated compared to AKShare
- Smaller community and fewer contributors
- More limited in scope, primarily covering Chinese markets
Code Comparison
OpenData:
from OpenData import Stock
# Get daily price data for a stock
df = Stock.get_k_data('000001', start='2020-01-01', end='2020-12-31')
AKShare:
import akshare as ak
# Get daily price data for a stock
df = ak.stock_zh_a_daily(symbol="000001", start_date="20200101", end_date="20201231")
Both libraries provide similar functionality for fetching stock data, but AKShare offers a wider range of data sources and more frequent updates. OpenData focuses more on specific Chinese financial data and provides detailed documentation for each source. AKShare has a larger community and more diverse data offerings, while OpenData may be more suitable for users specifically interested in Chinese market data with comprehensive documentation.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
欢è¿å å ¥ä¸æ³¨äºè´¢ç»æ°æ®åéåæèµçç¥è¯ç¤¾åºï¼è¯·ç¹å»äºè§£æ´å¤
ç¸å ³è§é¢æç¨å·²ç»åå¸ï¼ãAKShare-åé¶-使ç¨æå¦ãããAKShare-åé¶-å®æåºç¨ãããAKShare-æºç 解æãããå¼æºé¡¹ç®å·¡ç¤¼ãï¼è¯¦æ 请访é®è¯¾ç¨æ¥çæ´å¤è¯¾ç¨ä¿¡æ¯ï¼
AKQuant éåæç¨è¯·è®¿é®ï¼å©ç¨ PyBroker è¿è¡éåæèµ
æ¬æ¬¡åå¸ AKTools ä½ä¸º AKShare ç HTTP API çæ¬ï¼ çªç ´ Python è¯è¨çéå¶ï¼æ¬¢è¿åä½å°ä¼ä¼´è¯ç¨å¹¶æåºæ´å¥½çæè§æå»ºè®®ï¼ ç¹å» AKTools æ¥ç使ç¨æåãå¦å¤æä¾ awesome-data æ¹ä¾¿åä½å°ä¼ä¼´æ¥è¯¢åç§æ°æ®æºã
Overview
AKShare requires Python(64 bit) 3.8 or higher and aims to simplify the process of fetching financial data.
Write less, get more!
- Documentation: ä¸æææ¡£
Installation
General
pip install akshare --upgrade
China
pip install akshare -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host=mirrors.aliyun.com --upgrade
PR
Please check out Documentation if you want to contribute to AKShare
Docker
Pull images
docker pull registry.cn-shanghai.aliyuncs.com/akfamily/aktools:jupyter
Run Container
docker run -it registry.cn-shanghai.aliyuncs.com/akfamily/aktools:jupyter python
Test
import akshare as ak
print(ak.__version__)
Usage
Data
Code:
import akshare as ak
stock_zh_a_hist_df = ak.stock_zh_a_hist(symbol="000001", period="daily", start_date="20170301", end_date='20231022', adjust="")
print(stock_zh_a_hist_df)
Output:
æ¥æ å¼ç æ¶ç æé« ... æ¯å¹
涨è·å¹
涨è·é¢ æ¢æç
0 2017-03-01 9.49 9.49 9.55 ... 0.84 0.11 0.01 0.21
1 2017-03-02 9.51 9.43 9.54 ... 1.26 -0.63 -0.06 0.24
2 2017-03-03 9.41 9.40 9.43 ... 0.74 -0.32 -0.03 0.20
3 2017-03-06 9.40 9.45 9.46 ... 0.74 0.53 0.05 0.24
4 2017-03-07 9.44 9.45 9.46 ... 0.63 0.00 0.00 0.17
... ... ... ... ... ... ... ... ...
1610 2023-10-16 11.00 11.01 11.03 ... 0.73 0.09 0.01 0.26
1611 2023-10-17 11.01 11.02 11.05 ... 0.82 0.09 0.01 0.25
1612 2023-10-18 10.99 10.95 11.02 ... 1.00 -0.64 -0.07 0.34
1613 2023-10-19 10.91 10.60 10.92 ... 3.01 -3.20 -0.35 0.61
1614 2023-10-20 10.55 10.60 10.67 ... 1.51 0.00 0.00 0.27
[1615 rows x 11 columns]
Plot
Code:
import akshare as ak
import mplfinance as mpf # Please install mplfinance as follows: pip install mplfinance
stock_us_daily_df = ak.stock_us_daily(symbol="AAPL", adjust="qfq")
stock_us_daily_df = stock_us_daily_df.set_index(["date"])
stock_us_daily_df = stock_us_daily_df["2020-04-01": "2020-04-29"]
mpf.plot(stock_us_daily_df, type="candle", mav=(3, 6, 9), volume=True, show_nontrading=False)
Output:
Communication
Welcome to join the æ°æ®ç§å¦å®æ knowledge planet to learn more about quantitative investment, please visit æ°æ®ç§å¦å®æ for more information:
Pay attention to æ°æ®ç§å¦å®æ WeChat Official Accounts to get the AKShare updated info:
Features
- Easy of use: Just one line code to fetch the data;
- Extensible: Easy to customize your own code with other application;
- Powerful: Python ecosystem.
Tutorials
Contribution
AKShare is still under developing, feel free to open issues and pull requests:
- Report or fix bugs
- Require or publish interface
- Write or fix documentation
- Add test cases
Notice: We use Ruff to format the code
Statement
- All data provided by AKShare is just for academic research purpose;
- The data provided by AKShare is for reference only and does not constitute any investment proposal;
- Any investor based on AKShare research should pay more attention to data risk;
- AKShare will insist on providing open-source financial data;
- Based on some uncontrollable factors, some data interfaces in AKShare may be removed;
- Please follow the relevant open-source protocol used by AKShare;
- Provide HTTP API for the person who uses other program language: AKTools.
Show your style
Use the badge in your project's README.md:
[![Data: akshare](https://img.shields.io/badge/Data%20Science-AKShare-green)](https://github.com/akfamily/akshare)
Using the badge in README.rst:
.. image:: https://img.shields.io/badge/Data%20Science-AKShare-green
:target: https://github.com/akfamily/akshare
Looks like this:
Citation
Please use this bibtex if you want to cite this repository in your publications:
@misc{akshare,
author = {Albert King},
title = {AKShare},
year = {2019},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/akfamily/akshare}},
}
Acknowledgement
Special thanks FuShare for the opportunity of learning from the project;
Special thanks TuShare for the opportunity of learning from the project;
Thanks for the data provided by çæ社ç½ç«;
Thanks for the data provided by å¥è´§å¯æ¥ç½ç«;
Thanks for the data provided by ä¸å½é¶è¡é´å¸åºäº¤æååä¼ç½ç«;
Thanks for the data provided by 99æè´§ç½ç«;
Thanks for the data provided by è±ä¸ºè´¢æ ç½ç«;
Thanks for the data provided by ä¸å½å¤æ±äº¤æä¸å¿æ¨å ¨å½é¶è¡é´åä¸æåä¸å¿ç½ç«;
Thanks for the data provided by éåæ°æ®ç½ç«;
Thanks for the data provided by å讯财ç»ç½ç«;
Thanks for the data provided by æ°æµªè´¢ç»ç½ç«;
Thanks for the data provided by Oxford-Man Institute ç½ç«;
Thanks for the data provided by DACHENG-XIU ç½ç«;
Thanks for the data provided by ä¸æµ·è¯å¸äº¤ææç½ç«;
Thanks for the data provided by æ·±è¯è¯å¸äº¤ææç½ç«;
Thanks for the data provided by å京è¯å¸äº¤ææç½ç«;
Thanks for the data provided by ä¸å½éèæ货交ææç½ç«;
Thanks for the data provided by ä¸æµ·æ货交ææç½ç«;
Thanks for the data provided by 大è¿åå交ææç½ç«;
Thanks for the data provided by éå·åå交ææç½ç«;
Thanks for the data provided by ä¸æµ·å½é è½æºäº¤æä¸å¿ç½ç«;
Thanks for the data provided by Timeanddate ç½ç«;
Thanks for the data provided by æ²³åç空æ°è´¨éé¢æ¥ä¿¡æ¯åå¸ç³»ç»ç½ç«;
Thanks for the data provided by ååæè´§ç½ç«;
Thanks for the data provided by Economic Policy Uncertainty ç½ç«;
Thanks for the data provided by å¾®åææ°ç½ç«;
Thanks for the data provided by ç¾åº¦ææ°ç½ç«;
Thanks for the data provided by è°·æææ°ç½ç«;
Thanks for the data provided by ç³ä¸ææ°ç½ç«;
Thanks for the data provided by çæ°ç½ç½ç«;
Thanks for the data provided by è´¢å¯ç½ç«;
Thanks for the data provided by ä¸å½è¯å¸æèµåºéä¸åä¼ç½ç«;
Thanks for the data provided by Expatistan ç½ç«;
Thanks for the data provided by å京å¸ç¢³ææ¾æçµå交æå¹³å°ç½ç«;
Thanks for the data provided by å½å®¶éèä¸åå±å®éªå®¤ç½ç«;
Thanks for the data provided by ITæ¡åç½ç«;
Thanks for the data provided by ä¸æ¹è´¢å¯ç½ç«;
Thanks for the data provided by ä¹ä¹å°ååææ°ç½ç«;
Thanks for the data provided by ä¸å½å½å®¶åå±åæ¹é©å§åä¼ç½ç«;
Thanks for the data provided by ç¾åº¦è¿å¾ç½ç«;
Thanks for the data provided by æ åä¸å½ç½ç«;
Thanks for the data provided by æç¥ç½ç«;
Thanks for the data provided by Currencyscoop ç½ç«;
Thanks for the data provided by æ°å å¡äº¤ææç½ç«;
Thanks for the tutorials provided by å¾®ä¿¡å ¬ä¼å·: Python大åè°.
Backer and Sponsor
Top Related Projects
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot