AkShare is an elegant and simple financial data interface library for Python, built for human beings! 开源财经数据接口库

Overview

PyPI - Python Version PyPI Downloads Documentation Status Code style: black akshare Actions Status MIT Licence code style: prettier

Overview

AkShare requires Python(64 bit) 3.7 or greater, aims to make fetch financial data as convenient as possible.

Write less, get more!

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-hangzhou.aliyuncs.com/akshare/akdocker

Run AkDocker

docker run -it registry.cn-hangzhou.aliyuncs.com/akshare/akdocker python

Test AkDocker

import akshare as ak
ak.__version__

Usage

Data

Code

import akshare as ak
hist_df = ak.stock_us_daily(symbol="AMZN")  # Get U.S. stock Amazon's price info
print(hist_df)

Output

               open       high        low      close     volume
date                                                           
1997-05-15    29.25    30.0000    23.1300    23.5000  6013000.0
1997-05-16    23.63    23.7500    20.5000    20.7500  1225000.0
1997-05-19    21.13    21.2500    19.5000    20.5000   508900.0
1997-05-20    20.75    21.0000    19.6300    19.6300   455600.0
1997-05-21    19.63    19.7500    16.5000    17.1300  1571100.0
             ...        ...        ...        ...        ...
2021-01-04  3270.00  3272.0000  3144.0200  3186.6299  4205801.0
2021-01-05  3166.01  3223.3799  3165.0601  3218.5100  2467255.0
2021-01-06  3146.48  3197.5090  3131.1599  3138.3799  4065357.0
2021-01-07  3157.00  3208.5420  3155.0000  3162.1599  3320882.0
2021-01-08  3180.00  3190.6399  3142.2000  3182.7000  3410288.0
[5951 rows x 5 columns]

Plot

Code

import akshare as ak
import mplfinance as mpf  # Please install mplfinance

stock_us_daily_df = ak.stock_us_daily(symbol="AAPL", adjust="qfq")
stock_us_daily_df = stock_us_daily_df[["open", "high", "low", "close", "volume"]]
stock_us_daily_df.columns = ["Open", "High", "Low", "Close", "Volume"]
stock_us_daily_df.index.name = "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

Pay attention to 数据科学实战 WeChat Official Accounts to get the AkShare updated info:

Application to add AkShare-官方 QQ group and talk about AkShare issues, QQ group number: 772100249

AkShare-官方

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

  1. Overview
  2. Installation
  3. Tutorial
  4. Data Dict
  5. Subjects

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 Black to format the code

Statement

  1. All data provided by AkShare is just for academic research purpose;

  2. The data provided by AkShare is for reference only and does not constitute any investment proposal;

  3. Any investor based on AkShare research should pay more attention to data risk;

  4. AkShare will insist on providing open-source financial data;

  5. Based on some uncontrollable factors, some data interfaces in AkShare may be removed;

  6. Please follow the relevant open-source protocol used by AkShare

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/jindaxiang/akshare)

Using the badge in README.rst:

.. image:: https://img.shields.io/badge/Data%20Science-AkShare-green
    :target: https://github.com/jindaxiang/akshare

Looks like this:

Data: akshare

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/jindaxiang/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 中国银行间市场交易商协会网站;

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 新浪财经网站;

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 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 猫眼电影网站;

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 163网站;

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 Currencyscoop网站;

Thanks for the data provided by 新加坡交易所网站;

Thanks for the data provided by 中国期货市场监控中心;

Thanks for the data provided by 宽客在线;

Thanks for the tutorials provided by 微信公众号: Python大咖谈.

Backer and Sponsor

