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
A Udemy downloader that can download DRM protected videos and non-DRM protected videos.

Udemy Downloader with DRM support NOTE This program is WIP, the code is provided as-is and i am not held resposible for any legal repercussions result

Puyodead1 468 Dec 29, 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 toolkit to automatically crawl the paper list and download paper pdfs of ACL Ahthology.

ACL-Anthology-Crawler A toolkit to automatically crawl the paper list and download paper pdfs of ACL Anthology

Ray GG 9 Oct 09, 2022
Source code of paper: "HRegNet: A Hierarchical Network for Efficient and Accurate Outdoor LiDAR Point Cloud Registration".

HRegNet: A Hierarchical Network for Efficient and Accurate Outdoor LiDAR Point Cloud Registration Environments The code mainly requires the following

Intelligent Sensing, Perception and Computing Group 3 Oct 06, 2022
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
code for paper"3D reconstruction method based on a generative model in continuous latent space"

PyTorch implementation of 3D-VGT(3D-VAE-GAN-Transformer) This repository contains the source code for the paper "3D reconstruction method based on a g

Tong 5 Apr 25, 2022
Fast TikTok NO Watermark Video Downloader (username or url)

💎 TD [ TikDown v4 ] Star ⭐ if you want more Discord Server * discord.gg/onlp | Waxor#9999 Why not open source anymore ? * BECAUSE PEOPLE SKID, STEA

Tekky 26 Dec 01, 2022
Downloads .ksy files and their dependencies straight from the official kaitai-struct format gallery.

ksy-dl Downloads .ksy files and their dependencies straight from the official kaitai-struct format gallery. This tool will: Fetch any of the official

3 Jun 20, 2022
Animoo - Python scraper made with BeautifulSoup4 that scrapes images from /c/.

Animoo - Python scraper made with BeautifulSoup4 that scrapes images from /c/. Features Scrapes 10 pages Scrapes each thread Downloads all the images

aether 1 Dec 29, 2021
Using Youtube downloader is the fast and easy way to download and save any YouTube video.

Youtube video downloader using Django Using Django as a backend along with pytube module to create Youtbue Video Downloader. https://yt-videos-downloa

Suman Raj Khanal 10 Jun 18, 2022
📼Command line tool based on youtube-dl to easily download selected channels from your subscriptions.

youtube-cdl Command line tool based on youtube-dl to easily download selected channels from your subscriptions. This tool is very handy if you want to

Anatoly 64 Dec 25, 2022
This script fully automates of downloading tiktok videos, editing them,compiling them and finally uploading them to youtube.

This script fully automates of downloading tiktok videos, editing them,compiling them and finally uploading them to youtube. If you wanted to create a tiktok video compiilation youtubbe channel this

Supriyo Sarkar 32 Dec 16, 2022
Terminal based YouTube player and downloader

termitube NOTE: THIS REPOSITORY IS A FORK OF mps-youtube as mps-youtube has been unmaintained for almost a year now. Features Search and play audio/vi

Otis/Jacob Root 27 Dec 23, 2022
Tool To download Amazon 4k SDR HDR 1080, CDM IS Not Included

WV-AMZN-4K-RIPPER Tool To download Amazon 4k SDR HDR 1080, CDM IS Not Included For CDM You can Mail :- 11 Dec 23, 2021

squid-dl is a massively parallel yt-dlp-based YouTube downloader.

squid-dl squid-dl is a massively parallel yt-dlp-based YouTube downloader. Installation Run the setup.py, which will install squid-dl and its two depe

tuxlovesyou 51 Jan 05, 2023
Tkinter based YouTube video downloader works on pytube 11.0.2. Can download YouTube videos in 720p(HD), 144p and even only audio.

YouTube-Downloader Tkinter based YouTube video downloader works on pytube 11.0.2. Can download YouTube videos in 720p(HD), 144p and even only audio. G

Manav Grover 2 Dec 27, 2021
Stremio addon for fetching videos from your google drive.

stremio-gdrive Instructions: There are two ways to go about: Method 1 is hard and long but might give you better performance and you need to make your

72 Dec 31, 2022
A cross-platform python based utility to download courses from udemy for personal offline use.

udemy-dl A cross-platform python based utility to download courses from udemy for personal offline use. Warning Udemy has started to encrypt many of t

Nasir Khan 4.6k Dec 31, 2022
YouTube Video publisher using youtube-dl & ROS2🐢

YouTube-publisher-ROS2 Publish sensor_msgs/Image by "YouTube" 🤗 🤗 🤗 ! You don't have to use webcamera or your video to check demos. Purpose Quick d

Ar-Ray 5 Dec 04, 2022
Can automatically download mods from a Curseforge modpack

Curseforge-Modpack-Downloader A Python script which automatically downloads mods from a Curseforge modpack. Installing Dependencies ⚠ Make sure you ha

Rayr 1 Sep 20, 2022