AKShare is an elegant and simple financial data interface library for Python, built for human beings

Overview

本次发布 AKTools 作为 AKShare 的 HTTP Server 版本,突破 Python 语言的限制,欢迎各位小伙伴试用并提出更好的意见或建议! 点击 AKTools 查看使用指南

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

stock_zh_a_hist_df = ak.stock_zh_a_hist(symbol="000001", period="daily", start_date="20170301", end_date='20210907', 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
          ...    ...    ...    ...  ...   ...   ...   ...   ...
1100  2021-09-01  17.48  17.88  17.92  ...  5.11  0.45  0.08  1.19
1101  2021-09-02  18.00  18.40  18.78  ...  5.48  2.91  0.52  1.25
1102  2021-09-03  18.50  18.04  18.50  ...  4.35 -1.96 -0.36  0.72
1103  2021-09-06  17.93  18.45  18.60  ...  4.55  2.27  0.41  0.78
1104  2021-09-07  18.60  19.24  19.56  ...  6.56  4.28  0.79  0.84
[1105 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[["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 数据科学家 Official Accounts to get more information about Quant, ML, DS and so on.

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

Application to add AKShare-VIP群 QQ group and talk about AKShare issues, please contact AKShare-小助手 QQ: 2875328287

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/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:

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/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 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 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 接口问题报告

    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 6
  • 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
Releases(release-v1.8.51)
Owner
AKFamily
AKFamily is the family of AKShare
AKFamily
An all-in-one financial analytics and smart portfolio creator as a Discord bot!

An all-in-one financial analytics bot to help you gain quantitative financial insights. Finn is a Discord Bot that lets you explore the stock market like you've never before!

null 6 Jan 12, 2022
WallAlley.bot is an open source and free to use financial discord bot originaly build for WallAlley server's community

WallAlley.bot About WallAlley.bot is an open source and free to use financial discord bot originaly build for WallAlley server's community. All data a

Mohammad KHADDAN 1 Jan 22, 2022
A python library built on the API of the coderHub.sa, which helps you to fetch the challenges and more

coderHub A python library built on the API of the coderHub.sa, which helps you to fetch the challenges and more Installation • Features • Usage • Lice

TheAwiteb 5 Nov 4, 2022
A Python interface between Earth Engine and xarray for processing weather and climate data

wxee What is wxee? wxee was built to make processing gridded, mesoscale time series weather and climate data quick and easy by integrating the data ca

Aaron Zuspan 160 Dec 31, 2022
A Python Library to interface with LinkedIn API, OAuth and JSON responses

#Overview Here's another library based on the LinkedIn API, OAuth and JSON responses. Hope this documentation explains everything you need to get star

Mike Helmick 69 Dec 11, 2022
A simple Telegram bot that analyses a given word, built with python-telegram-bot

Telegram Word Bot A simple Telegram bot that analyses a given word, built with python-telegram-bot. The bot is fairly useless - unless you often need

Chris N 2 Jul 14, 2022
A Python Library to interface with Flickr REST API, OAuth & JSON Responses

Python-Flickr Python-Flickr is A Python library to interface with Flickr REST API & OAuth Features Photo Uploading Retrieve user information Common Fl

Mike Helmick 40 Sep 25, 2021
A Python Library to interface with Tumblr v2 REST API & OAuth

Tumblpy Tumblpy is a Python library to help interface with Tumblr v2 REST API & OAuth Features Retrieve user information and blog information Common T

Mike Helmick 125 Jun 20, 2022
Python Client Library to interface with the Phoenix Realtime Server

supabase-realtime-client Python Client Library to interface with the Phoenix Realtime Server This is a fork of the supabase community realtime client

Anand 2 May 24, 2022
First Party data integration solution built for marketing teams to enable audience and conversion onboarding into Google Marketing products (Google Ads, Campaign Manager, Google Analytics).

Megalista Sample integration code for onboarding offline/CRM data from BigQuery as custom audiences or offline conversions in Google Ads, Google Analy

Google 76 Dec 29, 2022
Deep reinforcement learning library built on top of Neural Network Libraries

Deep Reinforcement Learning Library built on top of Neural Network Libraries NNablaRL is a deep reinforcement learning library built on top of Neural

Sony 100 Dec 14, 2022
a simple quant trading bot with CLI interface

shepherd a simple quant trading bot with CLI interface CLI shell command docs coming soon after I brush up the code and add more features :) Minimal R

m00n 0 Jun 6, 2022
:snake: A simple library to fetch data from the iTunes Store API made for Python >= 3.5

itunespy itunespy is a simple library to fetch data from the iTunes Store API made for Python 3.5 and beyond. Important: Since version 1.6 itunespy no

Fran González 56 Dec 22, 2022
A simple Python library to integrate with the Heron Data API

Heron Python This library provides easy access to the Heron Data API from applications written in Python. Documentation No language-specific docs are

Heron Data 11 Nov 11, 2022
Dribble sign up screen built in python and kivy

Dribble sign up screen built in python and kivy contains Dribble icon with icon position and shadow animation.

null 1 Dec 6, 2021
Minimal Python client for the Iris API, built on top of Authlib and httpx.

??️ Iris Python Client Minimal Python client for the Iris API, built on top of Authlib and httpx. Installation pip install dioptra-iris-client Usage f

Dioptra 1 Jan 28, 2022
A Python interface to AFL, allowing for easy injection of testcases and other functionality.

Fuzzer This module provides a Python wrapper for interacting with AFL (American Fuzzy Lop: http://lcamtuf.coredump.cx/afl/). It supports starting an A

Shellphish 614 Dec 26, 2022
A Python interface module to the SAS System. It works with Linux, Windows, and mainframe SAS. It supports the sas_kernel project (a Jupyter Notebook kernel for SAS) or can be used on its own.

A Python interface to MVA SAS Overview This module creates a bridge between Python and SAS 9.4. This module enables a Python developer, familiar with

SAS Software 319 Dec 19, 2022