Comments
  • live data

    live data

    Hi,

    I noticed there are two functions that can possibly provide real-time data.

    1. stock_zh_a_spot
    2. stock_zh_a_tick

    I've questions/suggestions regarding both, respectively.

    1. Is it possible to provide a symbol argument to stock_zh_a_spot? eg. stock_zh_a_spot(symbol = '000001').
    2. Does stock_zh_a_tick provide live data during regular trade hours?
    3. I'm interested in symbol = 'sh204007' (GC007, repo rate). Can stock_zh_a_spot fetch this data?

    Thanks.

    opened by edwardsun 25
  • ak.stock_zh_a_daily  查询k线数据问题

    ak.stock_zh_a_daily 查询k线数据问题

    Python 3.9.2

    Traceback (most recent call last):
      File "/Users/cuijl/PycharmProjects/rqalpha/akshare_test/test.py", line 5, in <module>
        stock_zh_a_daily_qfq_df = ak.stock_zh_a_daily(symbol="sz000002", start_date="20101103", end_date="20201116",
      File "/Users/cuijl/PycharmProjects/rqalpha/venv/lib/python3.9/site-packages/akshare/stock/zh_stock_a_sina.py", line 181, in stock_zh_a_daily
        temp_df = pd.merge(
      File "/Users/cuijl/PycharmProjects/rqalpha/venv/lib/python3.9/site-packages/pandas/core/reshape/merge.py", line 89, in merge
        return op.get_result()
      File "/Users/cuijl/PycharmProjects/rqalpha/venv/lib/python3.9/site-packages/pandas/core/reshape/merge.py", line 684, in get_result
        join_index, left_indexer, right_indexer = self._get_join_info()
      File "/Users/cuijl/PycharmProjects/rqalpha/venv/lib/python3.9/site-packages/pandas/core/reshape/merge.py", line 896, in _get_join_info
        join_index, left_indexer, right_indexer = left_ax.join(
      File "/Users/cuijl/PycharmProjects/rqalpha/venv/lib/python3.9/site-packages/pandas/core/indexes/datetimelike.py", line 893, in join
        this, other = self._maybe_utc_convert(other)
      File "/Users/cuijl/PycharmProjects/rqalpha/venv/lib/python3.9/site-packages/pandas/core/indexes/datetimes.py", line 413, in _maybe_utc_convert
        raise TypeError("Cannot join tz-naive with tz-aware DatetimeIndex")
    TypeError: Cannot join tz-naive with tz-aware DatetimeIndex
    
    bug 
    opened by mixbe 14
  • 开发者您好,stock_zh_a_hist该接口获取日K线数据,遇到停牌的股票会直接报错,使用版本1.5.91

    开发者您好,stock_zh_a_hist该接口获取日K线数据,遇到停牌的股票会直接报错,使用版本1.5.91

    比如 吉林化纤 000420 这个股票 使用stock_zh_a_hist接口,参数设置为period="daily"的时候,遇到这个停牌的股票,直接报错,无法继续执行下去,其他股票能正常拉取数据,今天更新到1.5.91版本后,出现这个问题,上周五5月20日使用1.5.82版本的时候,正常 还请开发者能帮忙看看修复下,谢谢~

    opened by tzmdaming 9
  • AKShare 接口问题报告

    AKShare 接口问题报告

    遇到任何问题,请先确认您的 AKShare 版本是最新的

    pip install akshare --upgrade  # Python 版本需要大于 3.7
    

    描述遇到的问题

    1. 操作系统版本 Windows 11 22H2
    2. Python 版本 Python 3.11.0
    3. AKShare 版本 1.7.90
    4. 接口的名称和代码 fund_portfolio_hold_em ak.fund_portfolio_hold_em(symbol=code, date="2022")
    5. 接口报错的截图或代码 image 看起来页面解析的结果key是“占净值 比例”,“持股数 (万股)”, “ 持仓市值 (万元)”,--key中包含空格。 而代码是按照“占净值比例”,“持股数(万股)”, “ 持仓市值(万元)”处理的。
    6. 期望获得的正确结果
    bug 
    opened by jqAtNJ 7
  • currency_hist报错

    currency_hist报错

    遇到任何问题,请先确认您的 AKShare 版本是最新的

    pip install akshare --upgrade  # Python 版本需要大于 3.7
    

    描述遇到的问题

    1. 操作系统版本: ubuntu 20.04
    2. Python 版本: 3.8.10
    3. AKShare 版本: 最新版本,测试前刚刚升级过akshare
    4. 接口的名称和代码: currency_hist
    5. 接口报错的截图或代码
    >>> import akshare as ak
    >>> currency_hist_df = ak.currency_hist(symbol="usd-jpy", start_date="20050101", end_date="20200117")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/home/dean/work/pyenv/quantopianPython/lib/python3.8/site-packages/akshare/fx/currency_investing.py", line 57, in currency_hist
        title = soup.find("h2", attrs={"class": "float_lang_base_1"}).get_text()
    AttributeError: 'NoneType' object has no attribute 'get_text'
    
    1. 期望获得的正确结果 之前工作正常,最近两天突然报错。
    bug 
    opened by csfreebird 7
  • AKShare 接口问题报告 currency_hist

    AKShare 接口问题报告 currency_hist

    描述遇到的问题

    1. 操作系统版本
    2. Python 版本
    3. AKShare 版本 8-18 最新版
    4. 接口的名称和代码 currency_hist
    5. 接口报错的截图或代码

    这是 文档里面的示例,跑不通:T.T

    ak.currency_hist(symbol="usd-jpy", period="每日", start_date="20050101", end_date="20220808")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/local/lib/python3.9/site-packages/akshare/fx/currency_investing.py", line 85, in currency_hist
        code = currency_hist_area_index_name_code(symbol)
      File "/usr/local/lib/python3.9/site-packages/akshare/fx/currency_investing.py", line 56, in currency_hist_area_index_name_code
        data_text = soup.find("script", attrs={"id": "__NEXT_DATA__"}).text
    AttributeError: 'NoneType' object has no attribute 'text'
    
    1. 期望获得的正确结果
    bug 
    opened by h2y 6
  • AKShare 接口问题报告

    AKShare 接口问题报告

    遇到任何问题,请先确认您的 AKShare 版本是最新的

    pip install akshare --upgrade  # Python 版本需要大于 3.7
    

    描述遇到的问题

    1. 操作系统版本:MAC OS 11.6

    2. Python 版本:3.8

    3. AKShare 版本:1.1.17

    4. 接口的名称和代码:stock_fund_flow_industry & stock_fund_flow_concept

    5. 接口报错的截图或代码:即时返回行业涨跌幅度和领涨股返回空值 image

    6. 期望获得的正确结果

    bug 
    opened by xnw176 6
  • AKShare 接口问题报告 问财热股数据无法下载

    AKShare 接口问题报告 问财热股数据无法下载

    遇到任何问题,请先确认您的 AKShare 版本是最新的

    pip install akshare --upgrade  # Python 版本需要大于 3.7
    

    描述遇到的问题

    1. 操作系统版本 Mac OS 10.13
    2. Python 版本 3.8.5
    3. AKShare 版本
    4. 接口的名称和代码 stock_wc_hot_rank(date="20210908")
    5. 接口报错的截图或代码

    Error in py_call_impl(callable, dots$args, dots$keywords) : IndexError: list index out of range

    Detailed traceback: File "/opt/anaconda3/envs/queen/lib/python3.8/site-packages/akshare/stock_feature/stock_wencai.py", line 87, in stock_wc_hot_rank rank_date_str = temp_df.columns[2].split("[")[1].strip("]")

    1. 期望获得的正确结果 从2021年9月8日开始无法下载当日数据,但是历史数据可以正常下载。
    bug 
    opened by quanplex 6
  • ak.epidemic_baidu(indicator=

    ak.epidemic_baidu(indicator="历史") not working for two days

    epidemic_baidu_df = ak.epidemic_baidu(indicator="历史") print(epidemic_baidu_df)

    Fetching historic data from epidemic[email protected]... Traceback (most recent call last): File "", line 8, in File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/akshare/event/sos.py", line 278, in epidemic_baidu json_data = json.loads(r.text[r.text.find("V.conf = ") + 9: r.text.find("V.bsData") - 1]) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/init.py", line 357, in loads return _default_decoder.decode(s) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

    Successfully installed akshare-0.4.1

    bug 
    opened by ericqianli 6
  • epidemic_163 not returning data in expected format

    epidemic_163 not returning data in expected format

    According to the documentation, calling history indicator on epidemic_163 should return data grouped by area. But in fact it is not.

    Query import akshare as ak epidemic_163_df = ak.epidemic_163(indicator="实时") print(epidemic_163_df)

    Expected Result day time country area dead confirm suspect heal city district 0 1.12 中国 湖北武汉 1 41 0 NaN None None 1 1.13 中国 湖北武汉 1 41 0 NaN None None 2 1.14 中国 湖北武汉 1 41 0 NaN None None 3 1.15 中国 湖北武汉 2 41 0 NaN None None 4 1.16 中国 湖北武汉 2 45 0 NaN None None .. ... ... ... ... ... ... ... ... ... ... 220 1.26 09:00 中国 台湾 0 3 0 0.0
    221 1.26 09:00 中国 新疆 0 4 0 0.0
    222 1.26 09:00 中国 澳门 0 5 0 0.0
    223 1.26 09:00 中国 内蒙古 0 7 0 0.0
    224 1.26 09:00 中国 青海 0 4 0 0.0

    Actual Result date confirm suspect dead heal 0 01.21 440 37 9 25 1 01.13 41 0 1 0 2 01.14 41 0 1 0 3 01.15 41 0 2 5 4 01.16 45 0 2 8 .. ... ... ... ... ... 11 01.20 291 54 6 25 12 01.25 1429 1965 42 38 13 01.26 2081 2684 56 49 14 01.27 2858 5794 82 58 15 01.28 4599 6973 106 68

    opened by ericqianli 6
  • 可转债实时数据参数需求

    可转债实时数据参数需求

    我想根据我的需求提两个建议: 一、我认为在可转债实时数据的获取中,获取该支转债的昨日收盘价是有必要的,可以用于量化参考; 二、增加以1分钟为尺度的成交量的数据会更加方便,现有的volume显示的是当天过去时间段所有的成交量,如果有每分钟的成交量,则可以更灵活的适应更多的需求。 以上两点建议望采纳,谢谢

    opened by balan123332 5
  • AKShare 接口问题报告

    AKShare 接口问题报告

    遇到任何问题,请先确认您的 AKShare 版本是最新的

    pip install akshare --upgrade  # Python 版本需要大于 3.7
    

    描述遇到的问题

    1. 操作系统版本:windows
    2. Python 版本:3.9.12
    3. AKShare 版本:最新
    4. 接口的名称和代码:获取展期收益率的接口get_roll_yield_bar
    5. 接口报错的截图或代码:KeyError: 'variety'。
    6. 期望获得的正确结果
    bug 
    opened by yinlinzhan 3
Releases(release-v1.8.45)
Owner
Albert King
Courage is more than a force
Albert King
Download YouTube videos that are available in the given playlist

Youtube-Playlist-Downloader Download YouTube videos that are available in the given playlist Project assets: music downloaded music folder. (will be g

Sultan Aljaberi 1 Dec 22, 2021
Download any video from YouTube playlists

youtube-dl Download any videos from YouTube playlists. Requirements Python 3 BeautifulSoup4 PyQt PyQtWebEngine pytube pyyoutube python-decouple Usage

Antonio Fortin 1 Oct 26, 2021
Download from HBO-MAX-BLIM-TV-Paramount

#HBO MAX- BlimTV -Paramount plus 4K Downloader Tool To download 4K HDR DV SDR from HBO MAX- BlimTV -Paramount plus Hello Fellow Developers/ ! Hi! M

4 Dec 25, 2021
A scriptable music downloader for Qobuz, Tidal, and Deezer

streamrip A scriptable stream downloader for Qobuz, Tidal, and Deezer. Features Downloads tracks, albums, playlists, discographies, and labels from Qo

967 Jan 03, 2023
Download Apple Music Cover Artwork in the best Quality by providing an Apple Music Link. It downloads the jpg, png and webp version since they often differ from another.

amogus.py - Version 0.0.5 amogus - Apple Music Hi-Res Artwork Fetcher this is my first real python tool so sorry if its bad amogus is a Python script

reaper 46 Jan 09, 2023
Download your Spotify playlists and songs along with album art and metadata

spotDL Download your Spotify playlists and songs along with album art and metadata The fastest, easiest, and most accurate command-line music download

10.6k Jan 03, 2023
Download candlestick data fast & easy for analysis

crypto-candlesticks 📈 The goal behind this project is to facilitate downloading cryptocurrency candlestick data fast & simple. Currently only the Bit

Pedro Torres 31 Dec 11, 2022
Spy Ad Network - Spy Ad Network Detection With Python

Spy Ad Network Spy Ad Network Detection Jumps from link to link to access a site

Baris Dincer 2 Jan 13, 2022
A股tick下载,自动判断交易日历,获取全市场level1数据

TickDown A股tick下载,自动判断交易日历,获取全市场level1数据 依赖项 func_timeout requests some_tool(仓库里) akshare 使用 定时任务在上午 09:07开始运行 参数调节 max_num 单批次提交的股票数,当前为800,可以自行尝试多个数

Demon Finch 7 Jul 06, 2022
A downloader for Cave Story written in Python

Cave Story Downloader This is a downloader for Cave Story written in Python. Thi

Imsad2 2 Feb 16, 2022
the best video downloader for terminals (currently only compatible with Linux and Windows)

the best video downloader for terminals (currently only compatible with Linux and Windows)

Amaral 2 Oct 14, 2021
A Telegram bot to download Subtitle for movies and tv shows.

Subtitle Downloader Bot A Telegram bot to download Subtitle for movies and tv shows. Host on Heroku Configuring Environments API_HASH : Your Telegram

Joy Biswas 15 Nov 12, 2022
This is a Text Data Analysis Project Involving (YouTube Case Study).

Text_Data_Analysis This is a Text Data Analysis Project Involving (YouTube Case Study). Problem Statement = Sentiment Analysis. Package1: There are m

1 Mar 05, 2022
Super S3 command line tool

s4cmd Super S3 command line tool Author: Chou-han Yang (@chouhanyang) Current Maintainers: Debodirno Chandra (@debodirno) | Naveen Vardhi (@rozuur) |

Bloomreach 1.2k Dec 27, 2022
Bulk Downloader for Reddit

saveddit is a bulk media downloader for reddit pip3 install saveddit Setting up authorization Register an application with Reddit Write down your clie

Pranav 136 Jan 03, 2023
Quickly, simply, and asynchronously download NFT's from an Opensea collection

iRightClick Quickly, simply, and asynchronously download NFT's from an Opensea collection. NOTICE This tool is not developed to encourage or facilitat

Setro 34 Dec 30, 2022
😷 Dowload dos documentos da CPI da Pandemia

A CPI da Pandemia recebeu milhares de documentos públicos, todos disponibilizados no site do Senado Federal.

Eduardo Cuducos 98 Sep 23, 2022
Most versatile Telegram torrent and youtube-dl bot.

TorToolkit Telegram So basically Tortoolkit is aimed to be the most versatile torrent leecher and Youtube-DL bot for telegram. This bot is highly cust

Yash Khadse 541 Dec 22, 2022
Downloads files and folders

PyDownloader Downloads files and folders at high speed (based on your interent speed). This is very useful to transfer big files from one computer to

ArmenG 4 Feb 24, 2022
Command-line program to download videos from YouTube.com and other video sites

youtube-dl - download videos from youtube.com or other video platforms

youtube-dl 116.4k Jan 07, 2023