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_baidu@akshare... 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 videos and audio with a graphical interface in python

Youtube-Downloader Download videos and audio with a graphical interface in python Windows To run windows using Command Prompt python main.py linux To

null 2 Jan 7, 2022
Ebook downloader built using python

ebook-downloader Getting Started Open a terminal and run the following commands. git clone github.com/georgemunyoro/ebook-downloader cd ./ebook-downlo

George Munyoro 1 Oct 19, 2021
Youtube Downloader by PyTube é uma ferramenta simples com interface gráfica e escrito em python para baixar vídeos e playlists do youtube...

YouTube Downloader by PyTube O que é o YouTube Downloader by PyTube? YouTube Downloader by PyTube é um software simples para baixar vídeos no YouTube

Elizeu Barbosa Abreu 5 Jul 30, 2022
Programmers-quest - Programmer's Quest! An open source MMO built on top of the Panda3D game engine and Astron server

Programmer's Quest! Programmer's Quest! The open source Python 3 2D MMORPG showc

Jordan Maxwell 5 Oct 7, 2022
A YouTube downloader app built with Django.

YouTube Downloader ⭐️ Star this project ⭐️ Requirements Python3+ Git Installation Install the dependencies and start the server. git clone https://git

Gabriel Tavares 26 Aug 19, 2022
A youtube downloader, built with flask yt-dlp

Built With Python Flask - The Python micro framework for building web applications. yt-dlp - A youtube-dl fork with additional features and fixes

Abhijith N T 13 Dec 17, 2022
Youtube Downloader is a Graphic User Interface(GUI) that lets users download a Youtube Video or Audio through a URL

Youtube Downloader This Python and Tkinter based GUI allows users to directly download the Best Resolution Videos and Audios from Youtube. Pa-fy Insta

Samarth Kumar 2 Jun 25, 2022
A lightweight, dependency-free Python library (and command-line utility) for downloading YouTube Videos.

A lightweight, dependency-free Python library (and command-line utility) for downloading YouTube Videos.

pytube 7.9k Jan 2, 2023
A simple python script to fetch Bing daily images and set them randomly using hsetroot

Daily bing walls A script to set the daily bing image as the wallpaper. It can also set from a random set of previously fetched wallpapers. usage: dai

Harinarayanan K S 5 Nov 23, 2022
Arxiv2Kindle is a simple script written in python that converts LaTeX source downloaded from Arxiv and recompiles it to better fit a Kindle or other similar reading devices.

Arxiv2Kindle is a simple script written in python that converts LaTeX source downloaded from Arxiv and recompiles it to better fit a read

Soumik Rakshit 8 Jul 9, 2022
A simple python script and it's used for mp4 type video downloading from youtube.

This is a simple python script and it's used for mp4 type video downloading from youtube. also, it's used inbuilt python module pytube. Furthermore, I know we have so many apps and online websites to do the same thing so it's just an experiment to study how to do those things in python.

Yousaf K Hamza 1 Jan 10, 2022
YouTube Downloader is extremely simple program for downloading songs or playlists (in audio or video) from YouTube. Created using Python, PyTube and PySimpleGUI.

YouTube Downloader YouTube Downloader is extremely simple program for downloading songs or playlists (in audio or video) from YouTube. Disclaimer It's

Simeon Tsvetanov 3 Dec 14, 2022
Simple Python script to download images and videos from public subreddits without using Reddit's API 😎

Subreddit Media Downloader Download images and videos from any public subreddit without using Reddit's API Made with ❤ by Nico ?? About: This script a

Nico 106 Jan 7, 2023
Python library to download bulk of images from Bing.com

Python library to download bulk of images form Bing.com. This package uses async url, which makes it very fast while downloading.

Guru Prasad Singh 105 Dec 14, 2022
Youtube_dl_helper - A hacky python script meant to automate the process of downloading mp3 files from YouTube using youtube-dl library

youtube_dl_helper A helper program meant to automate the process of downloading mp3 files from YouTube using youtube-dl library Dependencies In order

Guilherme Bittencourt de Borba 1 Jan 4, 2022
Simple python script to download .mp3 formatted files from YouTube video URLs

Introduction: Simple python script to download .mp3 formatted files from YouTube video URLs Requirements: Requires: youtube_dl module Requires: ffmpeg

Pat 2 Aug 18, 2022
A simple Python program which uses youtube-dl for downloading YouTube videos as mp3 files.

yt-mp3 converter This is a simple Python program which uses youtube-dl for downloading YouTube videos as mp3 files. This program is for you if you are

nostalgicnerdpenguin 1 Oct 24, 2021
A simple contents download module using url for python

A simple contents download module using url for python

Fayas Noushad 16 Oct 20, 2022
A simple kemono.party downloader using python.

kemono-dl This is a simple kemono.party downloader. How to use Install python Download source code from releases and extract it Then install requireme

null 318 Dec 27, 2022