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[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
Releases(release-v1.8.51)
Owner
AKFamily
AKFamily is the family of AKShare
AKFamily
AWS Glue PySpark - Apache Hudi Quick Start Guide

AWS Glue PySpark - Apache Hudi Quick Start Guide Disclaimer: This is a quick start guide for the Apache Hudi Python Spark connector, running on AWS Gl

Gabriel Amazonas Mesquita 8 Nov 14, 2022
A Telegram Bot Plays With Words!!!

TheWordzBot ➠ I Can Turn Text Into Audio ➠ I Can Get Results From Dictionary ➠ I Can Make Google Search For You ➠ I Can Suggest Strong Passwords For Y

RAVEEN KUMAR 8 Feb 28, 2022
Web app for spotify playlist management with last.fm integration

Music Tools Set of utility tools for Spotify and Last.fm. Built on my other libraries for Spotify (spotframework), Last.fm (fmframework) and interfaci

andy 3 Dec 14, 2022
This Lambda will Pull propagated routes from TGW and update VPC route table

AWS-Transitgateway-Route-Propagation This Lambda will Pull propagated routes from TGW and update VPC route table. Tested on python 3.8 Lambda AWS INST

4 Jan 20, 2022
AWS SQS event redrive Lambda With Python

AWS SQS event redrive Lambda This repository contains one simple AWS Lambda function in Python to redrive AWS SQS events from source queue to destinat

1 Oct 19, 2021
Telegram forwarder

Telegram Forwarder Quick Start This application using docker, docker-compose to run. So I suppose that you can install these two things. Prepare essen

10 Dec 20, 2022
Automatically mass follows tons of NameMC profiles.

Automatically mass follows tons of NameMC profiles. (Creates REAL traffic to your profile)

Jam 3 Jun 29, 2022
Flood discord webhooks

Webhook-Spammer Flood discord webhooks Asynchronous webhook spammer Fast & Efficient Usage - Use it with atleast 500 threads Put a valid webhook Use a

trey 1 Apr 22, 2022
TORNADO CASH Pancakeswap Sniper BOT 2022-V1 (MAC WINDOWS ANDROID LINUX)

TORNADO CASH Pancakeswap Sniper BOT 2022-V1 (MAC WINDOWS ANDROID LINUX)

Crypto Trader 1 Jan 06, 2022
This is RequestTrackerBot and it used for tracking request made by user in a group

This is a Request Tracker Bot repo, It is for those who upload content like movies, anime, etc. It can be used for tracking request of content that your members asked for.

Abhijeet 27 Dec 29, 2022
Discord Online Account Forever

💠 Discord-Online-Account-Forever Discord Online Account Forever 📸 Tutorial Token Discord NEVER SHARE YOUR TOKEN Installation Replit 🧿 Replit : Here

nimaisox 2 Nov 28, 2021
A QQ(Tencent) robot created by go-cqhttp & nonebot2

绘梨花(胶布)Bot|ErikaBot ✨ 基于NoneBot2的绘梨花多功能 Bot ,自用 ✨ 快速开始 参考go-cqhttp项目文档,配置好机器人的相关设置,以及反向ws客户端 参考nonebot2项目文档,添加必要的.env相关设置 安装本项目相关的依赖库(依赖清单) git clone本

10 Aug 09, 2022
Updated version of A discord token/password grabber thats grabs all of their tokens, passwords, credit card + alot more

Updated version of A discord token/password grabber thats grabs all of their tokens, passwords, credit card + alot more

Rdimo 556 Aug 05, 2022
A youtube search telegram bot.

YouTube-Search-Bot A youtube search telegram bot. Made with Python3 (C) @FayasNoushad Copyright permission under MIT License License - https://github

Fayas Noushad 22 Nov 12, 2022
Utility for downloading fanfiction in bulk from the Archive of Our Own

What is this? This is a program intended to help you download fanfiction from the Archive of Our Own in bulk. This program is primarily intended to wo

73 Dec 30, 2022
Plataforma para atendimento a outras empresas que necessitam de atendimento técnico.

Plataforma para atendimento a outras empresas que necessitam de atendimento técnico. É possível que os usuarios de empresas parceiras registrem solici

Kelvin Alisson Cantarino 2 Jun 29, 2022
OpenSea Bulk Uploader And Trader 100000 NFTs (MAC WINDOWS ANDROID LINUX) Automatically and massively upload and sell your non-fungible tokens on OpenSea using Python Selenium

OpenSea Bulk Uploader And Trader 100000 NFTs (MAC WINDOWS ANDROID LINUX) Automatically and massively upload and sell your non-fungible tokens on OpenS

ERC-7211 3 Mar 24, 2022
A basic Ubisoft API wrapper created in python.

UbisoftAPI A basic Ubisoft API wrapper created in python. I will be updating this with more endpoints as time goes on. Please note that this is my fir

Ethan 2 Oct 31, 2021
Simple Telegram webscrap bot

webscrap-bot Simple Telegram webscrap bot Configs TOKEN - Get bot token from @BotFather API_ID - From my.telegram.org API_HASH - From my.telegram.org

lokaman chendekar 10 Oct 21, 2022
A free tempmail api for your needs!

Tempmail A free tempmail api for your needs! Website · Report Bug · Request Feature Features Add your own private domains Easy to use documentation No

dropout 10 Oct 26, 2021