├── akshare ├── pro │ ├── __init__.py │ ├── cons.py │ ├── data_pro.py │ └── client.py ├── air │ ├── __init__.py │ └── air_hebei.py ├── fx │ ├── __init__.py │ └── cons.py ├── hf │ ├── __init__.py │ └── hf_sp500.py ├── nlp │ ├── __init__.py │ └── nlp_interface.py ├── ws │ ├── __init__.py │ ├── argus.py │ └── js_ws_news.py ├── article │ ├── __init__.py │ ├── cons.py │ ├── agoyal.py │ ├── epu_index.py │ └── fred_md.py ├── bank │ ├── __init__.py │ └── cons.py ├── bond │ ├── __init__.py │ ├── bond_futures.py │ ├── bond_convert.py │ ├── china_repo.py │ ├── cons.py │ ├── bond_china_money.py │ ├── bond_em.py │ ├── bond_summary.py │ ├── zh_bond_sina.py │ └── bond_bank.py ├── charity │ └── __init__.py ├── cost │ ├── __init__.py │ ├── cons.py │ └── cost_living.py ├── crypto │ ├── __init__.py │ └── crypto_hold.py ├── currency │ └── __init__.py ├── energy │ ├── __init__.py │ └── energy_oil.py ├── event │ ├── __init__.py │ └── franchise.py ├── fortune │ ├── __init__.py │ ├── forbes_500.py │ ├── xincaifu_500.py │ ├── fortune_bloomberg.py │ └── cons.py ├── fund │ ├── __init__.py │ ├── fund_em_init.py │ ├── fund_em_portfolio.py │ ├── fund_etf.py │ └── fund_manager.py ├── futures │ ├── __init__.py │ ├── futures_rule.py │ ├── futures_contract_detail.py │ ├── futures_comex.py │ ├── futures_foreign.py │ ├── futures_sgx_daily.py │ ├── futures_inventory_em.py │ ├── futures_em_spot_stock.py │ ├── futures_cfmmc.py │ └── requests_fun.py ├── index │ ├── __init__.py │ ├── exceptions.py │ ├── index_google.py │ ├── index_spot.py │ ├── zh_stock_index_csindex.py │ ├── drewry_index.py │ ├── index_yw.py │ ├── index_eri.py │ ├── index_kq_fz.py │ ├── index_weibo.py │ └── index_kq_ss.py ├── movie │ └── __init__.py ├── news │ ├── __init__.py │ ├── cctv_news.py │ └── stock_news.py ├── option │ ├── __init__.py │ ├── czce_option.py │ └── option_em.py ├── other │ └── __init__.py ├── qhkc │ └── __init__.py ├── qhkc_web │ └── __init__.py ├── rate │ ├── __init__.py │ └── repo_rate.py ├── stock │ ├── __init__.py │ ├── stock_zh_a_new.py │ ├── stock_js_us.py │ ├── zh_stock_kcb_report.py │ ├── stock_us_yahoo.py │ └── stock_weibo_nlp.py ├── tool │ ├── __init__.py │ └── trade_date_hist.py ├── utils │ ├── __init__.py │ └── token_process.py ├── economic │ ├── __init__.py │ └── marco_cnbs.py ├── file_fold │ └── __init__.py ├── interest_rate │ └── __init__.py ├── stock_feature │ ├── __init__.py │ ├── cons.py │ ├── stock_em_tfp.py │ ├── stock_legu_market.py │ ├── stock_a_high_low.py │ ├── stock_a_below_net_asset_statistics.py │ ├── stock_em_comment.py │ ├── stock_em_gdzjc.py │ ├── stock_em_fhps.py │ ├── stock_cninfo_yjyg.py │ ├── stock_em_account.py │ ├── stock_em_qsjy.py │ ├── stock_lh_yybpm.py │ └── stock_em_yzxdr.py ├── stock_fundamental │ ├── __init__.py │ ├── stock_ipo_declare.py │ └── stock_notice.py ├── futures_derivative │ ├── __init__.py │ ├── jyfm_login_func.py │ ├── futures_xgx.py │ └── nh_index_return.py └── wdbank │ ├── wdbank_doit.py │ └── __init__.py ├── example └── images │ ├── ds.png │ └── AKShare_logo.jpg ├── tests ├── __init__.py └── test_func.py ├── docs ├── requirements.txt ├── data │ ├── qhkc │ │ ├── index.rst │ │ └── tools.md │ ├── index.rst │ ├── hf │ │ └── hf.md │ └── tool │ │ └── tool.md ├── strategy.md ├── platform.md ├── topic │ ├── index.rst │ ├── anaconda │ │ └── index.rst │ └── pandas │ │ └── index.rst ├── Makefile ├── make.bat ├── index.rst ├── _templates │ └── layout.html ├── README.rst ├── akdocker │ └── akdocker.md ├── answer.md └── conf.py ├── CONTRIBUTING.md ├── .github ├── ISSUE_TEMPLATE │ ├── custom.md │ ├── akshare-----.md │ ├── feature_request.md │ └── bug_report.md └── workflows │ ├── bulid.yml │ └── release_and_deploy.yml ├── .readthedocs.yml ├── Dockerfile ├── .gitignore ├── requirements.txt ├── LICENSE └── setup.py /akshare/pro/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /example/images/ds.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rockyzsu/akshare/master/example/images/ds.png -------------------------------------------------------------------------------- /example/images/AKShare_logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rockyzsu/akshare/master/example/images/AKShare_logo.jpg -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2019/12/12 18:16 5 | Desc: 6 | """ 7 | -------------------------------------------------------------------------------- /akshare/air/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2019/9/30 13:58 5 | Desc: 6 | """ 7 | -------------------------------------------------------------------------------- /akshare/fx/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2019/10/20 10:57 5 | Desc: 6 | """ 7 | -------------------------------------------------------------------------------- /akshare/hf/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/4/21 15:33 5 | Desc: 6 | """ 7 | -------------------------------------------------------------------------------- /akshare/nlp/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/3/1 0:02 5 | Desc: 6 | """ 7 | -------------------------------------------------------------------------------- /akshare/ws/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2019/11/16 22:47 5 | Desc: 6 | """ 7 | -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | sphinx 2 | sphinx-hoverxref 3 | sphinx-notfound-page 4 | sphinx_rtd_theme 5 | sphinx-markdown-tables 6 | -------------------------------------------------------------------------------- /akshare/article/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2019/11/12 14:51 5 | Desc: 6 | """ 7 | -------------------------------------------------------------------------------- /akshare/bank/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2019/11/7 14:06 5 | Desc: 6 | """ 7 | -------------------------------------------------------------------------------- /akshare/bond/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2019/9/30 13:58 5 | Desc: 6 | """ 7 | -------------------------------------------------------------------------------- /akshare/charity/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/2/21 16:03 5 | Desc: 6 | """ 7 | -------------------------------------------------------------------------------- /akshare/cost/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2019/12/18 12:32 5 | Desc: 6 | """ 7 | -------------------------------------------------------------------------------- /akshare/crypto/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/10/23 13:51 5 | Desc: 6 | """ 7 | -------------------------------------------------------------------------------- /akshare/currency/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/3/6 16:40 5 | Desc: 6 | """ 7 | -------------------------------------------------------------------------------- /akshare/energy/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2019/12/17 16:54 5 | Desc: 6 | """ 7 | -------------------------------------------------------------------------------- /akshare/event/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/1/23 9:07 5 | Desc: 6 | """ 7 | -------------------------------------------------------------------------------- /akshare/fortune/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2019/12/10 21:55 5 | Desc: 6 | """ 7 | -------------------------------------------------------------------------------- /akshare/fund/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2019/9/30 13:58 5 | Desc: 6 | """ 7 | -------------------------------------------------------------------------------- /akshare/futures/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2019/9/30 13:58 5 | Desc: 6 | """ 7 | -------------------------------------------------------------------------------- /akshare/index/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2019/9/30 13:58 5 | Desc: 6 | """ 7 | -------------------------------------------------------------------------------- /akshare/movie/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2019/12/16 20:44 5 | Desc: 6 | """ 7 | -------------------------------------------------------------------------------- /akshare/news/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/10/18 12:54 5 | Desc: 6 | """ 7 | -------------------------------------------------------------------------------- /akshare/option/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2019/9/30 13:58 5 | Desc: 6 | """ 7 | -------------------------------------------------------------------------------- /akshare/other/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2021/5/14 17:52 5 | Desc: 6 | """ 7 | -------------------------------------------------------------------------------- /akshare/qhkc/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2019/9/30 13:58 5 | Desc: 6 | """ 7 | -------------------------------------------------------------------------------- /akshare/qhkc_web/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2019/9/30 13:58 5 | Desc: 6 | """ 7 | -------------------------------------------------------------------------------- /akshare/rate/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/10/29 13:03 5 | Desc: 6 | """ 7 | -------------------------------------------------------------------------------- /akshare/stock/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2019/10/25 15:55 5 | Desc: 6 | """ 7 | -------------------------------------------------------------------------------- /akshare/tool/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2019/9/30 13:58 5 | Desc: 6 | """ 7 | -------------------------------------------------------------------------------- /akshare/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/2/13 21:21 5 | Desc: 6 | """ 7 | -------------------------------------------------------------------------------- /akshare/economic/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2019/10/21 12:08 5 | Desc: 6 | """ 7 | -------------------------------------------------------------------------------- /akshare/file_fold/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2019/9/30 13:58 5 | Desc: 6 | """ 7 | -------------------------------------------------------------------------------- /akshare/interest_rate/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/1/10 17:09 5 | Desc: 6 | """ 7 | -------------------------------------------------------------------------------- /akshare/stock_feature/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2019/12/27 18:02 5 | Desc: 6 | """ 7 | -------------------------------------------------------------------------------- /akshare/stock_fundamental/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/5/14 15:34 5 | Desc: 6 | """ 7 | -------------------------------------------------------------------------------- /akshare/futures_derivative/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2019/10/27 19:45 5 | Desc: 6 | """ 7 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Developing 2 | 3 | If you already cloned the repository, you know that you need to deep dive in the code, here are some guidelines to set up your environment. 4 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/custom.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Custom issue template 3 | about: Describe this issue template's purpose here. 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | -------------------------------------------------------------------------------- /akshare/pro/cons.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/12/24 16:28 5 | Desc: API常量文件 6 | """ 7 | TOKEN_F_P = 'tk.csv' 8 | TOKEN_ERR_MSG = '请设置 AKShare pro 的 token 凭证码,如果没有权限,请访问 https://qhkch.com/ 注册申请' 9 | -------------------------------------------------------------------------------- /docs/data/qhkc/index.rst: -------------------------------------------------------------------------------- 1 | AKShare 奇货可查 2 | ================= 3 | 4 | AkShare 奇货可查模块主要介绍奇货可查提供的数据接口的详细说明 5 | 6 | .. toctree:: 7 | :maxdepth: 2 8 | 9 | commodity.md 10 | broker.md 11 | index_data.md 12 | fundamental.md 13 | tools.md 14 | fund.md -------------------------------------------------------------------------------- /akshare/wdbank/wdbank_doit.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/3/17 20:57 5 | Desc: world bank interface test file 6 | """ 7 | from akshare import wdbank 8 | 9 | wdbank.get_source() 10 | wdbank.get_data("NY.GDP.PCAP.PP.CD", country=["CHN", "USA"]) 11 | -------------------------------------------------------------------------------- /akshare/index/exceptions.py: -------------------------------------------------------------------------------- 1 | class ResponseError(Exception): 2 | """Something was wrong with the response from Google""" 3 | 4 | def __init__(self, message, response): 5 | super(Exception, self).__init__(message) 6 | 7 | # pass response so it can be handled upstream 8 | self.response = response 9 | -------------------------------------------------------------------------------- /akshare/article/cons.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2019/11/14 20:32 5 | Desc: 学术板块配置文件 6 | """ 7 | # EPU 8 | epu_home_url = "http://www.policyuncertainty.com/index.html" 9 | 10 | # FF-Factor 11 | ff_home_url = "http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/data_library.html" 12 | -------------------------------------------------------------------------------- /.readthedocs.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | #formats: all 3 | sphinx: 4 | configuration: docs/conf.py 5 | fail_on_warning: true 6 | python: 7 | # For available versions, see: 8 | # https://docs.readthedocs.io/en/stable/config-file/v2.html#build-image 9 | version: 3.7 10 | install: 11 | - requirements: docs/requirements.txt 12 | - path: . 13 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # https://github.com/nikolaik/docker-python-nodejs 2 | FROM nikolaik/python-nodejs:python3.8-nodejs16 3 | 4 | MAINTAINER Albert King 5 | 6 | # RUN pip install akshare jupyterlab -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host=mirrors.aliyun.com --upgrade 7 | RUN pip install akshare jupyterlab scikit-learn scipy --upgrade 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.bak 2 | 3 | *.pyc 4 | 5 | *.xml 6 | 7 | *.tar.gz 8 | 9 | *.iml 10 | 11 | *.zip 12 | 13 | *.icls 14 | 15 | /_windows/ 16 | 17 | /codestyles/ 18 | 19 | # Temp 20 | build/ 21 | docs/_build/ 22 | dist/ 23 | *.egg-info/ 24 | colors 25 | 26 | 27 | # IDE 28 | .idea/ 29 | 30 | # jupyter 31 | .ipynb_checkpoints 32 | #docs/source/_static/ 33 | #docs/source/_templates/ 34 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/akshare-----.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: AKShare-问题报告 3 | about: 反馈接口相关的问题 4 | title: AKShare 接口问题报告 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **遇到任何问题,请先确认您的 AKShare 版本是最新的** 11 | ``` 12 | pip install akshare --upgrade # Python 版本需要大于 3.7 13 | ``` 14 | 15 | **描述遇到的问题** 16 | 1. 操作系统版本 17 | 2. Python 版本 18 | 3. AKShare 版本 19 | 4. 接口的名称和代码 20 | 5. 接口报错的截图或代码 21 | 6. 期望获得的正确结果 22 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | beautifulsoup4>=4.9.1 2 | lxml>=4.2.1 3 | matplotlib>=3.1.1 4 | numpy>=1.17.2 5 | pandas>=0.25 6 | requests>=2.22.0 7 | urllib3>=1.25.6 8 | demjson>=2.2.4 9 | pillow>=6.2.1 10 | pypinyin>=0.35.0 11 | websocket-client>=0.56.0 12 | html5lib>=1.0.1 13 | tqdm>=4.43.0 14 | xlrd==1.2.0 15 | openpyxl>=3.0.3 16 | jsonpath>=0.82 17 | tabulate>=0.8.6 18 | decorator>=4.4.2 19 | py_mini_racer>=0.4.0 20 | -------------------------------------------------------------------------------- /docs/strategy.md: -------------------------------------------------------------------------------- 1 | # [AKShare](https://github.com/jindaxiang/akshare) 量化策略 2 | 3 | [掘金量化策略文档](https://jfds-1252952517.cos.ap-chengdu.myqcloud.com/akshare/readme/strategy/classic_strategy_myquant.pdf) 4 | 5 | 目录 6 | - 双均线策略(期货) 7 | - alpha对冲(股票+期货) 8 | - 集合竞价选股(股票) 9 | - 多因子选股(股票) 10 | - 网格交易(期货) 11 | - 指数增强(股票) 12 | - 跨品种套利(期货) 13 | - 跨期套利(期货) 14 | - 日内回转交易(股票) 15 | - 做市商交易(期货) 16 | - 海龟交易法(期货) 17 | - 行业轮动(股票) 18 | - 机器学习(股票) -------------------------------------------------------------------------------- /akshare/wdbank/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/3/17 20:40 5 | Desc: 6 | """ 7 | __version__ = "0.3.0-dev" 8 | 9 | from .api import ( 10 | get_country, 11 | get_data, 12 | get_series, 13 | get_dataframe, 14 | get_indicator, 15 | get_incomelevel, 16 | get_lendingtype, 17 | get_source, 18 | get_topic, 19 | search_countries, 20 | search_indicators, 21 | ) 22 | -------------------------------------------------------------------------------- /docs/platform.md: -------------------------------------------------------------------------------- 1 | # [AKShare](https://github.com/jindaxiang/akshare) 量化平台 2 | 3 | ## 目录 4 | 5 | ### 开源平台 6 | 7 | - [VN.PY](https://www.vnpy.com/) 8 | - [功夫量化](https://www.kungfu-trader.com/) 9 | - [Backtrader](https://www.backtrader.com/) 10 | 11 | ### 网页端 12 | 13 | - [JoinQuant](https://www.joinquant.com/) 14 | - [MyQuant](https://www.myquant.cn/) 15 | - [BigQuant](https://bigquant.com/) 16 | - [WindQuant](https://www.windquant.com/) 17 | - [DigQuant](http://www.digquant.com.cn/) 18 | -------------------------------------------------------------------------------- /docs/topic/index.rst: -------------------------------------------------------------------------------- 1 | AKShare 专题教程 2 | ================== 3 | 4 | 专题教程主要介绍数据科学的入门内容; 5 | 6 | 包含数据科学的基础工具: 7 | 8 | 1. Python-Pandas; 9 | 2. Python-Numpy; 10 | 3. Python-Matplotlib; 11 | 12 | .. toctree:: 13 | :maxdepth: 2 14 | 15 | anaconda/index 16 | pandas/index 17 | 18 | 特别感谢: 19 | 20 | |image0| 21 | 22 | .. |image0| image:: https://upload-images.jianshu.io/upload_images/3240514-61004f2c71be4a0b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240 23 | 24 | 对 Anaconda 和 Pandas 板块的大力支持, 欢迎大家扫码关注! 25 | -------------------------------------------------------------------------------- /tests/test_func.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/10/12 18:16 5 | Desc: To test intention, just write test code here! 6 | """ 7 | from akshare.cost.cost_living import cost_living 8 | 9 | 10 | def test_cost_living(): 11 | """ 12 | just for test aim 13 | :return: assert result 14 | :rtype: assert 15 | """ 16 | cost_living_df = cost_living() 17 | assert cost_living_df.shape[0] > 0 18 | 19 | 20 | if __name__ == "__main__": 21 | test_cost_living() 22 | -------------------------------------------------------------------------------- /docs/topic/anaconda/index.rst: -------------------------------------------------------------------------------- 1 | Anaconda 教程 2 | ============== 3 | 4 | .. note:: 5 | 6 | 专题教程-Anaconda教程内容来自于 Python 公众号: *Python大咖谈* ; 7 | 8 | 欢迎大家扫码关注公众号, 公众号文章同时也会在本文档持续连载, 方便在线阅读. 9 | 10 | 特别感谢 *Python大咖谈* 作者: 呆鸟 11 | 12 | |image0| 13 | 14 | .. |image0| image:: https://upload-images.jianshu.io/upload_images/3240514-61004f2c71be4a0b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240 15 | 16 | 本专题主要介绍 Anaconda3 的内容; 17 | 18 | .. toctree:: 19 | :maxdepth: 2 20 | 21 | anaconda-00 22 | anaconda-01 23 | -------------------------------------------------------------------------------- /akshare/stock_feature/cons.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2019/12/30 21:02 5 | Desc: 6 | """ 7 | stock_em_sy_js = """ 8 | function getCode(num) { 9 | var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; 10 | var codes = str.split(''); 11 | num = num || 6; 12 | var code = ""; 13 | for (var i = 0; i < num; i++) { 14 | code += codes[Math.floor(Math.random() * 52)] 15 | } 16 | return code 17 | } 18 | """ 19 | -------------------------------------------------------------------------------- /docs/data/index.rst: -------------------------------------------------------------------------------- 1 | AKShare 数据字典 2 | ================= 3 | 4 | 数据字典主要介绍 AkShare 提供的数据接口的详细说明 5 | 6 | .. toctree:: 7 | :maxdepth: 6 8 | 9 | stock/stock 10 | futures/futures 11 | bond/bond 12 | option/option 13 | fx/fx 14 | currency/currency 15 | interest_rate/interest_rate 16 | fund/fund_private 17 | fund/fund_public 18 | index/index 19 | macro/macro 20 | dc/dc 21 | bank/bank 22 | article/article 23 | ws/ws 24 | energy/energy 25 | event/event 26 | hf/hf 27 | nlp/nlp 28 | others/others 29 | qhkc/index 30 | tool/tool 31 | -------------------------------------------------------------------------------- /docs/topic/pandas/index.rst: -------------------------------------------------------------------------------- 1 | Pandas 教程 2 | ============ 3 | 4 | .. note:: 5 | 6 | 专题教程-Pandas教程内容来自于 Python 公众号: *Python大咖谈* ; 7 | 8 | 欢迎大家扫码关注公众号, 公众号文章同时也会在本文档持续连载, 方便在线阅读. 9 | 10 | 特别感谢 *Python大咖谈* 作者: 呆鸟 11 | 12 | |image0| 13 | 14 | .. |image0| image:: https://upload-images.jianshu.io/upload_images/3240514-61004f2c71be4a0b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240 15 | 16 | 本专题主要介绍 Pandas0.25+ 库的内容; 17 | 18 | .. toctree:: 19 | :maxdepth: 2 20 | :numbered: 2 21 | 22 | pandas-00 23 | pandas-01 24 | pandas-02 25 | pandas-03 26 | pandas-04 27 | pandas-05 28 | -------------------------------------------------------------------------------- /akshare/cost/cons.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2019/12/18 12:50 5 | Desc: cost配置文件 6 | """ 7 | url = "https://www.expatistan.com/cost-of-living/index" 8 | name_url_map = { 9 | "europe": "/cost-of-living/index/europe", 10 | "north-america": "/cost-of-living/index/north-america", 11 | "latin-america": "/cost-of-living/index/latin-america", 12 | "asia": "/cost-of-living/index/asia", 13 | "middle-east": "/cost-of-living/index/middle-east", 14 | "africa": "/cost-of-living/index/africa", 15 | "oceania": "/cost-of-living/index/oceania", 16 | "world": "/cost-of-living/index", 17 | } 18 | -------------------------------------------------------------------------------- /akshare/fx/cons.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2019/10/20 10:58 5 | Desc: 外汇配置文件 6 | """ 7 | # headers 8 | SHORT_HEADERS = { 9 | 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.91 Safari/537.36' 10 | } 11 | # url 12 | FX_SPOT_URL = "http://www.chinamoney.com.cn/r/cms/www/chinamoney/data/fx/rfx-sp-quot.json" 13 | FX_SWAP_URL = "http://www.chinamoney.com.cn/r/cms/www/chinamoney/data/fx/rfx-sw-quot.json" 14 | FX_PAIR_URL = "http://www.chinamoney.com.cn/r/cms/www/chinamoney/data/fx/cpair-quot.json" 15 | # payload 16 | SPOT_PAYLOAD = { 17 | "t": {} 18 | } 19 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | 3 | # You can set these variables from the command line. 4 | SPHINXOPTS = 5 | SPHINXBUILD = sphinx-build 6 | SPHINXPROJ = ReadtheDocsSphinxTheme 7 | SOURCEDIR = . 8 | BUILDDIR = build 9 | 10 | # Put it first so that "make" without argument is like "make help". 11 | help: 12 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 13 | 14 | .PHONY: help Makefile 15 | 16 | # Catch-all target: route all unknown targets to Sphinx using the new 17 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 18 | %: Makefile 19 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /akshare/utils/token_process.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/2/13 21:22 5 | Desc: 存储和读取Token文件 6 | """ 7 | import os 8 | 9 | import pandas as pd 10 | 11 | from akshare.pro import cons 12 | 13 | 14 | def set_token(token): 15 | df = pd.DataFrame([token], columns=['token']) 16 | user_home = os.path.expanduser('~') 17 | fp = os.path.join(user_home, cons.TOKEN_F_P) 18 | df.to_csv(fp, index=False) 19 | 20 | 21 | def get_token(): 22 | user_home = os.path.expanduser('~') 23 | fp = os.path.join(user_home, cons.TOKEN_F_P) 24 | if os.path.exists(fp): 25 | df = pd.read_csv(fp) 26 | return str(df.iloc[0]['token']) 27 | else: 28 | print(cons.TOKEN_ERR_MSG) 29 | return None 30 | 31 | 32 | if __name__ == '__main__': 33 | pass 34 | -------------------------------------------------------------------------------- /akshare/pro/data_pro.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2019/11/10 22:52 5 | Desc: 数据接口初始化 6 | """ 7 | from akshare.pro import client 8 | from akshare.utils import token_process 9 | 10 | 11 | def pro_api(token=''): 12 | """ 13 | 初始化 pro API,第一次可以通过ak.set_token('your token')来记录自己的token凭证,临时token可以通过本参数传入 14 | """ 15 | if token == '' or token is None: 16 | token = token_process.get_token() 17 | if token is not None and token != '': 18 | pro = client.DataApi(token) 19 | return pro 20 | else: 21 | raise Exception('api init error.') 22 | 23 | 24 | if __name__ == '__main__': 25 | pro_test = pro_api() 26 | variety_all_df = pro_test.variety_all() 27 | print(variety_all_df) 28 | variety_no_futures_df = pro_test.variety_no_futures(symbol="RB", date="2018-08-08") 29 | print(variety_no_futures_df) 30 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR = . 11 | set BUILDDIR = build 12 | 13 | if "%1" == "" goto help 14 | 15 | %SPHINXBUILD% >NUL 2>NUL 16 | if errorlevel 9009 ( 17 | echo. 18 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 19 | echo.installed, then set the SPHINXBUILD environment variable to point 20 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 21 | echo.may add the Sphinx directory to PATH. 22 | echo. 23 | echo.If you don't have Sphinx installed, grab it from 24 | echo.http://sphinx-doc.org/ 25 | exit /b 1 26 | ) 27 | 28 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 29 | goto end 30 | 31 | :help 32 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 33 | 34 | :end 35 | popd 36 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. AKShare documentation master file, created by 2 | sphinx-quickstart on Fri Oct 11 00:10:59 2019. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to AKShare's Online Documentation! 7 | =========================================== 8 | 9 | .. note:: 10 | 11 | Please visit `AkShare's Github`_ for source code or visit `Github Issues`_ if you have any question! 12 | 13 | .. _AkShare's Github: https://github.com/jindaxiang/akshare 14 | 15 | .. _Github Issues: https://github.com/jindaxiang/akshare/issues 16 | 17 | .. toctree:: 18 | :maxdepth: 2 19 | :glob: 20 | :caption: Table of contents: 21 | 22 | introduction 23 | installation 24 | akdocker/akdocker 25 | contributor 26 | answer 27 | tutorial 28 | data/index 29 | anaconda 30 | special 31 | strategy 32 | platform 33 | topic/index 34 | demo 35 | changelog 36 | 37 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /akshare/index/index_google.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2019/12/4 15:49 5 | Desc: 获取谷歌指数, 必须使用代理, 获得的数据是小时频率的, 所以获取时间周期太长会很慢 6 | """ 7 | from akshare.index.request import TrendReq 8 | import matplotlib.pyplot as plt 9 | 10 | 11 | def google_index( 12 | word="python", start_date="2019-12-01", end_date="2019-12-04", plot=True 13 | ): 14 | """ 15 | 返回指定区间的谷歌指数 16 | """ 17 | pytrends = TrendReq(hl="en-US", tz=360) 18 | kw_list = [word] 19 | pytrends.build_payload( 20 | kw_list, cat=0, timeframe=start_date + " " + end_date, geo="", gprop="" 21 | ) 22 | search_df = pytrends.interest_over_time() 23 | if plot: 24 | search_df[word].plot() 25 | plt.legend() 26 | plt.show() 27 | return search_df[word] 28 | return search_df[word] 29 | 30 | 31 | if __name__ == "__main__": 32 | google_index_df = google_index( 33 | word="AI", start_date="2019-12-10T10", end_date="2019-12-10T23", plot=True 34 | ) 35 | print(google_index_df) 36 | -------------------------------------------------------------------------------- /akshare/economic/marco_cnbs.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/12/28 15:22 5 | Desc: 国家金融与发展实验室-中国宏观杠杆率数据 6 | http://114.115.232.154:8080/ 7 | """ 8 | import pandas as pd 9 | 10 | 11 | def macro_cnbs() -> pd.DataFrame: 12 | """ 13 | 国家金融与发展实验室-中国宏观杠杆率数据 14 | http://114.115.232.154:8080/ 15 | :return: 中国宏观杠杆率数据 16 | :rtype: pandas.DataFrame 17 | """ 18 | url = "http://114.115.232.154:8080/handler/download.ashx" 19 | temp_df = pd.read_excel(url, sheet_name="Data", header=0, skiprows=1, engine="openpyxl") 20 | temp_df["Period"] = pd.to_datetime(temp_df["Period"]).dt.strftime("%Y-%m") 21 | temp_df.dropna(axis=1, inplace=True) 22 | temp_df.columns = [ 23 | "年份", 24 | "居民部门", 25 | "非金融企业部门", 26 | "政府部门", 27 | "中央政府", 28 | "地方政府", 29 | "实体经济部门", 30 | "金融部门资产方", 31 | "金融部门负债方", 32 | ] 33 | return temp_df 34 | 35 | 36 | if __name__ == '__main__': 37 | macro_cnbs_df = macro_cnbs() 38 | print(macro_cnbs_df) 39 | -------------------------------------------------------------------------------- /akshare/hf/hf_sp500.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/4/21 15:34 5 | Desc: 高频数据-标普 500 指数 6 | https://github.com/FutureSharks/financial-data 7 | long history data for S&P 500 index daily 8 | http://www.econ.yale.edu/~shiller/data.htm 9 | """ 10 | import pandas as pd 11 | 12 | 13 | def hf_sp_500(year: str = "2017") -> pd.DataFrame: 14 | """ 15 | S&P 500 minute data from 2012-2018 16 | :param year: from 2012-2018 17 | :type year: str 18 | :return: specific year dataframe 19 | :rtype: pandas.DataFrame 20 | """ 21 | url = f"https://github.com/FutureSharks/financial-data/raw/master/pyfinancialdata/data/stocks/histdata/SPXUSD/DAT_ASCII_SPXUSD_M1_{year}.csv" 22 | temp_df = pd.read_table(url, header=None, sep=";") 23 | temp_df.columns = ["date", "open", "high", "low", "close", "price"] 24 | temp_df.index = pd.to_datetime(temp_df.date) 25 | del temp_df["date"] 26 | return temp_df.iloc[:, :-1] 27 | 28 | 29 | if __name__ == '__main__': 30 | hf_sp_500_df = hf_sp_500(year="2017") 31 | print(hf_sp_500_df) 32 | -------------------------------------------------------------------------------- /akshare/futures/futures_rule.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/7/12 21:51 5 | Desc: 国泰君安期货-交易日历数据表 6 | https://www.gtjaqh.com/pc/calendar.html 7 | """ 8 | import pandas as pd 9 | import requests 10 | 11 | 12 | def futures_rule(trade_date: str = "20200712") -> pd.DataFrame: 13 | """ 14 | 国泰君安期货-交易日历数据表 15 | https://www.gtjaqh.com/pc/calendar.html 16 | :return: 交易日历数据 17 | :rtype: pandas.DataFrame 18 | """ 19 | url = "https://www.gtjaqh.com/fn/128" 20 | params = {"base_date": f"{trade_date}"} 21 | r = requests.post(url, json=params) 22 | temp_df = pd.DataFrame(r.json()["data"]) 23 | temp_df = temp_df[temp_df["tradingday"] == trade_date] 24 | if not temp_df["events"].values[0]: 25 | return f"{trade_date} 查询时间过早或者不是交易日" 26 | else: 27 | table_df = pd.read_html(temp_df["events"].values[0][0]["content"], header=1)[0] 28 | table_df.dropna(axis=1, how="all", inplace=True) 29 | return table_df 30 | 31 | 32 | if __name__ == '__main__': 33 | futures_rule_df = futures_rule(trade_date="20200915") 34 | print(futures_rule_df) 35 | -------------------------------------------------------------------------------- /akshare/index/index_spot.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2019/12/19 12:19 5 | Desc: 商品现货价格指数 6 | http://finance.sina.com.cn/futuremarket/spotprice.shtml#titlePos_0 7 | """ 8 | import json 9 | 10 | import requests 11 | import pandas as pd 12 | 13 | from akshare.index.cons import soy_url, bdi_url, gp_url, ps_url 14 | 15 | 16 | def spot_goods(symbol="波罗的海干散货指数"): 17 | """ 18 | 获取商品现货价格指数 19 | http://finance.sina.com.cn/futuremarket/spotprice.shtml#titlePos_0 20 | """ 21 | symbol_url_dict = {"进口大豆价格指数": soy_url, "波罗的海干散货指数": bdi_url, "钢坯价格指数": gp_url, "普氏62%铁矿石指数": ps_url} 22 | res = requests.get(symbol_url_dict[symbol]) 23 | res.encoding = "gbk" 24 | res_text = res.text 25 | data_json = json.loads(res_text[res_text.find("{"):res_text.rfind(")")]) 26 | data_df = pd.DataFrame(data_json["result"]["data"]["data"]) 27 | temp_df = data_df[["opendate", "price", "zde", "zdf"]] 28 | temp_df.columns = ["日期", "指数", "涨跌额", "涨跌幅"] 29 | return temp_df 30 | 31 | 32 | if __name__ == '__main__': 33 | spot_df = spot_goods(symbol="波罗的海干散货指数") 34 | print(spot_df) 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Albert King 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /akshare/ws/argus.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2021/1/26 10:39 5 | Desc: 宽客在线-阿尔戈斯全网监控预警系统 6 | https://www.quantinfo.com/Argus/ 7 | 此接口的目标网站稳定性较差, 可能造成部分时间段无法访问 8 | """ 9 | import pandas as pd 10 | import requests 11 | import urllib3 12 | 13 | 14 | def watch_argus(): 15 | """ 16 | 宽客在线-阿尔戈斯全网监控预警系统 17 | https://www.quantinfo.com/Argus/ 18 | :return: 阿尔戈斯全网监控预警系统的监控数据 19 | :rtype: pandas.DataFrame 20 | """ 21 | urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) 22 | url = "https://www.quantinfo.com/API/Argus/predict" 23 | headers = { 24 | "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36", 25 | } 26 | r = requests.get(url, headers=headers, verify=False) 27 | data_json = r.json() 28 | temp_df = pd.DataFrame(data_json) 29 | temp_df["time"] = pd.to_datetime(temp_df["time"], unit="s", utc=True).dt.tz_convert('Asia/Shanghai') 30 | return temp_df 31 | 32 | 33 | if __name__ == '__main__': 34 | watch_argus_df = watch_argus() 35 | print(watch_argus_df) 36 | -------------------------------------------------------------------------------- /akshare/article/agoyal.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/12/28 16:01 5 | Desc: 美国股市(S&P 500)的指数及其收益率,还有常用的14个经济指标 6 | http://www.hec.unil.ch/agoyal/ 7 | http://www.hec.unil.ch/agoyal/docs/PredictorData2018.xlsx 8 | """ 9 | import pandas as pd 10 | 11 | 12 | def agoyal_stock_return(indicator: str = "monthly"): 13 | """ 14 | This data will be updated every year at May 15 | :param indicator: monthly, quarterly or annual 16 | :type indicator: str 17 | :return: return data at specific indicator 18 | :rtype: pandas.DataFrame 19 | """ 20 | url = "http://www.hec.unil.ch/agoyal/docs/PredictorData2018.xlsx" 21 | if indicator == "monthly": 22 | return pd.read_excel(url, sheet_name="Monthly", engine="openpyxl") 23 | if indicator == "quarterly": 24 | return pd.read_excel(url, sheet_name="Quarterly", engine="openpyxl") 25 | if indicator == "annual": 26 | return pd.read_excel(url, sheet_name="Annual", engine="openpyxl") 27 | 28 | 29 | if __name__ == '__main__': 30 | agoyal_stock_return_df = agoyal_stock_return(indicator="monthly") 31 | print(agoyal_stock_return_df) 32 | -------------------------------------------------------------------------------- /akshare/bond/bond_futures.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/10/10 13:42 5 | Desc: 国债期货可交割券相关指标 6 | http://www.csindex.com.cn/zh-CN/bond-valuation/bond-futures-deliverable-coupons-related-indicators?date=2020-09-22 7 | """ 8 | import pandas as pd 9 | import requests 10 | 11 | 12 | def bond_futures_deliverable_coupons(trade_date: str = "2020-09-23") -> pd.DataFrame: 13 | """ 14 | 国债期货可交割券相关指标 15 | http://www.csindex.com.cn/zh-CN/bond-valuation/bond-futures-deliverable-coupons-related-indicators 16 | :param trade_date: 交易日 17 | :type trade_date: str 18 | :return: 国债期货可交割券相关指标 19 | :rtype: pandas.DataFrame 20 | """ 21 | url = "http://www.csindex.com.cn/zh-CN/bond-valuation/bond-futures-deliverable-coupons-related-indicators" 22 | params = { 23 | "date": trade_date 24 | } 25 | r = requests.get(url, params=params) 26 | temp_df = pd.read_html(r.text)[0] 27 | return temp_df 28 | 29 | 30 | if __name__ == '__main__': 31 | bond_futures_deliverable_coupons_df = bond_futures_deliverable_coupons(trade_date="2020-09-22") 32 | print(bond_futures_deliverable_coupons_df) 33 | -------------------------------------------------------------------------------- /akshare/futures/futures_contract_detail.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2021/1/6 12:52 5 | Desc: 查询期货合约当前时刻的详情 6 | https://finance.sina.com.cn/futures/quotes/V2101.shtml 7 | """ 8 | import pandas as pd 9 | import requests 10 | 11 | 12 | def futures_contract_detail(contract: str = 'AP2101') -> pd.DataFrame: 13 | """ 14 | 查询期货合约详情 15 | https://finance.sina.com.cn/futures/quotes/V2101.shtml 16 | :param contract: 合约 17 | :type contract: str 18 | :return: 期货合约详情 19 | :rtype: pandas.DataFrame 20 | """ 21 | url = f"https://finance.sina.com.cn/futures/quotes/{contract}.shtml" 22 | r = requests.get(url) 23 | r.encoding = 'gb2312' 24 | temp_df = pd.read_html(r.text)[6] 25 | data_one = temp_df.iloc[:, :2] 26 | data_one.columns = ['item', 'value'] 27 | data_two = temp_df.iloc[:, 2:4] 28 | data_two.columns = ['item', 'value'] 29 | data_three = temp_df.iloc[:, 4:] 30 | data_three.columns = ['item', 'value'] 31 | temp_df = pd.concat([data_one, data_two, data_three], axis=0, ignore_index=True) 32 | return temp_df 33 | 34 | 35 | if __name__ == '__main__': 36 | futures_contract_detail_df = futures_contract_detail(contract='V1903') 37 | print(futures_contract_detail_df) 38 | -------------------------------------------------------------------------------- /akshare/tool/trade_date_hist.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2021/1/4 13:07 5 | Desc: 新浪财经-交易日历 6 | https://finance.sina.com.cn/realstock/company/klc_td_sh.txt 7 | 此处可以用来更新 calendar.json 文件,注意末尾没有 "," 号 8 | """ 9 | from py_mini_racer import py_mini_racer 10 | import pandas as pd 11 | import requests 12 | 13 | from akshare.stock.cons import hk_js_decode 14 | 15 | 16 | def tool_trade_date_hist_sina() -> pd.DataFrame: 17 | """ 18 | 交易日历-历史数据 19 | https://finance.sina.com.cn/realstock/company/klc_td_sh.txt 20 | :return: 交易日历 21 | :rtype: pandas.DataFrame 22 | """ 23 | url = "https://finance.sina.com.cn/realstock/company/klc_td_sh.txt" 24 | r = requests.get(url) 25 | js_code = py_mini_racer.MiniRacer() 26 | js_code.eval(hk_js_decode) 27 | dict_list = js_code.call('d', r.text.split("=")[1].split(";")[0].replace('"', "")) # 执行js解密代码 28 | temp_df = pd.DataFrame(dict_list) 29 | temp_df.columns = ["trade_date"] 30 | temp_df["trade_date"] = pd.to_datetime(temp_df["trade_date"]).dt.date 31 | temp_df = temp_df.astype(str) 32 | return temp_df 33 | 34 | 35 | if __name__ == '__main__': 36 | tool_trade_date_hist_df = tool_trade_date_hist_sina() 37 | print(tool_trade_date_hist_df) 38 | -------------------------------------------------------------------------------- /akshare/bond/bond_convert.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/8/6 16:24 5 | Desc: 债券-可转债 6 | 集思录:https://app.jisilu.cn/data/cbnew/#cb 7 | """ 8 | import pandas as pd 9 | import requests 10 | 11 | 12 | def bond_cov_jsl() -> pd.DataFrame: 13 | """ 14 | 集思录可转债 15 | https://app.jisilu.cn/data/cbnew/#cb 16 | :return: 集思录可转债 17 | :rtype: pandas.DataFrame 18 | """ 19 | url = "https://app.jisilu.cn/data/cbnew/cb_list/" 20 | params = { 21 | "___jsl": "LST___t = 1596700481780", 22 | } 23 | payload = { 24 | "fprice": "", 25 | "tprice": "", 26 | "curr_iss_amt": "", 27 | "volume": "", 28 | "svolume": "", 29 | "premium_rt": "", 30 | "ytm_rt": "", 31 | "market": "", 32 | "rating_cd": "", 33 | "is_search": "N", 34 | "btype": "", 35 | # "listed": "Y", 36 | "sw_cd": "", 37 | "bond_ids": "", 38 | "rp": "50", 39 | } 40 | r = requests.post(url, params=params, data=payload) 41 | temp_df = pd.DataFrame([item["cell"] for item in r.json()["rows"]]) 42 | return temp_df 43 | 44 | 45 | if __name__ == '__main__': 46 | bond_convert_jsl_df = bond_cov_jsl() 47 | print(bond_convert_jsl_df) 48 | -------------------------------------------------------------------------------- /akshare/index/zh_stock_index_csindex.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/07/22 15:00 5 | Desc: 中证指数-所有指数-历史行情数据 6 | http://www.csindex.com.cn/zh-CN/indices/index-detail/H30374 7 | """ 8 | import pandas as pd 9 | import requests 10 | 11 | 12 | def stock_zh_index_hist_csindex(symbol: str = "H30374") -> pd.DataFrame: 13 | """ 14 | 中证指数获取某个指数的 5 年历史行情数据 15 | P.S. 只有收盘价,正常情况下不应使用该接口,除非指数只有中证网站有 16 | http://www.csindex.com.cn/zh-CN/indices/index-detail/H30374 17 | :param symbol: 指数代码; e.g., H30374 18 | :type symbol: str 19 | :return: 包含日期和收盘价的指数数据 20 | :rtype: pandas.DataFrame 21 | """ 22 | url = f"http://www.csindex.com.cn/zh-CN/indices/index-detail/{symbol}" 23 | params = { 24 | "earnings_performance": "5年", 25 | "data_type": "json" 26 | } 27 | r = requests.get(url, params=params) 28 | data_json = r.json() 29 | data_df = pd.DataFrame(data_json)[["tradedate", "tclose"]] 30 | data_df["tradedate"] = pd.to_datetime(data_df["tradedate"]) 31 | data_df.columns = ["date", "close"] 32 | return data_df 33 | 34 | 35 | if __name__ == "__main__": 36 | stock_zh_index_hist_csindex_df = stock_zh_index_hist_csindex(symbol="H30374") 37 | print(stock_zh_index_hist_csindex_df) 38 | -------------------------------------------------------------------------------- /.github/workflows/bulid.yml: -------------------------------------------------------------------------------- 1 | name: build 2 | 3 | on: 4 | push: 5 | branches: 6 | - develop 7 | pull_request: 8 | branches: 9 | - master 10 | - develop 11 | 12 | jobs: 13 | build: 14 | runs-on: ubuntu-latest 15 | strategy: 16 | matrix: 17 | os: [ubuntu-latest, macos-latest, windows-latest] 18 | python-version: [3.7, 3.8] 19 | 20 | steps: 21 | - uses: actions/checkout@v2 22 | - name: Set up Python ${{ matrix.python-version }} 23 | uses: actions/setup-python@v1 24 | with: 25 | python-version: ${{ matrix.python-version }} 26 | - name: Install dependencies 27 | run: | 28 | python -m pip install --upgrade pip 29 | pip install -r requirements.txt 30 | - name: Lint with flake8 31 | run: | 32 | pip install flake8 33 | # stop the build if there are Python syntax errors or undefined names 34 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 35 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 36 | flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 37 | - name: Test with pytest 38 | run: | 39 | pip install pytest 40 | pytest 41 | -------------------------------------------------------------------------------- /akshare/index/drewry_index.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2021/5/7 15:58 5 | Desc: Drewry集装箱指数 6 | https://www.drewry.co.uk/supply-chain-advisors/supply-chain-expertise/world-container-index-assessed-by-drewry 7 | """ 8 | import pandas as pd 9 | import requests 10 | 11 | 12 | def drewry_wci_index() -> pd.DataFrame: 13 | """ 14 | Drewry 集装箱指数 15 | https://www.drewry.co.uk/supply-chain-advisors/supply-chain-expertise/world-container-index-assessed-by-drewry 16 | :return: Drewry集装箱指数 17 | :rtype: pandas.DataFrame 18 | """ 19 | url = "https://api.chartblocks.com/v1/chart/data/6083e35c3ba0f6256a0afae3?t=733e658870e7bec" 20 | r = requests.get(url) 21 | data_json = r.json() 22 | data_text = data_json["data"]["series"]["ds-0"]["raw"] 23 | temp_df = pd.DataFrame(data_text) 24 | temp_df.columns = ["wci", "date"] 25 | temp_df = temp_df.applymap( 26 | lambda x: x.replace(",", "").replace("$", "") if type(x) == str else x 27 | ) 28 | temp_df = temp_df.astype({"wci": float}) 29 | temp_df["date"] = pd.to_datetime(temp_df["date"]) 30 | temp_df = temp_df[ 31 | [ 32 | "date", 33 | "wci", 34 | ] 35 | ] 36 | return temp_df 37 | 38 | 39 | if __name__ == "__main__": 40 | drewry_wci_index_df = drewry_wci_index() 41 | print(drewry_wci_index_df) 42 | -------------------------------------------------------------------------------- /akshare/fortune/forbes_500.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2021/5/6 17:10 5 | Desc: 福布斯中国-榜单 6 | https://www.forbeschina.com/lists 7 | """ 8 | import pandas as pd 9 | import requests 10 | from bs4 import BeautifulSoup 11 | 12 | 13 | def forbes_rank(indicator: str = "2020福布斯美国富豪榜") -> pd.DataFrame: 14 | """ 15 | 福布斯中国-榜单 16 | https://www.forbeschina.com/lists 17 | https://www.forbeschina.com/lists/1750 18 | :param indicator: choice of {"2020福布斯美国富豪榜", "2020福布斯新加坡富豪榜", "2020福布斯中国名人榜", *} 19 | :type indicator: str 20 | :return: 具体指标的榜单 21 | :rtype: pandas.DataFrame 22 | """ 23 | url = "https://www.forbeschina.com/lists" 24 | r = requests.get(url) 25 | soup = BeautifulSoup(r.text, "lxml") 26 | need_list = [ 27 | item.find_all("a") for item in soup.find_all("div", attrs={"class": "col-sm-4"}) 28 | ] 29 | all_list = [] 30 | for item in need_list: 31 | all_list.extend(item) 32 | name_url_dict = dict( 33 | zip( 34 | [item.text.strip() for item in all_list], 35 | ["https://www.forbeschina.com" + item["href"] for item in all_list], 36 | ) 37 | ) 38 | r = requests.get(name_url_dict[indicator]) 39 | temp_df = pd.read_html(r.text)[0] 40 | return temp_df 41 | 42 | 43 | if __name__ == "__main__": 44 | forbes_rank_df = forbes_rank(indicator="2020福布斯中国400富豪榜") 45 | print(forbes_rank_df) 46 | -------------------------------------------------------------------------------- /akshare/bond/china_repo.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2021/1/20 11:48 5 | Desc: 腾讯-债券-质押式回购-实时行情-成交明细 6 | 下载成交明细-每个交易日 16:00 提供当日数据 7 | http://stockhtm.finance.qq.com/sstock/ggcx/131802.shtml 8 | """ 9 | from io import StringIO 10 | 11 | import pandas as pd 12 | import requests 13 | 14 | 15 | def bond_repo_zh_tick( 16 | code: str = "sz131802", trade_date: str = "20201028" 17 | ) -> pd.DataFrame: 18 | """ 19 | 成交明细-每个交易日16:00提供当日数据 20 | http://stockhtm.finance.qq.com/sstock/ggcx/131802.shtml 21 | :param code: 带市场标识的债券-质押式回购代码 22 | :type code: str 23 | :param trade_date: 需要提取数据的日期 24 | :type trade_date: str 25 | :return: 返回指定交易日债券-质押式回购成交明细的数据 26 | :rtype: pandas.DataFrame 27 | """ 28 | url = "http://stock.gtimg.cn/data/index.php" 29 | params = { 30 | "appn": "detail", 31 | "action": "download", 32 | "c": code, 33 | "d": trade_date, 34 | } 35 | r = requests.get(url, params=params) 36 | r.encoding = "gbk" 37 | temp_df = pd.read_table(StringIO(r.text)) 38 | return temp_df 39 | 40 | 41 | if __name__ == "__main__": 42 | date_list = pd.date_range(start="20210101", end="20210120").tolist() 43 | date_list = [item.strftime("%Y%m%d") for item in date_list] 44 | for item in date_list: 45 | data = bond_repo_zh_tick(code="sz131802", trade_date=f"{item}") 46 | if not data.empty: 47 | print(data) 48 | -------------------------------------------------------------------------------- /docs/_templates/layout.html: -------------------------------------------------------------------------------- 1 | {% extends "!layout.html" %} 2 | 3 | {% block extrahead %} 4 | 5 | {{ super() }} 6 | {% endblock %} 7 | 8 | 9 | {% block footer %} 10 | {{ super() }} 11 | 22 | {% endblock %} -------------------------------------------------------------------------------- /akshare/bank/cons.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2019/11/7 15:23 5 | Desc: 银保监会配置文件 6 | """ 7 | cbirc_headers_without_cookie_2020 = { 8 | "Accept": "*/*", 9 | "Accept-Encoding": "gzip, deflate", 10 | "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8", 11 | "Cache-Control": "no-cache", 12 | "Connection": "keep-alive", 13 | "Host": "www.cbirc.gov.cn", 14 | "Pragma": "no-cache", 15 | "Referer": "http://www.cbirc.gov.cn/cn/view/pages/ItemList.html?itemPId=923&itemId=4115&itemUrl=ItemListRightList.html&itemName=%E9%93%B6%E4%BF%9D%E7%9B%91%E5%88%86%E5%B1%80%E6%9C%AC%E7%BA%A7&itemsubPId=931&itemsubPName=%E8%A1%8C%E6%94%BF%E5%A4%84%E7%BD%9A", 16 | "X-Requested-With": "XMLHttpRequest", 17 | "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36" 18 | } 19 | 20 | cbirc_headers_without_cookie_2019 = { 21 | "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3", 22 | "Accept-Encoding": "gzip, deflate", 23 | "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8", 24 | "Cache-Control": "no-cache", 25 | "Connection": "keep-alive", 26 | "Host": "www.cbirc.gov.cn", 27 | "Pragma": "no-cache", 28 | "Referer": "http://www.cbirc.gov.cn/cn/list/9103/910305/ybjjcf/1.html", 29 | "Upgrade-Insecure-Requests": "1", 30 | "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36" 31 | } 32 | -------------------------------------------------------------------------------- /akshare/cost/cost_living.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/12/18 12:32 5 | Desc: 获取世界各大城市生活成本数据 6 | https://expatistan.com/cost-of-living/index 7 | """ 8 | import pandas as pd 9 | import requests 10 | from bs4 import BeautifulSoup 11 | 12 | from akshare.cost.cons import url, name_url_map 13 | 14 | 15 | def _get_region(): 16 | """ 17 | 获取主要板块, 一般不调用 18 | :return: dict 19 | """ 20 | res = requests.get(url) 21 | soup = BeautifulSoup(res.text, "lxml") 22 | half_url_list = [ 23 | item["href"] 24 | for item in soup.find("ul", attrs={"class": "regions"}).find_all("a") 25 | ] 26 | name_list = [ 27 | item["href"].split("/")[-1] 28 | for item in soup.find("ul", attrs={"class": "regions"}).find_all("a") 29 | ] 30 | name_url_dict = dict(zip(name_list, half_url_list)) 31 | name_url_dict["world"] = "/cost-of-living/index" 32 | return name_url_dict 33 | 34 | 35 | def cost_living(region: str = "world") -> pd.DataFrame: 36 | """ 37 | 国家或地区生活成本数据 38 | https://expatistan.com/cost-of-living/index 39 | :param region: str ["europe", "north-america", "latin-america", "asia", "middle-east", "africa", "oceania", "world"] 40 | :return: pandas.DataFrame 41 | """ 42 | object_url = f"https://www.expatistan.com{name_url_map[region]}" 43 | res = requests.get(object_url) 44 | temp_df = pd.read_html(res.text)[0] 45 | temp_df.columns = ["rank", "city", "index"] 46 | return temp_df 47 | 48 | 49 | if __name__ == "__main__": 50 | cost_living_df = cost_living() 51 | print(cost_living_df) 52 | -------------------------------------------------------------------------------- /akshare/rate/repo_rate.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/10/29 13:04 5 | Desc: 中国外汇交易中心暨全国银行间同业拆借中心-回购定盘利率-历史数据 6 | """ 7 | import pandas as pd 8 | import requests 9 | 10 | 11 | def repo_rate_hist(start_date: str = "20200930", end_date: str = "20201029") -> pd.DataFrame: 12 | """ 13 | 中国外汇交易中心暨全国银行间同业拆借中心-回购定盘利率-历史数据 14 | http://www.chinamoney.com.cn/chinese/bkfrr/ 15 | :param start_date: 开始时间, 开始时间与结束时间需要在一个月内 16 | :type start_date: str 17 | :param end_date: 结束时间, 开始时间与结束时间需要在一个月内 18 | :type end_date: str 19 | :return: 回购定盘利率-历史数据 20 | :rtype: pandas.DataFrame 21 | """ 22 | start_date = "-".join([start_date[:4], start_date[4:6], start_date[6:]]) 23 | end_date = "-".join([end_date[:4], end_date[4:6], end_date[6:]]) 24 | url = "http://www.chinamoney.com.cn/ags/ms/cm-u-bk-currency/FrrHis" 25 | params = { 26 | "lang": "CN", 27 | "startDate": start_date, 28 | "endDate": end_date, 29 | "pageSize": "5000", 30 | } 31 | r = requests.post(url, params=params) 32 | data_json = r.json() 33 | temp_df = pd.DataFrame(data_json["records"]) 34 | temp_df = pd.DataFrame([item for item in temp_df["frValueMap"].to_list()]) 35 | temp_df = temp_df[[ 36 | "date", 37 | "FR001", 38 | "FR007", 39 | "FR014", 40 | "FDR001", 41 | "FDR007", 42 | "FDR014", 43 | ]] 44 | return temp_df 45 | 46 | 47 | if __name__ == '__main__': 48 | repo_rate_hist_df = repo_rate_hist(start_date="20200830", end_date="20200929") 49 | print(repo_rate_hist_df) 50 | -------------------------------------------------------------------------------- /docs/README.rst: -------------------------------------------------------------------------------- 1 | :orphan: 2 | 3 | ========================================= 4 | AkShare documentation quick start guide 5 | ========================================= 6 | 7 | This file provides a quick guide on how to compile the AkShare documentation. 8 | 9 | 10 | Setup the environment 11 | --------------------- 12 | 13 | To compile the documentation you need Sphinx Python library. To install it 14 | and all its dependencies run the following command from this dir 15 | 16 | :: 17 | 18 | pip install -r requirements.txt 19 | 20 | 21 | Compile the documentation 22 | ------------------------- 23 | 24 | To compile the documentation (to classic HTML output) run the following command 25 | from this dir:: 26 | 27 | make html 28 | 29 | Documentation will be generated (in HTML format) inside the ``build/html`` dir. 30 | 31 | 32 | View the documentation 33 | ---------------------- 34 | 35 | To view the documentation run the following command:: 36 | 37 | make htmlview 38 | 39 | This command will fire up your default browser and open the main page of your 40 | (previously generated) HTML documentation. 41 | 42 | 43 | Start over 44 | ---------- 45 | 46 | To cleanup all generated documentation files and start from scratch run:: 47 | 48 | make clean 49 | 50 | Keep in mind that this command won't touch any documentation source files. 51 | 52 | 53 | Recreating documentation on the fly 54 | ----------------------------------- 55 | 56 | There is a way to recreate the doc automatically when you make changes, you 57 | need to install watchdog (``pip install watchdog``) and then use:: 58 | 59 | make watch 60 | 61 | -------------------------------------------------------------------------------- /akshare/futures/futures_comex.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/10/10 13:46 5 | Desc: 东方财富网-数据中心-COMEX库存数据 6 | http://data.eastmoney.com/pmetal/comex/by.html 7 | """ 8 | import demjson 9 | import pandas as pd 10 | import requests 11 | 12 | 13 | def futures_comex_inventory(symbol: str = "黄金") -> pd.DataFrame: 14 | """ 15 | 东方财富网-数据中心-COMEX库存数据 16 | http://data.eastmoney.com/pmetal/comex/by.html 17 | :param symbol: choice of {"黄金", "白银"} 18 | :type symbol: str 19 | :return: COMEX库存数据 20 | :rtype: pandas.DataFrame 21 | """ 22 | symbol_map = { 23 | "黄金": "(ID='EMI00069026')", 24 | "白银": "(ID='EMI00069027')", 25 | } 26 | url = "http://dcfm.eastmoney.com/em_mutisvcexpandinterface/api/js/get" 27 | params = { 28 | "type": "HJBY_KC", 29 | "token": "70f12f2f4f091e459a279469fe49eca5", 30 | "p": "1", 31 | "ps": "5000", 32 | "st": "DATADATE", 33 | "sr": "-1", 34 | "filter": symbol_map[symbol], 35 | "js": "var hVtWMLwm={pages:(tp),data:(x)}", 36 | "rt": "53367096", 37 | } 38 | r = requests.get(url, params=params) 39 | data_text = r.text 40 | data_json = demjson.decode(data_text[data_text.find("{"):]) 41 | temp_df = pd.DataFrame(data_json["data"]) 42 | del temp_df["ID"] 43 | temp_df["DATADATE"] = pd.to_datetime(temp_df["DATADATE"]) 44 | temp_df.columns = ["date", "value1", "value2"] 45 | return temp_df 46 | 47 | 48 | if __name__ == '__main__': 49 | futures_comex_inventory_df = futures_comex_inventory(symbol="黄金") 50 | print(futures_comex_inventory_df) 51 | -------------------------------------------------------------------------------- /akshare/stock_feature/stock_em_tfp.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/3/25 0:05 5 | Desc: 东方财富网-数据中心-特色数据-停复牌信息 6 | http://data.eastmoney.com/tfpxx/ 7 | """ 8 | import demjson 9 | import pandas as pd 10 | import requests 11 | 12 | 13 | def stock_em_tfp(trade_date: str = "2020-03-19") -> pd.DataFrame: 14 | """ 15 | 东方财富网-数据中心-特色数据-停复牌信息 16 | http://data.eastmoney.com/tfpxx/ 17 | :param trade_date: specific date as "2020-03-19" 18 | :type trade_date: str 19 | :return: 停复牌信息表 20 | :rtype: pandas.DataFrame 21 | """ 22 | url = "http://datainterface.eastmoney.com/EM_DataCenter/JS.aspx" 23 | params = { 24 | "type": "FD", 25 | "sty": "SRB", 26 | "st": "0", 27 | "sr": "-1", 28 | "p": "1", 29 | "ps": "50", 30 | "js": "var BSkKafhD={pages:(pc),data:[(x)]}", 31 | "mkt": "1", 32 | "fd": trade_date, 33 | "rt": "52835529", 34 | } 35 | r = requests.get(url, params=params) 36 | data_text = r.text 37 | data_json = demjson.decode(data_text[data_text.find("{") :]) 38 | temp_df = pd.DataFrame(data_json["data"]).iloc[:, 0].str.split(",", expand=True) 39 | temp_df.columns = [ 40 | "代码", 41 | "名称", 42 | "停牌时间", 43 | "停牌截止时间", 44 | "停牌期限", 45 | "停牌原因", 46 | "所属市场", 47 | "-", 48 | "预计复牌时间", 49 | ] 50 | data_df = temp_df[["代码", "名称", "停牌时间", "停牌截止时间", "停牌期限", "停牌原因", "所属市场", "预计复牌时间"]] 51 | return data_df 52 | 53 | 54 | if __name__ == "__main__": 55 | stock_em_tfp_df = stock_em_tfp(trade_date="2020-06-24") 56 | print(stock_em_tfp_df) 57 | -------------------------------------------------------------------------------- /akshare/fund/fund_em_init.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2021/4/29 14:30 5 | Desc: 基金数据-新发基金-新成立基金 6 | http://fund.eastmoney.com/data/xinfound.html 7 | """ 8 | import requests 9 | import demjson 10 | import pandas as pd 11 | 12 | 13 | def fund_em_new_found(): 14 | """ 15 | 基金数据-新发基金-新成立基金 16 | http://fund.eastmoney.com/data/xinfound.html 17 | :return: 新成立基金 18 | :rtype: pandas.DataFrame 19 | """ 20 | url = 'http://fund.eastmoney.com/data/FundNewIssue.aspx' 21 | params = { 22 | 't': 'xcln', 23 | 'sort': 'jzrgq,desc', 24 | 'y': '', 25 | 'page': '1,5000', 26 | 'isbuy': '1', 27 | 'v': '0.4069919776543214', 28 | } 29 | r = requests.get(url, params=params) 30 | data_text = r.text 31 | data_json = demjson.decode(data_text.strip("var newfunddata=")) 32 | temp_df = pd.DataFrame(data_json['datas']) 33 | temp_df.columns = [ 34 | "基金代码", 35 | "基金简称", 36 | "发行公司", 37 | "_", 38 | "基金类型", 39 | "募集份额", 40 | "成立日期", 41 | "成立来涨幅", 42 | "基金经理", 43 | "申购状态", 44 | "集中认购期", 45 | "_", 46 | "_", 47 | "_", 48 | "_", 49 | "_", 50 | "_", 51 | "_", 52 | "优惠费率", 53 | ] 54 | temp_df = temp_df[[ 55 | "基金代码", 56 | "基金简称", 57 | "发行公司", 58 | "基金类型", 59 | "集中认购期", 60 | "募集份额", 61 | "成立日期", 62 | "成立来涨幅", 63 | "基金经理", 64 | "申购状态", 65 | "优惠费率", 66 | ]] 67 | return temp_df 68 | 69 | 70 | if __name__ == '__main__': 71 | fund_em_new_found_df = fund_em_new_found() 72 | print(fund_em_new_found_df) 73 | -------------------------------------------------------------------------------- /docs/data/hf/hf.md: -------------------------------------------------------------------------------- 1 | ## [AKShare](https://github.com/jindaxiang/akshare) 高频数据 2 | 3 | ### 标普 500 指数 4 | 5 | 接口: hf_sp_500 6 | 7 | 目标地址: https://github.com/FutureSharks/financial-data 8 | 9 | 描述: 获取标普500指数的分钟数据, 由于数据量比较大, 需要等待, 由于服务器在国外, 建议使用代理访问 10 | 11 | 输入参数 12 | 13 | | 名称 | 类型 | 必选 | 描述 | 14 | | -------- | ---- | ---- | --- | 15 | | year | str | Y | year="2017"; 只能获取 **2012-2018** 年的数据 | 16 | 17 | 输出参数 18 | 19 | | 名称 | 类型 | 默认显示 | 描述 | 20 | | --------------- | ----- | -------- | ---------------- | 21 | | date | datetime | Y | 日期时间 | 22 | | open | float | Y | 开盘价 | 23 | | high | float | Y | 最高价 | 24 | | low | float | Y | 最低价 | 25 | | close | float | Y | 收盘价 | 26 | 27 | 接口示例 28 | 29 | ```python 30 | import akshare as ak 31 | hf_sp_500_df = ak.hf_sp_500(year="2017") 32 | print(hf_sp_500_df) 33 | ``` 34 | 35 | 数据示例 36 | 37 | ``` 38 | open high low close 39 | date 40 | 2017-01-02 18:00:00 2241.00 2244.50 2241.00 2243.50 41 | 2017-01-02 18:01:00 2243.75 2243.75 2243.00 2243.00 42 | 2017-01-02 18:02:00 2243.25 2243.25 2243.00 2243.25 43 | 2017-01-02 18:03:00 2243.00 2243.00 2243.00 2243.00 44 | 2017-01-02 18:04:00 2243.25 2243.75 2243.25 2243.75 45 | ... ... ... ... 46 | 2017-12-29 16:53:00 2669.50 2669.75 2669.25 2669.25 47 | 2017-12-29 16:54:00 2669.00 2669.25 2669.00 2669.00 48 | 2017-12-29 16:55:00 2668.75 2668.75 2668.00 2668.25 49 | 2017-12-29 16:57:00 2667.75 2668.50 2667.75 2668.00 50 | 2017-12-29 16:58:00 2668.25 2668.50 2667.75 2668.50 51 | ``` 52 | -------------------------------------------------------------------------------- /akshare/stock_feature/stock_legu_market.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2021/5/11 15:25 5 | Desc: 赚钱效应分析 6 | https://www.legulegu.com/stockdata/market-activity 7 | """ 8 | import requests 9 | import pandas as pd 10 | from bs4 import BeautifulSoup 11 | 12 | 13 | def stock_legu_market_activity(): 14 | """ 15 | 赚钱效应分析 16 | https://www.legulegu.com/stockdata/market-activity 17 | :return: 赚钱效应分析 18 | :rtype: pandas.DataFrame 19 | """ 20 | url = "https://www.legulegu.com/stockdata/market-activity" 21 | r = requests.get(url) 22 | temp_df = pd.read_html(r.text)[0] 23 | temp_df_one = temp_df.iloc[:, :2] 24 | temp_df_one.columns = ["item", "value"] 25 | temp_df_two = temp_df.iloc[:, 2:4] 26 | temp_df_two.columns = ["item", "value"] 27 | temp_df_three = temp_df.iloc[:, 4:6] 28 | temp_df_three.columns = ["item", "value"] 29 | temp_df = pd.concat([temp_df_one, temp_df_two, temp_df_three]) 30 | temp_df.dropna(how="all", axis=0, inplace=True) 31 | 32 | soup = BeautifulSoup(r.text, "lxml") 33 | item_str = soup.find("div", attrs={"class": "current-index"}).text 34 | inner_temp_df = pd.DataFrame(item_str.split(":")).T 35 | inner_temp_df.columns = ["item", "value"] 36 | temp_df = temp_df.append(inner_temp_df) 37 | 38 | item_str = soup.find("div", attrs={"class": "current-data"}).text.strip() 39 | inner_temp_df = pd.DataFrame(["统计日期", item_str]).T 40 | inner_temp_df.columns = ["item", "value"] 41 | temp_df = temp_df.append(inner_temp_df) 42 | temp_df.reset_index(inplace=True, drop=True) 43 | 44 | return temp_df 45 | 46 | 47 | if __name__ == "__main__": 48 | stock_legu_market_activity_df = stock_legu_market_activity() 49 | print(stock_legu_market_activity_df) 50 | -------------------------------------------------------------------------------- /akshare/index/index_yw.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2021/5/1 19:51 5 | Desc: 义乌小商品指数 6 | http://www.ywindex.com/Home/Product/index/ 7 | """ 8 | import pandas as pd 9 | import requests 10 | from bs4 import BeautifulSoup 11 | 12 | 13 | def index_yw(symbol: str = "月景气指数") -> pd.DataFrame: 14 | """ 15 | 义乌小商品指数 16 | http://www.ywindex.com/Home/Product/index/ 17 | :param symbol: choice of {"周价格指数", "月价格指数", "月景气指数"} 18 | :type symbol: str 19 | :return: 指数结果 20 | :rtype: pandas.DataFrame 21 | """ 22 | name_num_dict = { 23 | "周价格指数": 1, 24 | "月价格指数": 3, 25 | "月景气指数": 5, 26 | } 27 | url = "http://www.ywindex.com/Home/Product/index/" 28 | res = requests.get(url) 29 | soup = BeautifulSoup(res.text, "lxml") 30 | table_name = ( 31 | soup.find_all(attrs={"class": "tablex"})[name_num_dict[symbol]] 32 | .get_text() 33 | .split("\n\n\n\n\n")[2] 34 | .split("\n") 35 | ) 36 | table_content = ( 37 | soup.find_all(attrs={"class": "tablex"})[name_num_dict[symbol]] 38 | .get_text() 39 | .split("\n\n\n\n\n")[3] 40 | .split("\n\n") 41 | ) 42 | if symbol == "月景气指数": 43 | table_df = pd.DataFrame([item.split("\n") for item in table_content]).iloc[ 44 | :, :5 45 | ] 46 | table_df.columns = table_name 47 | return table_df 48 | table_df = pd.DataFrame([item.split("\n") for item in table_content]).iloc[:, :6] 49 | table_df.columns = table_name 50 | return table_df 51 | 52 | 53 | if __name__ == "__main__": 54 | index_yw_df = index_yw(symbol="周价格指数") 55 | print(index_yw_df) 56 | 57 | index_yw_df = index_yw(symbol="月价格指数") 58 | print(index_yw_df) 59 | 60 | index_yw_df = index_yw(symbol="月景气指数") 61 | print(index_yw_df) 62 | -------------------------------------------------------------------------------- /akshare/fortune/xincaifu_500.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/11/7 12:12 5 | Desc: 新财富 500 人富豪榜 6 | http://www.xcf.cn/zhuanti/ztzz/hdzt1/500frb/index.html 7 | """ 8 | import json 9 | 10 | import pandas as pd 11 | import requests 12 | 13 | 14 | def xincaifu_rank(year: str = "2020") -> pd.DataFrame: 15 | """ 16 | 新财富 500 人富豪榜 17 | http://www.xcf.cn/zhuanti/ztzz/hdzt1/500frb/index.html 18 | :param year: 具体排名年份, 数据从 2003-至今 19 | :type year: str 20 | :return: 排行榜 21 | :rtype: pandas.DataFrame 22 | """ 23 | url = "http://service.ikuyu.cn/XinCaiFu2/pcremoting/bdListAction.do" 24 | params = { 25 | "method": "getPage", 26 | "callback": "jsonpCallback", 27 | "sortBy": "", 28 | "order": "", 29 | "type": "4", 30 | "keyword": "", 31 | "pageSize": "1000", 32 | "year": year, 33 | "pageNo": "1", 34 | "from": "jsonp", 35 | "_": "1604722171732", 36 | } 37 | r = requests.get(url, params=params) 38 | data_text = r.text 39 | data_json = json.loads(data_text[data_text.find("{") : -1]) 40 | temp_df = pd.DataFrame(data_json["data"]["rows"]) 41 | temp_df.columns = [ 42 | "_", 43 | "财富", 44 | "性别", 45 | "排名", 46 | "年龄", 47 | "主要公司", 48 | "姓名", 49 | "公司总部", 50 | "年份", 51 | "_", 52 | "相关行业", 53 | ] 54 | temp_df = temp_df[ 55 | [ 56 | "排名", 57 | "财富", 58 | "姓名", 59 | "主要公司", 60 | "相关行业", 61 | "公司总部", 62 | "性别", 63 | "年龄", 64 | "年份", 65 | ] 66 | ] 67 | return temp_df 68 | 69 | 70 | if __name__ == "__main__": 71 | xincaifu_rank_df = xincaifu_rank(year="2020") 72 | print(xincaifu_rank_df) 73 | -------------------------------------------------------------------------------- /akshare/article/epu_index.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2019/11/30 13:14 5 | Desc: 网站的经济政策不确定性指数 6 | http://www.policyuncertainty.com/index.html 7 | """ 8 | import pandas as pd 9 | 10 | 11 | def article_epu_index(index: str = "China") -> pd.DataFrame: 12 | """ 13 | 网站的经济政策不确定性指数 14 | :param index: 指定的国家名称, e.g. “China” 15 | :type index: str 16 | :return: 指定 index 的数据 17 | :rtype: pandas.DataFrame 18 | """ 19 | if index == "China New": 20 | index = "China" 21 | if index == "USA": 22 | index = "US" 23 | if index == "Hong Kong": 24 | index = "HK" 25 | epu_df = pd.read_excel( 26 | f"http://www.policyuncertainty.com/media/{index}_EPU_Data_Annotated.xlsx", 27 | engine="openpyxl" 28 | ) 29 | return epu_df 30 | if index in ["Germany", "France", "Italy"]: # 欧洲 31 | index = "Europe" 32 | if index == "South Korea": 33 | index = "Korea" 34 | if index == "Spain New": 35 | index = "Spain" 36 | if index in ["Ireland", "Chile", "Colombia", "Netherlands", "Singapore", "Sweden"]: 37 | epu_df = pd.read_excel( 38 | f"http://www.policyuncertainty.com/media/{index}_Policy_Uncertainty_Data.xlsx", 39 | engine="openpyxl" 40 | ) 41 | return epu_df 42 | if index == "Greece": 43 | epu_df = pd.read_excel( 44 | f"http://www.policyuncertainty.com/media/FKT_{index}_Policy_Uncertainty_Data.xlsx", 45 | engine="openpyxl" 46 | ) 47 | return epu_df 48 | url = f"http://www.policyuncertainty.com/media/{index}_Policy_Uncertainty_Data.csv" 49 | epu_df = pd.read_csv(url) 50 | return epu_df 51 | 52 | 53 | if __name__ == "__main__": 54 | article_epu_index_df = article_epu_index(index="Greece") 55 | print(article_epu_index_df) 56 | -------------------------------------------------------------------------------- /akshare/stock/stock_zh_a_new.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/10/10 16:36 5 | Desc: 行情中心-沪深股市-次新股 6 | http://vip.stock.finance.sina.com.cn/mkt/#new_stock 7 | """ 8 | import math 9 | 10 | import pandas as pd 11 | import requests 12 | 13 | 14 | def stock_zh_a_new() -> pd.DataFrame: 15 | """ 16 | 行情中心-沪深股市-次新股 17 | http://vip.stock.finance.sina.com.cn/mkt/#new_stock 18 | :return: 次新股行情数据 19 | :rtype: pandas.DataFrame 20 | """ 21 | url = "http://vip.stock.finance.sina.com.cn/quotes_service/api/json_v2.php/Market_Center.getHQNodeStockCount" 22 | params = {"node": "new_stock"} 23 | r = requests.get(url, params=params) 24 | total_page = math.ceil(int(r.json()) / 80) 25 | url = "http://vip.stock.finance.sina.com.cn/quotes_service/api/json_v2.php/Market_Center.getHQNodeData" 26 | big_df = pd.DataFrame() 27 | for page in range(1, total_page + 1): 28 | params = { 29 | "page": str(page), 30 | "num": "80", 31 | "sort": "symbol", 32 | "asc": "1", 33 | "node": "new_stock", 34 | "symbol": "", 35 | "_s_r_a": "page", 36 | } 37 | r = requests.get(url, params=params) 38 | r.encoding = "gb2312" 39 | data_json = r.json() 40 | temp_df = pd.DataFrame(data_json) 41 | big_df = big_df.append(temp_df, ignore_index=True) 42 | big_df = big_df[ 43 | [ 44 | "symbol", 45 | "code", 46 | "name", 47 | "open", 48 | "high", 49 | "low", 50 | "volume", 51 | "amount", 52 | "mktcap", 53 | "turnoverratio", 54 | ] 55 | ] 56 | return big_df 57 | 58 | 59 | if __name__ == "__main__": 60 | stock_zh_a_new_df = stock_zh_a_new() 61 | print(stock_zh_a_new_df) 62 | -------------------------------------------------------------------------------- /akshare/stock/stock_js_us.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/6/26 13:30 5 | Desc: 美股目标价 or 港股目标价 6 | https://www.ushknews.com/report.html 7 | """ 8 | import requests 9 | import pandas as pd 10 | 11 | 12 | def stock_js_price(category: str = "us") -> pd.DataFrame: 13 | """ 14 | 美股目标价 or 港股目标价 15 | :param category: choice of ["us", "hk"] 16 | :type category: str 17 | :return: 美股目标价 or 港股目标价 18 | :rtype: pandas.DataFrame 19 | """ 20 | url = "https://calendar-api.ushknews.com/getWebTargetPriceList" 21 | params = { 22 | "limit": "10000", 23 | "category": category 24 | } 25 | headers = { 26 | "accept": "application/json, text/plain, */*", 27 | "accept-encoding": "gzip, deflate, br", 28 | "accept-language": "zh-CN,zh;q=0.9,en;q=0.8", 29 | "cache-control": "no-cache", 30 | "cookie": "UM_distinctid=1721157a7ea9b-07ab7d5af65271-d373666-1fa400-1721157a7ebb94", 31 | "origin": "https://www.ushknews.com", 32 | "pragma": "no-cache", 33 | "referer": "https://www.ushknews.com/report.html", 34 | "sec-fetch-dest": "empty", 35 | "sec-fetch-mode": "cors", 36 | "sec-fetch-site": "same-site", 37 | "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36", 38 | "x-app-id": "BNsiR9uq7yfW0LVz", 39 | "x-version": "1.0.0" 40 | } 41 | r = requests.get(url, params=params, headers=headers) 42 | json_data = r.json() 43 | temp_df = pd.DataFrame(json_data["data"]["list"]) 44 | return temp_df 45 | 46 | 47 | if __name__ == '__main__': 48 | stock_js_price_us_df = stock_js_price(category="us") 49 | print(stock_js_price_us_df) 50 | 51 | stock_js_price_hk_df = stock_js_price(category="hk") 52 | print(stock_js_price_hk_df) 53 | -------------------------------------------------------------------------------- /akshare/stock_fundamental/stock_ipo_declare.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2021/4/6 16:02 5 | Desc: 东方财富网-数据中心-新股申购-首发申报信息-首发申报企业信息 6 | https://data.eastmoney.com/xg/xg/sbqy.html 7 | """ 8 | import pandas as pd 9 | import requests 10 | import demjson 11 | 12 | 13 | def stock_ipo_declare(): 14 | """ 15 | 东方财富网-数据中心-新股申购-首发申报信息-首发申报企业信息 16 | https://data.eastmoney.com/xg/xg/sbqy.html 17 | :return: 首发申报企业信息 18 | :rtype: pandas.DataFrame 19 | """ 20 | url = "https://datainterface.eastmoney.com/EM_DataCenter/JS.aspx" 21 | params = { 22 | "st": "1", 23 | "sr": "-1", 24 | "ps": "500", 25 | "p": "1", 26 | "type": "NS", 27 | "sty": "NSFR", 28 | "js": "({data:[(x)],pages:(pc)})", 29 | "mkt": "1", 30 | "fd": "2021-04-02", 31 | } 32 | r = requests.get(url, params=params) 33 | data_text = r.text 34 | data_json = demjson.decode(data_text[1:-1]) 35 | temp_df = pd.DataFrame([item.split(",") for item in data_json["data"]]) 36 | temp_df.reset_index(inplace=True) 37 | temp_df["index"] = range(1, len(temp_df) + 1) 38 | temp_df.columns = [ 39 | "序号", 40 | "会计师事务所", 41 | "_", 42 | "保荐机构", 43 | "_", 44 | "律师事务所", 45 | "_", 46 | "_", 47 | "拟上市地", 48 | "_", 49 | "_", 50 | "备注", 51 | "申报企业", 52 | "_", 53 | "_", 54 | "_", 55 | "_", 56 | ] 57 | temp_df = temp_df[ 58 | [ 59 | "序号", 60 | "申报企业", 61 | "拟上市地", 62 | "保荐机构", 63 | "会计师事务所", 64 | "律师事务所", 65 | "备注", 66 | ] 67 | ] 68 | return temp_df 69 | 70 | 71 | if __name__ == "__main__": 72 | stock_ipo_declare_df = stock_ipo_declare() 73 | print(stock_ipo_declare_df) 74 | -------------------------------------------------------------------------------- /akshare/stock_feature/stock_a_high_low.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2021/5/6 18:32 5 | Desc: 创新高、新低的股票数量 6 | https://www.legulegu.com/stockdata/high-low-statistics 7 | """ 8 | import pandas as pd 9 | import requests 10 | 11 | 12 | def stock_a_high_low_statistics(market: str = "all") -> pd.DataFrame: 13 | """ 14 | 创新高、新低的股票数量 15 | https://www.legulegu.com/stockdata/high-low-statistics 16 | :param market: choice of {"all", "sz50", "hs300", "zz500"} 17 | :type market: str 18 | :return: 创新高、新低的股票数量 19 | :rtype: pandas.DataFrame 20 | """ 21 | if market == "all": 22 | url = f"https://www.legulegu.com/stockdata/member-ship/get-high-low-statistics/{market}" 23 | elif market == "sz50": 24 | url = f"https://www.legulegu.com/stockdata/member-ship/get-high-low-statistics/{market}" 25 | elif market == "hs300": 26 | url = f"https://www.legulegu.com/stockdata/member-ship/get-high-low-statistics/{market}" 27 | elif market == "zz500": 28 | url = f"https://www.legulegu.com/stockdata/member-ship/get-high-low-statistics/{market}" 29 | r = requests.get(url) 30 | data_json = r.json() 31 | temp_df = pd.DataFrame(data_json) 32 | temp_df["date"] = pd.to_datetime(temp_df["date"], unit="ms") 33 | del temp_df["id"] 34 | del temp_df["indexCode"] 35 | return temp_df 36 | 37 | 38 | if __name__ == '__main__': 39 | stock_a_high_low_statistics_df = stock_a_high_low_statistics(market="all") 40 | print(stock_a_high_low_statistics_df) 41 | 42 | stock_a_high_low_statistics_df = stock_a_high_low_statistics(market="sz50") 43 | print(stock_a_high_low_statistics_df) 44 | 45 | stock_a_high_low_statistics_df = stock_a_high_low_statistics(market="hs300") 46 | print(stock_a_high_low_statistics_df) 47 | 48 | stock_a_high_low_statistics_df = stock_a_high_low_statistics(market="zz500") 49 | print(stock_a_high_low_statistics_df) 50 | -------------------------------------------------------------------------------- /akshare/bond/cons.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2019/10/20 10:21 5 | Desc: 债券配置文件 6 | """ 7 | # bond-cov-sina 8 | zh_sina_bond_hs_cov_url = "http://vip.stock.finance.sina.com.cn/quotes_service/api/json_v2.php/Market_Center.getHQNodeDataSimple" 9 | zh_sina_bond_hs_cov_count_url = "http://vip.stock.finance.sina.com.cn/quotes_service/api/json_v2.php/Market_Center.getHQNodeStockCountSimple" 10 | zh_sina_bond_hs_cov_hist_url = "https://finance.sina.com.cn/realstock/company/{}/hisdata/klc_kl.js?d={}" 11 | zh_sina_bond_hs_cov_payload = { 12 | "page": "1", 13 | "num": "80", 14 | "sort": "symbol", 15 | "asc": "1", 16 | "node": "hskzz_z", 17 | "_s_r_a": "page" 18 | } 19 | 20 | # bond-sina 21 | zh_sina_bond_hs_url = "http://vip.stock.finance.sina.com.cn/quotes_service/api/json_v2.php/Market_Center.getHQNodeData" 22 | zh_sina_bond_hs_count_url = "http://vip.stock.finance.sina.com.cn/quotes_service/api/json_v2.php/Market_Center.getHQNodeStockCountSimple" 23 | zh_sina_bond_hs_hist_url = "https://finance.sina.com.cn/realstock/company/{}/hisdata/klc_kl.js?d={}" 24 | zh_sina_bond_hs_payload = { 25 | "page": "1", 26 | "num": "80", 27 | "sort": "symbol", 28 | "asc": "1", 29 | "node": "hs_z", 30 | "_s_r_a": "page" 31 | } 32 | 33 | # headers 34 | SHORT_HEADERS = { 35 | 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.91 Safari/537.36' 36 | } 37 | 38 | # quote 39 | MARKET_QUOTE_URL = "http://www.chinamoney.com.cn/ags/ms/cm-u-md-bond/CbMktMakQuot?flag=1&lang=cn&abdAssetEncdShrtDesc=&emaEntyEncdShrtDesc=" 40 | MARKET_QUOTE_PAYLOAD = { 41 | "flag": "1", 42 | "lang": "cn", 43 | "abdAssetEncdShrtDesc": "", 44 | "emaEntyEncdShrtDesc": "", 45 | } 46 | 47 | # trade 48 | MARKET_TRADE_URL = "http://www.chinamoney.com.cn/ags/ms/cm-u-md-bond/CbtPri?lang=cn&flag=1&bondName=" 49 | MARKET_TRADE_PAYLOAD = { 50 | "lang": "cn", 51 | "flag": "1", 52 | "bondName": "" 53 | } 54 | -------------------------------------------------------------------------------- /akshare/futures_derivative/jyfm_login_func.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2019/12/9 14:23 5 | Desc: 交易法门-登录函数 6 | """ 7 | from io import BytesIO 8 | 9 | from PIL import Image 10 | import requests 11 | from py_mini_racer import py_mini_racer 12 | 13 | from akshare.futures_derivative import jymf_js 14 | 15 | from akshare.futures_derivative.cons import ( 16 | jyfm_init_headers, 17 | jyfm_login_url, 18 | ) 19 | 20 | 21 | def jyfm_login(account="", password=""): 22 | """ 23 | 交易法门网站登录函数 24 | :param account: user account 25 | :type account: str 26 | :param password: user password 27 | :type password: str 28 | :return: headers with cookies 29 | :rtype: dict 30 | """ 31 | try: 32 | pic_url = f"https://www.jiaoyifamen.com/captcha" 33 | res = requests.get(pic_url) 34 | f = Image.open(BytesIO(res.content)) 35 | f.show() 36 | code = input() 37 | c_func = py_mini_racer.MiniRacer() 38 | c_func.eval(jymf_js.c.replace(r"\n", "")) 39 | en_psw = c_func.call("e", password) 40 | payload = {"nameOrEmail": account, "userPassword": en_psw, "captcha": code} 41 | except: 42 | c_func = py_mini_racer.MiniRacer() 43 | c_func.eval(jymf_js.c.replace(r"\n", "")) 44 | en_psw = c_func.call("e", password) 45 | payload = {"nameOrEmail": account, "userPassword": en_psw} 46 | res = requests.post(jyfm_login_url, json=payload, headers=jyfm_init_headers) 47 | copy_jyfm_init_headers = jyfm_init_headers.copy() 48 | copy_jyfm_init_headers["cookie"] = ( 49 | list(dict(res.cookies).keys())[0] 50 | + "=" 51 | + list(dict(res.cookies).values())[0] 52 | + "; " 53 | + list(dict(res.cookies).keys())[1] 54 | + "=" 55 | + list(dict(res.cookies).values())[1] 56 | ) 57 | return copy_jyfm_init_headers 58 | 59 | 60 | if __name__ == "__main__": 61 | headers = jyfm_login(account="", password="") 62 | print(headers) 63 | -------------------------------------------------------------------------------- /akshare/index/index_eri.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2021/5/9 16:16 5 | Desc: 浙江省排污权交易指数 6 | https://zs.zjpwq.net/ 7 | """ 8 | import requests 9 | import pandas as pd 10 | 11 | 12 | def index_eri() -> pd.DataFrame: 13 | """ 14 | 浙江省排污权交易指数 15 | https://zs.zjpwq.net 16 | :return: 浙江省排污权交易指数 17 | :rtype: pandas.DataFrame 18 | """ 19 | url = "https://zs.zjpwq.net/zhe-jiang-pwq-webapi/indexData" 20 | params = { 21 | "indexId": "1", 22 | "areaCode": "330000", 23 | "cycle": "MONTH", 24 | "structCode": "01", 25 | } 26 | r = requests.get(url, params=params) 27 | data_json = r.json() 28 | temp_df = pd.DataFrame(data_json["data"]) 29 | del temp_df["id"] 30 | del temp_df["indexId"] 31 | del temp_df["stageId"] 32 | del temp_df["structCode"] 33 | del temp_df["areaCode"] 34 | del temp_df["rawValue"] 35 | temp_df.columns = [ 36 | "value", 37 | "date", 38 | ] 39 | temp_df = temp_df[ 40 | [ 41 | "date", 42 | "value", 43 | ] 44 | ] 45 | big_df = temp_df 46 | url = "https://zs.zjpwq.net/zhe-jiang-pwq-webapi/rawValueStatistics" 47 | params = { 48 | "orderBy": "-date", 49 | "pageSize": "1000", 50 | "quotaType": "0", 51 | "index": "TOTAL_QUANTITY", 52 | "areaCode": "330000", 53 | } 54 | r = requests.get(url, params=params) 55 | data_json = r.json() 56 | temp_df = pd.DataFrame(data_json["data"]) 57 | del temp_df["id"] 58 | del temp_df["quotaType"] 59 | del temp_df["index"] 60 | temp_df.columns = [ 61 | "date", 62 | "value", 63 | "update", 64 | ] 65 | big_df = big_df.merge(temp_df, on="date") 66 | big_df.columns = [ 67 | "日期", 68 | "交易指数", 69 | "成交量", 70 | "更新时间", 71 | ] 72 | return big_df 73 | 74 | 75 | if __name__ == "__main__": 76 | index_eri_df = index_eri() 77 | print(index_eri_df) 78 | -------------------------------------------------------------------------------- /akshare/stock_feature/stock_a_below_net_asset_statistics.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2021/5/6 15:32 5 | Desc: 破净股统计历史走势 6 | https://www.legulegu.com/stockdata/below-net-asset-statistics 7 | """ 8 | import pandas as pd 9 | import requests 10 | 11 | 12 | def stock_a_below_net_asset_statistics(symbol: str = "全部A股") -> pd.DataFrame: 13 | """ 14 | 破净股统计历史走势 15 | https://www.legulegu.com/stockdata/below-net-asset-statistics 16 | :param symbol: choice of {"全部A股", "沪深300"} 17 | :type symbol: str 18 | :return: 创新高和新低的股票数量 19 | :rtype: pandas.DataFrame 20 | """ 21 | symbol_map = { 22 | "全部A股": "1", 23 | "沪深300": "000300.XSHG", 24 | } 25 | url = "https://www.legulegu.com/stockdata/below-net-asset-statistics-data" 26 | params = { 27 | "marketId": symbol_map[symbol], 28 | "token": "325843825a2745a2a8f9b9e3355cb864", 29 | } 30 | r = requests.get(url, params=params) 31 | data_json = r.json() 32 | temp_df = pd.DataFrame(data_json) 33 | temp_df["date"] = pd.to_datetime(temp_df["date"], unit="ms").dt.date 34 | del temp_df["id"] 35 | del temp_df["marketId"] 36 | temp_df.columns = ["below_net_asset", "total_company", "date"] 37 | temp_df["below_net_asset_ratio"] = round( 38 | temp_df["below_net_asset"] / temp_df["total_company"], 4 39 | ) 40 | temp_df = temp_df[ 41 | ["date", "below_net_asset", "total_company", "below_net_asset_ratio"] 42 | ] 43 | temp_df.date = temp_df.date.astype("str") 44 | temp_df.iloc[:, 1:] = temp_df.iloc[:, 1:].astype(float) 45 | temp_df.sort_values(["date"], inplace=True) 46 | return temp_df 47 | 48 | 49 | if __name__ == "__main__": 50 | stock_a_below_net_asset_statistics_df = stock_a_below_net_asset_statistics(symbol="全部A股") 51 | print(stock_a_below_net_asset_statistics_df) 52 | 53 | stock_a_below_net_asset_statistics_df = stock_a_below_net_asset_statistics(symbol="沪深300") 54 | print(stock_a_below_net_asset_statistics_df) 55 | -------------------------------------------------------------------------------- /akshare/nlp/nlp_interface.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/11/27 14:02 5 | Desc: ownthink-knowledge graph 6 | https://ownthink.com/ 7 | https://www.ownthink.com/docs/kg/ 8 | """ 9 | import pandas as pd 10 | import requests 11 | 12 | 13 | def nlp_ownthink(word: str = "人工智能", indicator: str = "entity") -> pd.DataFrame: 14 | """ 15 | Knowledge Graph interface for financial research 16 | https://ownthink.com/ 17 | :param word: word in chinese 18 | :type word: str 19 | :param indicator: entity or desc or avp or tag 20 | :type indicator: str 21 | :return: indicator data 22 | :rtype: list or dict or pandas.DataFrame 23 | """ 24 | url = "https://api.ownthink.com/kg/knowledge" 25 | payload = { 26 | "entity": word, 27 | } 28 | r = requests.post(url, data=payload) 29 | if not r.json()["data"]: 30 | print("Can not find the resource, please type into the correct word") 31 | return None 32 | if indicator == "entity": 33 | return r.json()["data"]["entity"] 34 | if indicator == "desc": 35 | return r.json()["data"]["desc"] 36 | if indicator == "avp": 37 | return pd.DataFrame(r.json()["data"]["avp"], columns=["字段", "值"]) 38 | if indicator == "tag": 39 | return r.json()["data"]["tag"] 40 | 41 | 42 | def nlp_answer(question: str = "人工智能") -> str: 43 | """ 44 | 智能问答 45 | https://ownthink.com/robot.html 46 | :param question: word in chinese 47 | :type question: str 48 | :return: indicator data 49 | :rtype: list or dict or pandas.DataFrame 50 | """ 51 | url = 'https://api.ownthink.com/bot' 52 | params = { 53 | 'spoken': question 54 | } 55 | r = requests.get(url, params=params) 56 | json_data = r.json() 57 | answer = json_data['data']['info']['text'] 58 | return answer 59 | 60 | 61 | if __name__ == "__main__": 62 | nlp_ownthink_df = nlp_ownthink(word="人工智能", indicator="tag") 63 | print(nlp_ownthink_df) 64 | 65 | nlp_answer_df = nlp_answer(question="姚明的身高") 66 | print(nlp_answer_df) 67 | -------------------------------------------------------------------------------- /akshare/futures/futures_foreign.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/3/26 19:10 5 | Desc: foreign futures detail data 6 | http://finance.sina.com.cn/money/future/hf.html 7 | """ 8 | from datetime import datetime 9 | 10 | import pandas as pd 11 | import requests 12 | 13 | from akshare.futures.hf_futures_sina import hq_subscribe_exchange_symbol 14 | 15 | 16 | def futures_foreign_hist(symbol: str = "ZSD") -> pd.DataFrame: 17 | """ 18 | foreign futures historical data 19 | :param symbol: futures symbol, you can get it from hf_subscribe_exchange_symbol function 20 | :type symbol: str 21 | :return: historical data from 2010 22 | :rtype: pandas.DataFrame 23 | """ 24 | today = f'{datetime.today().year}_{datetime.today().month}_{datetime.today().day}' 25 | url = f"https://stock2.finance.sina.com.cn/futures/api/jsonp.php/var%20_S{today}=/GlobalFuturesService.getGlobalFuturesDailyKLine" 26 | params = { 27 | "symbol": symbol, 28 | "_": today, 29 | "source": "web", 30 | } 31 | r = requests.get(url, params=params) 32 | data_text = r.text 33 | data_df = pd.read_json(data_text[data_text.find("["):-2]) 34 | return data_df 35 | 36 | 37 | def futures_foreign_detail(symbol: str = "ZSD") -> pd.DataFrame: 38 | """ 39 | foreign futures contract detail data 40 | :param symbol: futures symbol, you can get it from hf_subscribe_exchange_symbol function 41 | :type symbol: str 42 | :return: contract detail 43 | :rtype: pandas.DataFrame 44 | """ 45 | url = f"https://finance.sina.com.cn/futures/quotes/{symbol}.shtml" 46 | r = requests.get(url) 47 | r.encoding = "gbk" 48 | data_df = pd.read_html(r.text)[6] 49 | return data_df 50 | 51 | 52 | if __name__ == '__main__': 53 | subscribes = hq_subscribe_exchange_symbol() 54 | for item in subscribes: 55 | futures_foreign_hist_df = futures_foreign_hist(symbol="ZSD") 56 | print(futures_foreign_hist_df) 57 | futures_foreign_detail_df = futures_foreign_detail(symbol="ZSD") 58 | print(futures_foreign_detail_df) 59 | -------------------------------------------------------------------------------- /akshare/fortune/fortune_bloomberg.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/7/11 21:44 5 | Desc: 彭博亿万富豪指数 6 | https://www.bloomberg.com/billionaires/ 7 | """ 8 | import pandas as pd 9 | import requests 10 | from bs4 import BeautifulSoup 11 | 12 | 13 | def index_bloomberg_billionaires() -> pd.DataFrame: 14 | """ 15 | Bloomberg Billionaires Index 16 | https://www.bloomberg.com/billionaires/ 17 | :return: 彭博亿万富豪指数 18 | :rtype: pandas.DataFrame 19 | """ 20 | url = "https://www.bloomberg.com/billionaires" 21 | headers = { 22 | "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", 23 | "accept-encoding": "gzip, deflate, br", 24 | "accept-language": "zh-CN,zh;q=0.9,en;q=0.8", 25 | "cache-control": "no-cache", 26 | "pragma": "no-cache", 27 | "sec-fetch-dest": "document", 28 | "sec-fetch-mode": "navigate", 29 | "sec-fetch-site": "same-origin", 30 | "sec-fetch-user": "?1", 31 | "upgrade-insecure-requests": "1", 32 | "referer": "https://www.bloomberg.com/", 33 | "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36", 34 | } 35 | r = requests.get(url, headers=headers) 36 | soup = BeautifulSoup(r.text, "lxml") 37 | big_content_list = list() 38 | soup_node = soup.find(attrs={"class": "table-chart"}).find_all(attrs={"class": "table-row"}) 39 | for row in soup_node: 40 | temp_content_list = row.text.strip().replace("\n", "").split(" ") 41 | content_list = [item for item in temp_content_list if item != ""] 42 | big_content_list.append(content_list) 43 | temp_df = pd.DataFrame(big_content_list) 44 | temp_df.columns = ["rank", "name", "total_net_worth", "last_change", "YTD_change", "country", "industry"] 45 | return temp_df 46 | 47 | 48 | if __name__ == '__main__': 49 | index_bloomberg_billionaires_df = index_bloomberg_billionaires() 50 | print(index_bloomberg_billionaires_df) 51 | -------------------------------------------------------------------------------- /akshare/stock_fundamental/stock_notice.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2021/4/17 14:49 5 | Desc: 东方财富网-数据中心-公告大全-沪深 A 股公告 6 | http://data.eastmoney.com/notices/hsa/5.html 7 | """ 8 | import pandas as pd 9 | import requests 10 | from tqdm import tqdm 11 | 12 | 13 | def stock_notice_report() -> pd.DataFrame: 14 | """ 15 | 东方财富网-数据中心-公告大全-沪深 A 股公告 16 | :return: 沪深 A 股公告 17 | :rtype: pandas.DataFrame 18 | """ 19 | url = "http://np-anotice-stock.eastmoney.com/api/security/ann" 20 | big_df = pd.DataFrame() 21 | for page in tqdm(range(1, 1000)): 22 | params = { 23 | "sr": "-1", 24 | "page_size": "100", 25 | "page_index": page, 26 | "ann_type": "A", 27 | "client_source": "web", 28 | "f_node": "0", 29 | "s_node": "0", 30 | } 31 | r = requests.get(url, params=params) 32 | data_json = r.json() 33 | temp_df = pd.DataFrame(data_json["data"]["list"]) 34 | temp_codes_df = pd.DataFrame( 35 | [item["codes"][0] for item in data_json["data"]["list"]] 36 | ) 37 | try: 38 | temp_columns_df = pd.DataFrame( 39 | [item["columns"][0] for item in data_json["data"]["list"]] 40 | ) 41 | except: 42 | continue 43 | del temp_df["codes"] 44 | del temp_df["columns"] 45 | temp_df = pd.concat([temp_df, temp_columns_df, temp_codes_df], axis=1) 46 | big_df = big_df.append(temp_df, ignore_index=True) 47 | big_df.columns = [ 48 | "_", 49 | "_", 50 | "公告日期", 51 | "公告标题", 52 | "_", 53 | "公告类型", 54 | "_", 55 | "_", 56 | "名称", 57 | "代码", 58 | ] 59 | big_df = big_df[ 60 | [ 61 | "代码", 62 | "名称", 63 | "公告标题", 64 | "公告类型", 65 | "公告日期", 66 | ] 67 | ] 68 | return big_df 69 | 70 | 71 | if __name__ == "__main__": 72 | stock_notice_report_df = stock_notice_report() 73 | print(stock_notice_report_df) 74 | -------------------------------------------------------------------------------- /akshare/news/cctv_news.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2021/1/25 12:54 5 | Desc: 新闻联播文字稿 6 | http://www.xwlbo.com/date-2020-7-11.html 7 | """ 8 | import re 9 | 10 | import pandas as pd 11 | import requests 12 | from bs4 import BeautifulSoup 13 | from tqdm import tqdm 14 | 15 | 16 | def news_cctv(date: str = "20200902") -> pd.DataFrame: 17 | """ 18 | 新闻联播文字稿 19 | http://www.xwlbo.com/date-2020-7-11.html 20 | :param date: 需要获取数据的日期; 目前 2018 年后 21 | :type date: str 22 | :return: 新闻联播文字稿 23 | :rtype: pandas.DataFrame 24 | """ 25 | url = f"http://www.xwlbo.com/date-{date[:4]}-{int(date[4:6])}-{date[6:]}.html" 26 | r = requests.get(url) 27 | soup = BeautifulSoup(r.text, "lxml") 28 | pattern = re.compile(f"{date[:4]}年{int(date[4:6])}月{int(date[6:])}日新闻联播") 29 | url = soup.find("a", text=pattern)["href"] 30 | r = requests.get(url) 31 | soup = BeautifulSoup(r.text, "lxml") 32 | news_list = soup.find("div", attrs={"class": "text_content"}).find_all("a") 33 | title_list = [item.get_text() for item in news_list] 34 | href_list = [item["href"] for item in news_list] 35 | news_content_list = [] 36 | for href in tqdm(href_list): 37 | if "http://www.xwlbo.com" in href: 38 | url = href 39 | else: 40 | url = f"http://www.xwlbo.com/{href}" 41 | r = requests.get(url) 42 | soup = BeautifulSoup(r.text, "lxml") 43 | content_list = ( 44 | soup.find(attrs={"id": "tab_con2"}) 45 | .find("div", attrs={"class": "text_content"}) 46 | .find_all("p") 47 | ) 48 | content = " ".join([item.get_text() for item in content_list]) 49 | pure_content = content.strip("央视网消息(新闻联播文字版):").strip() 50 | news_content_list.append(pure_content) 51 | temp_df = pd.DataFrame( 52 | [[date] * len(title_list), title_list, news_content_list], 53 | index=["date", "title", "content"], 54 | ).T 55 | return temp_df 56 | 57 | 58 | if __name__ == "__main__": 59 | news_cctv_df = news_cctv(date="20210123") 60 | print(news_cctv_df) 61 | -------------------------------------------------------------------------------- /.github/workflows/release_and_deploy.yml: -------------------------------------------------------------------------------- 1 | name: release and deploy 2 | 3 | on: 4 | push: 5 | branchs: 6 | - master 7 | tags: 8 | - "v*.*.*" 9 | 10 | jobs: 11 | build: 12 | runs-on: ubuntu-latest 13 | strategy: 14 | matrix: 15 | os: [ubuntu-latest, macos-latest, windows-latest] 16 | python-version: [3.7, 3.8] 17 | 18 | steps: 19 | - uses: actions/checkout@v2 20 | - name: Set up Python ${{ matrix.python-version }} 21 | uses: actions/setup-python@v1 22 | with: 23 | python-version: ${{ matrix.python-version }} 24 | - name: Install dependencies 25 | run: | 26 | python -m pip install --upgrade pip 27 | pip install -r requirements.txt 28 | - name: Lint with flake8 29 | run: | 30 | pip install flake8 31 | # stop the build if there are Python syntax errors or undefined names 32 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 33 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 34 | flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 35 | - name: Test with pytest 36 | run: | 37 | pip install pytest 38 | pytest 39 | 40 | deploy: 41 | needs: build 42 | runs-on: ubuntu-latest 43 | steps: 44 | - name: checkout 45 | uses: actions/checkout@v2 46 | - name: release 47 | uses: softprops/action-gh-release@v1 48 | env: 49 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 50 | - name: set up python 51 | uses: actions/setup-python@v1 52 | with: 53 | python-version: "3.x" 54 | - name: Install dependencies 55 | run: | 56 | python -m pip install --upgrade pip 57 | pip install setuptools wheel twine 58 | - name: Build and publish 59 | env: 60 | TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} 61 | TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} 62 | run: | 63 | python setup.py sdist bdist_wheel 64 | twine upload dist/* 65 | -------------------------------------------------------------------------------- /akshare/crypto/crypto_hold.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2021/4/20 15:08 5 | Desc: 金十数据-比特币持仓报告 6 | https://datacenter.jin10.com/dc_report?name=bitcoint 7 | """ 8 | import requests 9 | import pandas as pd 10 | 11 | 12 | def crypto_bitcoin_hold_report(): 13 | """ 14 | 金十数据-比特币持仓报告 15 | https://datacenter.jin10.com/dc_report?name=bitcoint 16 | :return: 比特币持仓报告 17 | :rtype: pandas.DataFrame 18 | """ 19 | url = "https://datacenter-api.jin10.com/bitcoin_treasuries/list" 20 | headers = { 21 | "accept": "*/*", 22 | "accept-encoding": "gzip, deflate, br", 23 | "accept-language": "zh-CN,zh;q=0.9,en;q=0.8", 24 | "cache-control": "no-cache", 25 | "origin": "https://datacenter.jin10.com", 26 | "pragma": "no-cache", 27 | "referer": "https://datacenter.jin10.com/", 28 | "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36", 29 | "x-app-id": "rU6QIu7JHe2gOUeR", 30 | "x-version": "1.0.0", 31 | } 32 | params = {"_": "1618902583006"} 33 | r = requests.get(url, params=params, headers=headers) 34 | data_json = r.json() 35 | temp_df = pd.DataFrame(data_json["data"]["values"]) 36 | temp_df.columns = [ 37 | '代码', 38 | '公司名称-英文', 39 | '国家/地区', 40 | '市值', 41 | '比特币占市值比重', 42 | '持仓成本', 43 | '持仓占比', 44 | '持仓量', 45 | '当日持仓市值', 46 | '查询日期', 47 | '公告链接', 48 | '_', 49 | '分类', 50 | '倍数', 51 | '_', 52 | '公司名称-中文', 53 | ] 54 | temp_df = temp_df[[ 55 | '代码', 56 | '公司名称-英文', 57 | '公司名称-中文', 58 | '国家/地区', 59 | '市值', 60 | '比特币占市值比重', 61 | '持仓成本', 62 | '持仓占比', 63 | '持仓量', 64 | '当日持仓市值', 65 | '查询日期', 66 | '公告链接', 67 | '分类', 68 | '倍数', 69 | ]] 70 | return temp_df 71 | 72 | 73 | if __name__ == '__main__': 74 | crypto_bitcoin_hold_report_df = crypto_bitcoin_hold_report() 75 | print(crypto_bitcoin_hold_report_df) 76 | -------------------------------------------------------------------------------- /akshare/stock_feature/stock_em_comment.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2021/3/26 15:28 5 | Desc: 东方财富网-数据中心-特色数据-千股千评 6 | http://data.eastmoney.com/stockcomment/ 7 | """ 8 | import demjson 9 | import pandas as pd 10 | import requests 11 | 12 | 13 | def stock_em_comment() -> pd.DataFrame: 14 | """ 15 | 东方财富网-数据中心-特色数据-千股千评 16 | http://data.eastmoney.com/stockcomment/ 17 | :return: 千股千评数据 18 | :rtype: pandas.DataFrame 19 | """ 20 | url = "http://dcfm.eastmoney.com/em_mutisvcexpandinterface/api/js/get" 21 | params = { 22 | "type": "QGQP_LB", 23 | "token": "70f12f2f4f091e459a279469fe49eca5", 24 | "cmd": "", 25 | "st": "Code", 26 | "sr": "1", 27 | "p": "1", 28 | "ps": "10000", 29 | "js": "var fHdHpFHW={pages:(tp),data:(x),font:(font)}", 30 | "filter": "", 31 | "rt": "52831859", 32 | } 33 | r = requests.get(url, params=params) 34 | data_text = r.text 35 | data_json = demjson.decode(data_text[data_text.find("{") :]) 36 | temp_df = pd.DataFrame(data_json["data"]) 37 | temp_df.reset_index(inplace=True) 38 | temp_df["index"] = range(1, len(temp_df) + 1) 39 | temp_df.columns = [ 40 | "序号", 41 | "发布时间", 42 | "代码", 43 | "名称", 44 | "最新价", 45 | "涨跌幅", 46 | "市盈率", 47 | "换手率", 48 | "主力成本", 49 | "机构参与度", 50 | "_", 51 | "_", 52 | "_", 53 | "_", 54 | "_", 55 | "_", 56 | "_", 57 | "_", 58 | "_", 59 | "综合得分", 60 | "上升", 61 | "目前排名", 62 | "关注指数", 63 | ] 64 | temp_df = temp_df[ 65 | [ 66 | "序号", 67 | "代码", 68 | "名称", 69 | "最新价", 70 | "涨跌幅", 71 | "换手率", 72 | "市盈率", 73 | "主力成本", 74 | "机构参与度", 75 | "综合得分", 76 | "上升", 77 | "目前排名", 78 | "关注指数", 79 | "发布时间", 80 | ] 81 | ] 82 | return temp_df 83 | 84 | 85 | if __name__ == "__main__": 86 | stock_em_comment_df = stock_em_comment() 87 | print(stock_em_comment_df) 88 | -------------------------------------------------------------------------------- /akshare/ws/js_ws_news.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2021/1/26 12:47 5 | Desc: 金十数据 websocket 实时数据接口-新闻 6 | https://www.jin10.com/ 7 | wss://wss-flash-1.jin10.com/ 8 | # TODO 此接口在 Ubuntu 18.04 里面有问题 9 | """ 10 | import pandas as pd 11 | import requests 12 | 13 | 14 | def js_news(indicator: str = '最新资讯') -> pd.DataFrame: 15 | """ 16 | 金十数据-最新资讯 17 | https://www.jin10.com/ 18 | :param indicator: choice of {'最新资讯', '最新数据'} 19 | :type indicator: str 20 | :return: 最新资讯 21 | :rtype: pandas.DataFrame 22 | """ 23 | url = 'https://m.jin10.com/flash' 24 | r = requests.get(url) 25 | text_data = r.json() 26 | text_data = [item.strip() for item in text_data] 27 | big_df = pd.DataFrame() 28 | try: 29 | temp_df_part_one = pd.DataFrame([item.split("#") for item in text_data if item.startswith('0#1#')]).iloc[:, [2, 3]] 30 | except IndexError: 31 | temp_df_part_one = pd.DataFrame() 32 | try: 33 | temp_df_part_two = pd.DataFrame([item.split('#') for item in text_data if item.startswith('0#0#')]).iloc[:, [2, 3]] 34 | except IndexError: 35 | temp_df_part_two = pd.DataFrame() 36 | try: 37 | temp_df_part_three = pd.DataFrame([item.split('#') for item in text_data if item.startswith('1#')]).iloc[:, [8, 2, 3, 5]] 38 | except IndexError: 39 | temp_df_part_three = pd.DataFrame() 40 | big_df = big_df.append(temp_df_part_one, ignore_index=True) 41 | big_df = big_df.append(temp_df_part_two, ignore_index=True) 42 | big_df.columns = [ 43 | 'datetime', 44 | 'content', 45 | ] 46 | big_df['datetime'] = pd.to_datetime(big_df['datetime']) 47 | big_df.sort_values('datetime', ascending=False, inplace=True) 48 | big_df.reset_index(inplace=True, drop=True) 49 | if not temp_df_part_three.empty: 50 | temp_df_part_three.columns = [ 51 | 'datetime', 52 | 'content', 53 | 'before', 54 | 'now', 55 | ] 56 | if indicator == '最新资讯': 57 | return big_df 58 | else: 59 | return temp_df_part_three 60 | 61 | 62 | if __name__ == '__main__': 63 | js_news_df = js_news(indicator='最新资讯') 64 | print(js_news_df) 65 | -------------------------------------------------------------------------------- /akshare/futures_derivative/futures_xgx.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/4/19 14:27 5 | Desc: 西本新干线-指数数据 6 | http://nanjing.96369.net/ 7 | """ 8 | import random 9 | from io import BytesIO 10 | 11 | import matplotlib.pyplot as plt 12 | import pandas as pd 13 | import requests 14 | from PIL import Image 15 | from bs4 import BeautifulSoup 16 | 17 | from akshare.futures_derivative.cons import ( 18 | xgx_short_headers, 19 | xgx_headers, 20 | xgx_code_url, 21 | xgx_main_url, 22 | symbol_dict, 23 | ) 24 | 25 | plt.rcParams["font.sans-serif"] = "SimHei" 26 | plt.rcParams["axes.unicode_minus"] = False 27 | 28 | 29 | def _get_code_pic(): 30 | payload = {"": round(random.random(), 16)} 31 | session = requests.session() 32 | res = session.get(xgx_code_url, params=payload, headers=xgx_short_headers) 33 | f = Image.open(BytesIO(res.content)) 34 | f.show() 35 | return session 36 | 37 | 38 | def futures_xgx_index( 39 | symbol: str = 67, 40 | start_date: str = "2000-10-01", 41 | end_date: str = "2020-04-17", 42 | plot: bool = True, 43 | ) -> pd.DataFrame: 44 | session = _get_code_pic() 45 | value = input() 46 | payload = {"txtStartTime": start_date, "txtEndTime": end_date, "txtyzcode": value} 47 | res = session.post(xgx_main_url.format(symbol), data=payload, headers=xgx_headers) 48 | soup = BeautifulSoup(res.text, "lxml") 49 | 50 | table_df = pd.read_html(res.text)[0] 51 | table_df.index = pd.to_datetime(table_df["日期"]) 52 | del table_df["日期"] 53 | if plot: 54 | table_df["值"].plot() 55 | plt.title( 56 | soup.find("div", attrs={"class": "commodity_right"}).find("h5").get_text() 57 | ) 58 | plt.xlabel("日期") 59 | plt.ylabel("值") 60 | plt.show() 61 | return table_df 62 | else: 63 | return table_df 64 | 65 | 66 | if __name__ == "__main__": 67 | # 国内螺纹钢社会库存量 67 68 | # 国内线材社会库存量 68 69 | symbol_dict_df = pd.DataFrame.from_dict(symbol_dict, orient="index") 70 | print(symbol_dict_df) 71 | futures_xgx_index_df = futures_xgx_index( 72 | symbol=161, start_date="2000-10-01", end_date="2020-04-17", plot=True 73 | ) 74 | print(futures_xgx_index_df) 75 | -------------------------------------------------------------------------------- /akshare/stock_feature/stock_em_gdzjc.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2021/4/26 14:57 5 | Desc: 东方财富网-数据中心-特色数据-高管持股 6 | http://data.eastmoney.com/executive/gdzjc.html 7 | """ 8 | import warnings 9 | 10 | import pandas as pd 11 | import requests 12 | 13 | 14 | def stock_em_ggcg(): 15 | """ 16 | 东方财富网-数据中心-特色数据-高管持股 17 | http://data.eastmoney.com/executive/gdzjc.html 18 | :return: 高管持股 19 | :rtype: pandas.DataFrame 20 | """ 21 | warnings.warn("正在下载数据,请稍等") 22 | url = 'http://datainterface3.eastmoney.com/EM_DataCenter_V3/api/GDZC/GetGDZC' 23 | params = { 24 | 'pageSize': '5000000', 25 | 'pageNum': '1', 26 | 'tkn': 'eastmoney', 27 | 'cfg': 'gdzc', 28 | 'secucode': '', 29 | 'fx': '', 30 | 'sharehdname': '', 31 | 'sortFields': 'BDJZ', 32 | 'sortDirec': '1', 33 | 'startDate': '', 34 | 'endDate': '', 35 | 'p': '1', 36 | 'pageNo': '1', 37 | '_': '1619420305426', 38 | } 39 | r = requests.get(url, params=params) 40 | data_json = r.json() 41 | data_str_list = data_json['Data'][0]['Data'] 42 | temp_df = pd.DataFrame([item.split('|') for item in data_str_list]) 43 | temp_df.columns = [ 44 | '_', 45 | '_', 46 | '代码', 47 | '最新价', 48 | '涨跌幅', 49 | '名称', 50 | '股东名称', 51 | '持股变动信息-增减', 52 | '持股变动信息-变动数量', 53 | '持股变动信息-占流通股比例', 54 | '持股变动信息-占总股本比例', 55 | '_', 56 | '变动后持股情况-持股总数', 57 | '变动后持股情况-占总股本比例', 58 | '变动后持股情况-持流通股数', 59 | '变动后持股情况-占流通股比例', 60 | '变动开始日', 61 | '变动截止日', 62 | '公告日', 63 | ] 64 | temp_df = temp_df[[ 65 | '代码', 66 | '名称', 67 | '最新价', 68 | '涨跌幅', 69 | '股东名称', 70 | '持股变动信息-增减', 71 | '持股变动信息-变动数量', 72 | '持股变动信息-占总股本比例', 73 | '持股变动信息-占流通股比例', 74 | '变动后持股情况-持股总数', 75 | '变动后持股情况-占总股本比例', 76 | '变动后持股情况-持流通股数', 77 | '变动后持股情况-占流通股比例', 78 | '变动开始日', 79 | '变动截止日', 80 | '公告日', 81 | ]] 82 | return temp_df 83 | 84 | 85 | if __name__ == '__main__': 86 | stock_em_ggcg_df = stock_em_ggcg() 87 | print(stock_em_ggcg_df) 88 | -------------------------------------------------------------------------------- /akshare/energy/energy_oil.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/4/2 20:24 5 | Desc: 东方财富-数据中心-中国油价 6 | http://data.eastmoney.com/cjsj/oil_default.html 7 | """ 8 | import json 9 | 10 | import pandas as pd 11 | import requests 12 | 13 | 14 | def energy_oil_hist() -> pd.DataFrame: 15 | """ 16 | 汽柴油历史调价信息 17 | http://data.eastmoney.com/cjsj/oil_default.html 18 | :return: 汽柴油历史调价数 19 | :rtype: pandas.DataFrame 20 | """ 21 | url = "http://datacenter.eastmoney.com/api/data/get" 22 | params = { 23 | "type": "RPTA_WEB_YJ_BD", 24 | "sty": "ALL", 25 | "source": "WEB", 26 | "p": "1", 27 | "ps": "5000", 28 | "st": "dim_date", 29 | "sr": "-1", 30 | "var": "OxGINxug", 31 | "rt": "52861006", 32 | } 33 | r = requests.get(url, params=params) 34 | data_text = r.text 35 | data_json = json.loads(data_text[data_text.find("{"): -1]) 36 | temp_df = pd.DataFrame(data_json["result"]["data"]) 37 | temp_df.columns = ["日期", "汽油价格", "柴油价格", "汽油涨幅", "柴油涨幅"] 38 | return temp_df 39 | 40 | 41 | def energy_oil_detail(date: str = "2020-03-19") -> pd.DataFrame: 42 | """ 43 | 全国各地区的汽油和柴油油价 44 | http://data.eastmoney.com/cjsj/oil_default.html 45 | :param date: call function: energy_oil_hist to get the date point 46 | :type date: str 47 | :return: oil price at specific date 48 | :rtype: pandas.DataFrame 49 | """ 50 | url = "http://datacenter.eastmoney.com/api/data/get" 51 | params = { 52 | "type": "RPTA_WEB_YJ_JH", 53 | "sty": "ALL", 54 | "source": "WEB", 55 | "p": "1", 56 | "ps": "5000", 57 | "st": "cityname", 58 | "sr": "1", 59 | "filter": f'(dim_date="{date}")', 60 | "var": "todayPriceData", 61 | } 62 | r = requests.get(url, params=params) 63 | data_text = r.text 64 | data_json = json.loads(data_text[data_text.find("{"): -1]) 65 | temp_df = pd.DataFrame(data_json["result"]["data"]).iloc[:, 1:] 66 | return temp_df 67 | 68 | 69 | if __name__ == "__main__": 70 | energy_oil_hist_df = energy_oil_hist() 71 | print(energy_oil_hist_df) 72 | 73 | energy_oil_detail_df = energy_oil_detail(date="2021-04-01") 74 | print(energy_oil_detail_df) 75 | -------------------------------------------------------------------------------- /docs/akdocker/akdocker.md: -------------------------------------------------------------------------------- 1 | # [AKShare](https://github.com/jindaxiang/akshare) Docker 部署 2 | 3 | 目前 [AKShare](https://github.com/jindaxiang/akshare) 数据接口是基于 Python 开发的,鉴于部分其他语言的用户难以在短时间部署 4 | [AKShare](https://github.com/jindaxiang/akshare) 的 Python 使用环境,特此提供基于虚拟化容器技术 Docker 的使用教程。 5 | 6 | ## 安装 Docker 7 | 8 | ### 官方安装指导 9 | 10 | 1. Windows 10: [安装教程](https://hub.docker.com/editions/community/docker-ce-desktop-windows) 11 | 2. Mac: [安装教程](https://docs.docker.com/docker-for-mac/install) 12 | 3. Ubuntu: [安装教程](https://docs.docker.com/engine/install/ubuntu) 13 | 4. CentOS: [安装教程](https://docs.docker.com/engine/install/centos) 14 | 15 | ### 第三方安装指导 16 | 17 | 1. [Docker 安装教程](https://www.runoob.com/docker/docker-tutorial.html) 18 | 2. 建议 Windows 7 和 8 的用户升级到 Windows 10 系统进行安装 19 | 3. [Windows 镜像下载地址](https://msdn.itellyou.cn/) 20 | 21 | ### 配置国内镜像 22 | 23 | 1. [Docker 国内镜像加速教程](https://www.runoob.com/docker/docker-mirror-acceleration.html) 24 | 2. 请在国内使用的用户务必进行该项配置, 从而加速获取镜像的速度. 25 | 26 | ## AKDocker 镜像使用 27 | 28 | ### 拉取 AKDocker 镜像 29 | 30 | ``` 31 | docker pull registry.cn-hangzhou.aliyuncs.com/akshare/akdocker 32 | ``` 33 | 34 | ### 运行 AKDocker 容器 35 | 36 | ``` 37 | docker run -it registry.cn-hangzhou.aliyuncs.com/akshare/akdocker python 38 | ``` 39 | 40 | ### 测试 AKDocker 容器 41 | 42 | ```python 43 | import akshare as ak 44 | ak.__version__ 45 | ``` 46 | 47 | ## 使用案例 48 | 49 | ### 背景说明 50 | 51 | 本案例是基于 AKDocker 容器中已经安装的 JupyterLab 来演示的. 主要是利用 JupyterLab 的 Python 交互式的开发环境, 使用户可以在 Web 输入 AKShare 52 | 的 Python 示例代码, 仅需要修改一些简单的参数, 就可以获取需要的数据. 为了能把 JupyterLab 中下载的数据从容器映射到本地, 请在 53 | 容器的 ```/home``` 目录下编辑 ```.ipynb``` 文件, 如果需要下载相关的文件也请保存到该目录. 54 | 55 | ### 命令行 56 | 57 | ``` 58 | docker run -it -p 8888:8888 --name akdocker -v /c/home:/home registry.cn-hangzhou.aliyuncs.com/akshare/akdocker jupyter-lab --allow-root --no-browser --ip=0.0.0.0 59 | ``` 60 | 61 | ### 注意事项 62 | 63 | 1. 其中 Windows 系统的路径如: ```C:\home``` 需要改写为: ```/c/home``` 的形式; 64 | 2. 在 Terminal 中运行上述指令后,会在 Terminal 中显示如下信息: ![](https://jfds-1252952517.cos.ap-chengdu.myqcloud.com/akshare/readme/akdocker/akdocker_terminal.png) 65 | 3. 打开本地游览器输入地址: ```http://127.0.0.1:8888/lab?token=bbe7c8633c098b67df913dce522b82e00828b311a6fc954d```; 66 | 4. 在本地游览器中的 JupyterLab 界面进入 ```home``` 文件夹, 该目录内容会与本地的 ```C:\home``` 保持同步, 可以在此编辑 notebook 文件和导入数据到该文件夹从而在本地的 ```C:\home``` 文件夹下获取数据; 67 | -------------------------------------------------------------------------------- /akshare/air/air_hebei.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2021/4/26 12:33 5 | Desc: 河北省空气质量预报信息发布系统 6 | http://110.249.223.67/publish/ 7 | 每日 17 时发布 8 | 等级划分 9 | 1. 空气污染指数为0-50,空气质量级别为一级,空气质量状况属于优。此时,空气质量令人满意,基本无空气污染,各类人群可正常活动。 10 | 2. 空气污染指数为51-100,空气质量级别为二级,空气质量状况属于良。此时空气质量可接受,但某些污染物可能对极少数异常敏感人群健康有较弱影响,建议极少数异常敏感人群应减少户外活动。 11 | 3. 空气污染指数为101-150,空气质量级别为三级,空气质量状况属于轻度污染。此时,易感人群症状有轻度加剧,健康人群出现刺激症状。建议儿童、老年人及心脏病、呼吸系统疾病患者应减少长时间、高强度的户外锻炼。 12 | 4. 空气污染指数为151-200,空气质量级别为四级,空气质量状况属于中度污染。此时,进一步加剧易感人群症状,可能对健康人群心脏、呼吸系统有影响,建议疾病患者避免长时间、高强度的户外锻练,一般人群适量减少户外运动。 13 | 5. 空气污染指数为201-300,空气质量级别为五级,空气质量状况属于重度污染。此时,心脏病和肺病患者症状显著加剧,运动耐受力降低,健康人群普遍出现症状,建议儿童、老年人和心脏病、肺病患者应停留在室内,停止户外运动,一般人群减少户外运动。 14 | 6. 空气污染指数大于300,空气质量级别为六级,空气质量状况属于严重污染。此时,健康人群运动耐受力降低,有明显强烈症状,提前出现某些疾病,建议儿童、老年人和病人应当留在室内,避免体力消耗,一般人群应避免户外活动。 15 | 发布单位:河北省环境应急与重污染天气预警中心 技术支持:中国科学院大气物理研究所 中科三清科技有限公司 16 | """ 17 | from datetime import datetime 18 | 19 | import pandas as pd 20 | from tqdm import tqdm 21 | import requests 22 | 23 | 24 | def air_quality_hebei(city: str = "唐山市") -> pd.DataFrame: 25 | """ 26 | 河北省空气质量预报信息发布系统-空气质量预报, 未来 6 天 27 | http://110.249.223.67/publish/ 28 | :param city: choice of {'石家庄市', '唐山市', '秦皇岛市', '邯郸市', '邢台市', '保定市', '张家口市', '承德市', '沧州市', '廊坊市', '衡水市', '辛集市', '定州市'} 29 | :type city: str 30 | :return: city = "", 返回所有地区的数据; city="唐山市", 返回唐山市的数据 31 | :rtype: pandas.DataFrame 32 | """ 33 | url = "http://110.249.223.67/publishNewServer/api/CityPublishInfo/GetProvinceAndCityPublishData" 34 | params = {"publishDate": f"{datetime.today().strftime('%Y-%m-%d')} 16:00:00"} 35 | r = requests.get(url, params=params) 36 | json_data = r.json() 37 | city_list = pd.DataFrame.from_dict(json_data["cityPublishDatas"], orient="columns")[ 38 | "CityName" 39 | ].tolist() 40 | outer_df = pd.DataFrame() 41 | for i in tqdm(range(1, 7)): 42 | inner_df = pd.DataFrame( 43 | [item[f"Date{i}"] for item in json_data["cityPublishDatas"]], 44 | index=city_list, 45 | ) 46 | outer_df = outer_df.append(inner_df) 47 | if city == "": 48 | return outer_df 49 | else: 50 | return outer_df[outer_df.index == city] 51 | 52 | 53 | if __name__ == "__main__": 54 | air_quality_hebei_df = air_quality_hebei(city="石家庄市") 55 | print(air_quality_hebei_df) 56 | -------------------------------------------------------------------------------- /akshare/stock_feature/stock_em_fhps.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2021/3/15 15:46 5 | Desc: 东方财富网-数据中心-年报季报-分红送配 6 | http://data.eastmoney.com/yjfp/ 7 | """ 8 | import pandas as pd 9 | import requests 10 | 11 | 12 | def stock_em_fhps(date: str = "20191231"): 13 | """ 14 | 东方财富网-数据中心-年报季报-分红送配 15 | http://data.eastmoney.com/yjfp/ 16 | :param date: 分红送配报告期 17 | :type date: str 18 | :return: 分红送配 19 | :rtype: pandas.DataFrame 20 | """ 21 | url = 'http://dcfm.eastmoney.com/EM_MutiSvcExpandInterface/api/js/get' 22 | params = { 23 | 'st': 'YAGGR', 24 | 'sr': '-1', 25 | 'ps': '5000', 26 | 'p': '1', 27 | 'type': 'DCSOBS', 28 | 'js': '{"data":(x),"pages":(tp)}', 29 | 'token': '894050c76af8597a853f5b408b759f5d', 30 | 'filter': f'(ReportingPeriod=^{"-".join([date[:4], date[4:6], date[6:]])}^)' 31 | } 32 | r = requests.get(url, params=params) 33 | data_json = r.json() 34 | temp_df = pd.DataFrame(data_json['data']) 35 | temp_df.columns = [ 36 | '_', 37 | '代码', 38 | '名称', 39 | '送转股份-送转总比例', 40 | '送转股份-送转比例', 41 | '送转股份-转股比例', 42 | '现金分红-现金分红比例', 43 | '现金分红-股息率', 44 | '预案公告日', 45 | '_', 46 | '_', 47 | '股权登记日', 48 | '除权除息日', 49 | '_', 50 | '_', 51 | '总股本', 52 | '每股收益', 53 | '每股净资产', 54 | '每股公积金', 55 | '每股未分配利润', 56 | '净利润同比增长', 57 | '分红配送报告期', 58 | '_', 59 | '方案进度', 60 | '配送方案', 61 | '_', 62 | '_', 63 | '_', 64 | '最新公告日期', 65 | '_', 66 | ] 67 | temp_df = temp_df[[ 68 | '代码', 69 | '名称', 70 | '送转股份-送转总比例', 71 | '送转股份-送转比例', 72 | '送转股份-转股比例', 73 | '现金分红-现金分红比例', 74 | '现金分红-股息率', 75 | '每股收益', 76 | '每股净资产', 77 | '每股公积金', 78 | '每股未分配利润', 79 | '净利润同比增长', 80 | '总股本', 81 | '预案公告日', 82 | '股权登记日', 83 | '除权除息日', 84 | '方案进度', 85 | '最新公告日期', 86 | '配送方案', 87 | '分红配送报告期', 88 | ]] 89 | return temp_df 90 | 91 | 92 | if __name__ == '__main__': 93 | stock_em_fhps_df = stock_em_fhps(date="20201231") 94 | print(stock_em_fhps_df) 95 | -------------------------------------------------------------------------------- /akshare/fund/fund_em_portfolio.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2021/2/2 17:54 5 | Desc: 天天基金网-基金档案-投资组合-基金持仓 6 | http://fundf10.eastmoney.com/ccmx_000001.html 7 | """ 8 | import demjson 9 | import pandas as pd 10 | import requests 11 | from bs4 import BeautifulSoup 12 | 13 | 14 | def fund_em_portfolio_hold(code: str = "162411", year: str = "2020") -> pd.DataFrame: 15 | """ 16 | 天天基金网-基金档案-投资组合-基金持仓 17 | http://fundf10.eastmoney.com/ccmx_000001.html 18 | :param code: 基金代码 19 | :type code: str 20 | :param year: 查询年份 21 | :type year: str 22 | :return: 基金持仓 23 | :rtype: pandas.DataFrame 24 | """ 25 | url = "http://fundf10.eastmoney.com/FundArchivesDatas.aspx" 26 | params = { 27 | "type": "jjcc", 28 | "code": code, 29 | "topline": "200", 30 | "year": year, 31 | "month": "", 32 | "rt": "0.913877030254846", 33 | } 34 | r = requests.get(url, params=params) 35 | data_text = r.text 36 | data_json = demjson.decode(data_text[data_text.find("{") : -1]) 37 | soup = BeautifulSoup(data_json["content"], "lxml") 38 | item_label = [ 39 | item.text.split("\xa0\xa0")[1] 40 | for item in soup.find_all("h4", attrs={"class": "t"}) 41 | ] 42 | big_df = pd.DataFrame() 43 | for item in range(len(item_label)): 44 | temp_df = pd.read_html(data_json["content"])[item] 45 | temp_df["股票代码"] = temp_df["股票代码"].astype(str).str.zfill(6) 46 | del temp_df["相关资讯"] 47 | temp_df["占净值比例"] = temp_df["占净值比例"].str.split("%", expand=True).iloc[:, 0] 48 | temp_df.rename(columns={"持股数(万股)": "持股数", "持仓市值(万元)": "持仓市值"}, inplace=True) 49 | temp_df.rename(columns={"持股数(万股)": "持股数", "持仓市值(万元人民币)": "持仓市值"}, inplace=True) 50 | temp_df["季度"] = item_label[item] 51 | temp_df = temp_df[ 52 | [ 53 | "序号", 54 | "股票代码", 55 | "股票名称", 56 | "占净值比例", 57 | "持股数", 58 | "持仓市值", 59 | "季度", 60 | ] 61 | ] 62 | big_df = big_df.append(temp_df, ignore_index=True) 63 | return big_df 64 | 65 | 66 | if __name__ == "__main__": 67 | fund_em_portfolio_hold_df = fund_em_portfolio_hold(code="000001", year="2020") 68 | print(fund_em_portfolio_hold_df) 69 | -------------------------------------------------------------------------------- /akshare/option/czce_option.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/12/15 19:22 5 | Desc: 郑州商品交易所-交易数据-历史行情下载-期权历史行情下载 6 | http://www.czce.com.cn/cn/jysj/lshqxz/H770319index_1.htm 7 | 自 20200101 起,成交量、空盘量、成交额、行权量均为单边计算 8 | 郑州商品交易所-期权上市时间表 9 | "SR": "20170419" 10 | "CF": "20190410" 11 | "TA": "20191216" 12 | "MA": "20191217" 13 | "RM": "20200116" 14 | "ZC": "20200630" 15 | """ 16 | from io import StringIO 17 | import warnings 18 | 19 | import pandas as pd 20 | import requests 21 | from bs4 import BeautifulSoup 22 | 23 | 24 | def option_czce_hist(symbol: str = "SR", year: str = "2019") -> pd.DataFrame: 25 | """ 26 | 郑州商品交易所-交易数据-历史行情下载-期权历史行情下载 27 | http://www.czce.com.cn/cn/jysj/lshqxz/H770319index_1.htm 28 | :param symbol: choice of {"白糖": "SR", "棉花": "CF", "PTA": "TA", "甲醇": "MA", "菜籽粕": "RM", "动力煤": "ZC"} 29 | :type symbol: str 30 | :param year: 需要获取数据的年份, 注意品种的上市时间 31 | :type year: str 32 | :return: 制定年份的日频期权数据 33 | :rtype: pandas.DataFrame 34 | """ 35 | symbol_year_dict = { 36 | "SR": "2017", 37 | "CF": "2019", 38 | "TA": "2019", 39 | "MA": "2019", 40 | "RM": "2020", 41 | "ZC": "2020", 42 | } 43 | if int(symbol_year_dict[symbol]) > int(year): 44 | warnings.warn(f"{year} year, symbol {symbol} is not on trade") 45 | return None 46 | url = "http://app.czce.com.cn/cms/cmsface/czce/newcms/calendarnewAll.jsp" 47 | payload = { 48 | "dataType": "HISTORY", 49 | "radio": "options", 50 | "curpath": "/cn/jysj/lshqxz/H770319index_1.htm", 51 | "curpath1": "", 52 | "pubDate": f"{year}-01-01", 53 | "commodity": symbol, 54 | "fileType": "txt", 55 | "download": "下载", 56 | "operate": "download", 57 | } 58 | res = requests.post(url, data=payload) 59 | soup = BeautifulSoup(res.text, "lxml") 60 | # 获取 url 地址 61 | url = str(soup.find("script"))[ 62 | str(soup.find("script")).find("'") + 1 : str(soup.find("script")).rfind("'") 63 | ].split(",")[0][:-1] 64 | res = requests.get(url) 65 | option_df = pd.read_table(StringIO(res.text), skiprows=1, sep="|", low_memory=False) 66 | return option_df 67 | 68 | 69 | if __name__ == "__main__": 70 | option_czce_hist_df = option_czce_hist(symbol="ZC", year="2020") 71 | print(option_czce_hist_df) 72 | -------------------------------------------------------------------------------- /akshare/futures/futures_sgx_daily.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/3/14 0:25 5 | Desc: Futures data from Singapore Exchange 6 | https://www.sgx.com/zh-hans/research-education/derivatives 7 | https://links.sgx.com/1.0.0/derivatives-daily/5888/FUTURE.zip 8 | """ 9 | import zipfile 10 | from io import BytesIO 11 | from io import StringIO 12 | 13 | import pandas as pd 14 | import requests 15 | from tqdm import tqdm 16 | 17 | from akshare.index.index_investing import index_investing_global 18 | 19 | 20 | def futures_sgx_daily(trade_date: str = "2020/03/06", recent_day: str = "3") -> pd.DataFrame: 21 | """ 22 | Futures daily data from sgx 23 | P.S. it will be slowly if you do not use VPN 24 | :param trade_date: it means the specific trade day you want to fetch 25 | :type trade_date: str e.g., "2020/03/06" 26 | :param recent_day: the data range near the specific trade day 27 | :type recent_day: str e.g. "3" means 3 day before specific trade day 28 | :return: data contains from (trade_date - recent_day) to trade_day 29 | :rtype: pandas.DataFrame 30 | """ 31 | big_df = pd.DataFrame() 32 | index_df = index_investing_global(country="新加坡", index_name="FTSE Singapore", start_date="2020/01/01", end_date=trade_date) 33 | index_df.sort_index(inplace=True) 34 | index_df.reset_index(inplace=True) 35 | index_df.reset_index(inplace=True) 36 | index_df.index = index_df["index"] + 5840 37 | date_start = index_df.index[-1] + 1 - int(recent_day) 38 | date_end = index_df.index[-1] + 1 39 | for page in tqdm(range(date_start, date_end)): 40 | # page = 5883 41 | url = f"https://links.sgx.com/1.0.0/derivatives-daily/{page}/FUTURE.zip" 42 | r = requests.get(url) 43 | with zipfile.ZipFile(BytesIO(r.content)) as file: 44 | with file.open(file.namelist()[0]) as my_file: 45 | data = my_file.read().decode() 46 | if file.namelist()[0].endswith("txt"): 47 | data_df = pd.read_table(StringIO(data)) 48 | else: 49 | data_df = pd.read_csv(StringIO(data)) 50 | big_df = big_df.append(data_df) 51 | return big_df 52 | 53 | 54 | if __name__ == '__main__': 55 | futures_sgx_daily_df = futures_sgx_daily(trade_date="2021/01/23", recent_day="2") 56 | print(futures_sgx_daily_df) 57 | -------------------------------------------------------------------------------- /akshare/pro/client.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2019/11/10 22:52 5 | Desc: 数据接口源代码 6 | """ 7 | from functools import partial 8 | from urllib import parse 9 | 10 | import pandas as pd 11 | import requests 12 | 13 | 14 | class DataApi: 15 | 16 | __token = "" 17 | __http_url = "https://api.qhkch.com" 18 | 19 | def __init__(self, token, timeout=10): 20 | """ 21 | 初始化函数 22 | :param token: API接口TOKEN,用于用户认证 23 | :type token: str 24 | :param timeout: 超时设置 25 | :type timeout: int 26 | """ 27 | self.__token = token 28 | self.__timeout = timeout 29 | 30 | def query(self, api_name, fields="", **kwargs): 31 | """ 32 | :param api_name: 需要调取的接口 33 | :type api_name: str 34 | :param fields: 想要获取的字段 35 | :type fields: str 36 | :param kwargs: 指定需要输入的参数 37 | :type kwargs: 键值对 38 | :return: 指定的数据 39 | :rtype: dict or pandas.DataFrame 40 | """ 41 | headers = { 42 | "X-Token": self.__token, 43 | } 44 | url = parse.urljoin(self.__http_url, "/".join([api_name, *kwargs.values()])) 45 | res = requests.get(url, headers=headers, timeout=self.__timeout) 46 | if res.status_code != 200: 47 | raise Exception("连接异常, 请检查您的Token是否过期和输入的参数是否正确") 48 | data_json = res.json() 49 | if fields == "": 50 | try: 51 | return pd.DataFrame(data_json) 52 | except ValueError as e: 53 | result_df = pd.DataFrame.from_dict(data_json, orient="index", columns=[api_name]) 54 | return result_df 55 | else: # 此处增加处理 56 | if api_name == "variety_all_positions": 57 | big_df = pd.DataFrame() 58 | for item in data_json[fields].keys(): 59 | temp_df = pd.DataFrame(data_json[fields][item]) 60 | temp_df["code"] = item 61 | big_df = big_df.append(temp_df, ignore_index=True) 62 | big_df.reset_index(inplace=True, drop=True) 63 | return big_df 64 | else: 65 | return pd.DataFrame(data_json[fields]) 66 | 67 | def __getattr__(self, name): 68 | return partial(self.query, name) 69 | 70 | 71 | if __name__ == '__main__': 72 | pass 73 | -------------------------------------------------------------------------------- /akshare/futures/futures_inventory_em.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/9/17 13:58 5 | Desc: 东方财富网-数据中心-期货库存数据 6 | http://data.eastmoney.com/ifdata/kcsj.html 7 | """ 8 | import demjson 9 | import pandas as pd 10 | import requests 11 | from bs4 import BeautifulSoup 12 | 13 | 14 | def futures_inventory_em(exchange: str = "上海期货交易所", symbol: str = "沪铝") -> pd.DataFrame: 15 | """ 16 | 东方财富网-数据中心-期货库存数据 17 | http://data.eastmoney.com/ifdata/kcsj.html 18 | :param exchange: choice of {"上海期货交易所", "郑州商品交易所", "大连商品交易所"} 19 | :type exchange: str 20 | :param symbol: http://data.eastmoney.com/ifdata/kcsj.html 对应的中文名称, 如: 沪铝 21 | :type symbol: str 22 | :return: 指定交易所和指定品种的库存数据 23 | :rtype: pandas.DataFrame 24 | """ 25 | url = "http://data.eastmoney.com/ifdata/kcsj.html" 26 | r = requests.get(url) 27 | soup = BeautifulSoup(r.text, "lxml") 28 | temp_soup = soup.find(attrs={"id": "select_jys"}).find_all("option") 29 | temp_key = [item.text for item in temp_soup] 30 | temp_value = [item.get("value") for item in temp_soup] 31 | exchange_dict = dict(zip(temp_key, temp_value)) 32 | url = 'http://datainterface.eastmoney.com/EM_DataCenter/JS.aspx' 33 | params = { 34 | 'type': 'QHKC', 35 | 'sty': 'QHKCSX', 36 | '_': '1618311930407', 37 | } 38 | r = requests.get(url, params=params) 39 | data_text = r.text 40 | data_json = demjson.decode(data_text[1:-1]) 41 | temp_df = pd.DataFrame(data_json) 42 | temp_df = temp_df.iloc[:, 0].str.split(',', expand=True) 43 | symbol_dict = dict(zip(temp_df.iloc[:, 3], temp_df.iloc[:, 2])) 44 | url = "http://datainterface.eastmoney.com/EM_DataCenter/JS.aspx" 45 | params = { 46 | "type": "QHKC", 47 | "sty": "QHKCMX", 48 | "mkt": exchange_dict[exchange], 49 | "code": symbol_dict[symbol], 50 | "stat": "1", 51 | "_": "1587887394138", 52 | } 53 | r = requests.get(url, params=params) 54 | data_text = r.text 55 | data_json = demjson.decode(data_text[1:-1]) 56 | temp_df = pd.DataFrame(data_json).iloc[:, 0].str.split(",", expand=True) 57 | temp_df.columns = ["日期", "库存", "增减"] 58 | return temp_df 59 | 60 | 61 | if __name__ == "__main__": 62 | futures_inventory_em_df = futures_inventory_em(exchange="大连商品交易所", symbol="豆粕") 63 | print(futures_inventory_em_df) 64 | -------------------------------------------------------------------------------- /akshare/futures/futures_em_spot_stock.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/4/3 14:24 5 | Desc: 东方财富网-数据中心-现货与股票 6 | http://data.eastmoney.com/ifdata/xhgp.html 7 | """ 8 | import pandas as pd 9 | import requests 10 | from bs4 import BeautifulSoup 11 | 12 | # pd.set_option('display.expand_frame_repr', False) 13 | # pd.set_option('display.max_columns', None) 14 | 15 | 16 | def futures_spot_stock(indicator: str = "能源") -> pd.DataFrame: 17 | """ 18 | 东方财富网-数据中心-现货与股票 19 | :param indicator: choice of ['能源', '化工', '塑料', '纺织', '有色', '钢铁', '建材', '农副']: 20 | :type indicator: str 21 | :return: 现货与股票上下游对应数据 22 | :rtype: pandas.DataFrame 23 | """ 24 | map_dict = { 25 | "能源": 0, 26 | "化工": 1, 27 | "塑料": 2, 28 | "纺织": 3, 29 | "有色": 4, 30 | "钢铁": 5, 31 | "建材": 6, 32 | "农副": 7, 33 | } 34 | url = "http://data.eastmoney.com/ifdata/xhgp.html" 35 | r = requests.get(url) 36 | temp_df = pd.read_html(r.text)[map_dict.get(indicator)] 37 | temp_columns = [item for item in temp_df.columns if not item.startswith("Un")] 38 | temp_df = temp_df.iloc[:, :10] 39 | temp_df.columns = temp_columns 40 | 41 | soup = BeautifulSoup(r.text, "lxml") 42 | temp_soup = soup.find(attrs={"id": f"tab{map_dict.get(indicator)}"}).find(attrs={"class": "tab1"}).find_all(attrs={"onmousemove": "this.className='over'"}) 43 | [item.find_all(attrs={"onmouseout": "hideall(1);"}) for item in temp_soup] 44 | 45 | big_list = [] 46 | for item in temp_soup: 47 | inner_item = item.find_all(attrs={"onmouseout": "hideall(1);"}) 48 | for hidden_item in inner_item: 49 | hidden_a = hidden_item.find_all("a") 50 | temp_list = [] 51 | for hidden_a_item in hidden_a: 52 | temp_list.append(hidden_a_item.text) 53 | big_list.append(temp_list) 54 | 55 | temp_df["生产商"] = [", ".join(item) for key, item in enumerate(big_list) if key in range(0, len(big_list), 2)] 56 | temp_df["下游用户"] = [", ".join(item) for key, item in enumerate(big_list) if key in range(1, len(big_list), 2)] 57 | return temp_df 58 | 59 | 60 | if __name__ == '__main__': 61 | for sector in ['能源', '化工', '塑料', '纺织', '有色', '钢铁', '建材', '农副']: 62 | futures_spot_stock_df = futures_spot_stock(indicator=sector) 63 | print(futures_spot_stock_df) 64 | -------------------------------------------------------------------------------- /akshare/index/index_kq_fz.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2021/5/1 20:23 5 | Desc: 中国柯桥纺织指数 6 | http://www.kqindex.cn/flzs/jiage 7 | """ 8 | import pandas as pd 9 | import requests 10 | from tqdm import tqdm 11 | 12 | 13 | def index_kq_fz(symbol: str = "价格指数") -> pd.DataFrame: 14 | """ 15 | 中国柯桥纺织指数 16 | http://www.kqindex.cn/flzs/jiage 17 | :param symbol: choice of {'价格指数', '景气指数', '外贸指数'} 18 | :type symbol: str 19 | :return: 中国柯桥纺织指数 20 | :rtype: pandas.DataFrame 21 | """ 22 | symbol_map = { 23 | "价格指数": "1_1", 24 | "景气指数": "1_2", 25 | "外贸指数": "2", 26 | } 27 | url = "http://www.kqindex.cn/flzs/table_data" 28 | params = { 29 | "category": "0", 30 | "start": "", 31 | "end": "", 32 | "indexType": f"{symbol_map[symbol]}", 33 | "pageindex": "1", 34 | "_": "1619871781413", 35 | } 36 | r = requests.get(url, params=params) 37 | data_json = r.json() 38 | page_num = data_json["page"] 39 | big_df = pd.DataFrame() 40 | for page in tqdm(range(1, page_num + 1)): 41 | params = { 42 | "category": "0", 43 | "start": "", 44 | "end": "", 45 | "indexType": f"{symbol_map[symbol]}", 46 | "pageindex": page, 47 | "_": "1619871781413", 48 | } 49 | r = requests.get(url, params=params) 50 | data_json = r.json() 51 | temp_df = pd.DataFrame(data_json["result"]) 52 | big_df = big_df.append(temp_df, ignore_index=True) 53 | if symbol == "价格指数": 54 | big_df.columns = [ 55 | "期次", 56 | "指数", 57 | "涨跌幅", 58 | ] 59 | elif symbol == "景气指数": 60 | big_df.columns = [ 61 | "期次", 62 | "总景气指数", 63 | "涨跌幅", 64 | "流通景气指数", 65 | "生产景气指数", 66 | ] 67 | elif symbol == "外贸指数": 68 | big_df.columns = [ 69 | "期次", 70 | "价格指数", 71 | "涨跌幅", 72 | "景气指数", 73 | "涨跌幅", 74 | ] 75 | return big_df 76 | 77 | 78 | if __name__ == "__main__": 79 | index_kq_df = index_kq_fz(symbol="价格指数") 80 | print(index_kq_df) 81 | 82 | index_kq_df = index_kq_fz(symbol="景气指数") 83 | print(index_kq_df) 84 | 85 | index_kq_df = index_kq_fz(symbol="外贸指数") 86 | print(index_kq_df) 87 | -------------------------------------------------------------------------------- /akshare/article/fred_md.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/4/10 19:58 5 | Desc: Economic Research from Federal Reserve Bank of St. Louis 6 | https://research.stlouisfed.org/econ/mccracken/fred-databases/ 7 | FRED-MD and FRED-QD are large macroeconomic databases designed for the empirical analysis of “big data.” The datasets of monthly and quarterly observations mimic the coverage of datasets already used in the literature, but they add three appealing features. They are updated in real-time through the FRED database. They are publicly accessible, facilitating the replication of empirical work. And they relieve the researcher of the task of incorporating data changes and revisions (a task accomplished by the data desk at the Federal Reserve Bank of St. Louis). 8 | """ 9 | import pandas as pd 10 | 11 | 12 | def fred_md(date: str = "2020-01") -> pd.DataFrame: 13 | """ 14 | The accompanying paper shows that factors extracted from the FRED-MD dataset share the same predictive content as those based on the various vintages of the so-called Stock-Watson data. In addition, it suggests that diffusion indexes constructed as the partial sum of the factor estimates can potentially be useful for the study of business cycle chronology. 15 | :param date: e.g., "2020-03"; from "2015-01" to now 16 | :type date: str 17 | :return: Monthly Data 18 | :rtype: pandas.DataFrame 19 | """ 20 | url = f"https://s3.amazonaws.com/files.fred.stlouisfed.org/fred-md/monthly/{date}.csv" 21 | temp_df = pd.read_csv(url) 22 | return temp_df 23 | 24 | 25 | def fred_qd(date: str = "2020-01") -> pd.DataFrame: 26 | """ 27 | FRED-QD is a quarterly frequency companion to FRED-MD. It is designed to emulate the dataset used in "Disentangling the Channels of the 2007-2009 Recession" by Stock and Watson (2012, NBER WP No. 18094) but also contains several additional series. Comments or suggestions are welcome. 28 | :param date: e.g., "2020-03"; from "2015-01" to now 29 | :type date: str 30 | :return: Quarterly Data 31 | :rtype: pandas.DataFrame 32 | """ 33 | url = f"https://s3.amazonaws.com/files.fred.stlouisfed.org/fred-md/quarterly/{date}.csv" 34 | temp_df = pd.read_csv(url) 35 | return temp_df 36 | 37 | 38 | if __name__ == "__main__": 39 | fred_md_df = fred_md(date="2020-03") 40 | print(fred_md_df) 41 | fred_qd_df = fred_qd(date="2020-03") 42 | print(fred_qd_df) 43 | -------------------------------------------------------------------------------- /akshare/stock_feature/stock_cninfo_yjyg.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2021/1/20 11:34 5 | Desc: 巨潮资讯-首页-数据-预约披露 6 | http://www.cninfo.com.cn/new/commonUrl?url=data/yypl 7 | """ 8 | import pandas as pd 9 | import requests 10 | 11 | 12 | def stock_report_disclosure( 13 | market: str = "科创板", period: str = "2019年报" 14 | ) -> pd.DataFrame: 15 | """ 16 | 巨潮资讯-首页-数据-预约披露 17 | http://www.cninfo.com.cn/new/commonUrl?url=data/yypl 18 | :param market: choice of {"沪深": "szsh", "深市": "sz", "深主板": "szmb", "中小板": "szsme", "创业板": "szcn", "沪市": "sh", "沪主板": "shmb", "科创板": "shkcp"} 19 | :type market: str 20 | :param period: 最近四期的财报 21 | :type period: str 22 | :return: 指定 market 和 period 的数据 23 | :rtype: pandas.DataFrame 24 | """ 25 | market_map = { 26 | "沪深": "szsh", 27 | "深市": "sz", 28 | "深主板": "szmb", 29 | "中小板": "szsme", 30 | "创业板": "szcn", 31 | "沪市": "sh", 32 | "沪主板": "shmb", 33 | "科创板": "shkcp", 34 | } 35 | year = period[:4] 36 | period_map = { 37 | f"{year}一季": f"{year}-03-31", 38 | f"{year}半年报": f"{year}-06-30", 39 | f"{year}三季": f"{year}-09-30", 40 | f"{year}年报": f"{year}-12-31", 41 | } 42 | url = "http://www.cninfo.com.cn/new/information/getPrbookInfo" 43 | params = { 44 | "sectionTime": period_map[period], 45 | "firstTime": "", 46 | "lastTime": "", 47 | "market": market_map[market], 48 | "stockCode": "", 49 | "orderClos": "", 50 | "isDesc": "", 51 | "pagesize": "10000", 52 | "pagenum": "1", 53 | } 54 | r = requests.post(url, params=params) 55 | text_json = r.json() 56 | temp_df = pd.DataFrame(text_json["prbookinfos"]) 57 | temp_df.columns = [ 58 | "股票代码", 59 | "股票简称", 60 | "首次预约", 61 | "实际披露", 62 | "初次变更", 63 | "二次变更", 64 | "三次变更", 65 | "报告期", 66 | "组织码", 67 | ] 68 | temp_df = temp_df[ 69 | [ 70 | "股票代码", 71 | "股票简称", 72 | "首次预约", 73 | "初次变更", 74 | "二次变更", 75 | "三次变更", 76 | "实际披露", 77 | ] 78 | ] 79 | return temp_df 80 | 81 | 82 | if __name__ == "__main__": 83 | stock_report_disclosure_df = stock_report_disclosure(market="沪深", period="2020年报") 84 | print(stock_report_disclosure_df) 85 | -------------------------------------------------------------------------------- /akshare/fund/fund_etf.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2021/1/29 12:52 5 | Desc: 新浪财经-基金行情 6 | http://vip.stock.finance.sina.com.cn/fund_center/index.html#jjhqetf 7 | """ 8 | import demjson 9 | from py_mini_racer import py_mini_racer 10 | import pandas as pd 11 | import requests 12 | 13 | from akshare.stock.cons import hk_js_decode 14 | 15 | 16 | def fund_etf_category_sina(symbol: str = "封闭式基金") -> pd.DataFrame: 17 | """ 18 | 基金列表 19 | http://vip.stock.finance.sina.com.cn/fund_center/index.html#jjhqetf 20 | :param symbol: choice of {"封闭式基金", "ETF基金", "LOF基金"} 21 | :type symbol: str 22 | :return: 指定 symbol 的基金列表 23 | :rtype: pandas.DataFrame 24 | """ 25 | fund_map = { 26 | "封闭式基金": "close_fund", 27 | "ETF基金": "etf_hq_fund", 28 | "LOF基金": "lof_hq_fund", 29 | } 30 | url = "http://vip.stock.finance.sina.com.cn/quotes_service/api/jsonp.php/IO.XSRV2.CallbackList['da_yPT46_Ll7K6WD']/Market_Center.getHQNodeDataSimple" 31 | params = { 32 | "page": "1", 33 | "num": "1000", 34 | "sort": "symbol", 35 | "asc": "0", 36 | "node": fund_map[symbol], 37 | "[object HTMLDivElement]": "qvvne", 38 | } 39 | r = requests.get(url, params=params) 40 | data_text = r.text 41 | data_json = demjson.decode(data_text[data_text.find("([")+1:-2]) 42 | temp_df = pd.DataFrame(data_json) 43 | return temp_df 44 | 45 | 46 | def fund_etf_hist_sina(symbol: str = "sz159996") -> pd.DataFrame: 47 | """ 48 | ETF 基金的日行情数据 49 | http://finance.sina.com.cn/fund/quotes/159996/bc.shtml 50 | :param symbol: 基金名称, 可以通过 fund_etf_category_sina 函数获取 51 | :type symbol: str 52 | :return: ETF 基金的日行情数据 53 | :rtype: pandas.DataFrame 54 | """ 55 | url = f"https://finance.sina.com.cn/realstock/company/{symbol}/hisdata/klc_kl.js" 56 | r = requests.get(url) 57 | js_code = py_mini_racer.MiniRacer() 58 | js_code.eval(hk_js_decode) 59 | dict_list = js_code.call('d', r.text.split("=")[1].split(";")[0].replace('"', "")) # 执行js解密代码 60 | temp_df = pd.DataFrame(dict_list) 61 | temp_df["date"] = pd.to_datetime(temp_df["date"]).dt.date 62 | return temp_df 63 | 64 | 65 | if __name__ == '__main__': 66 | fund_etf_category_sina_df = fund_etf_category_sina(symbol="LOF基金") 67 | print(fund_etf_category_sina_df) 68 | 69 | fund_etf_hist_sina_df = fund_etf_hist_sina(symbol="sz169103") 70 | print(fund_etf_hist_sina_df) 71 | -------------------------------------------------------------------------------- /akshare/option/option_em.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/11/24 21:44 5 | Desc: 东方财富-期权价格 6 | http://quote.eastmoney.com/center 7 | """ 8 | import json 9 | 10 | import pandas as pd 11 | import requests 12 | 13 | 14 | def option_current_em() -> pd.DataFrame: 15 | """ 16 | 东方财富-期权价格 17 | http://quote.eastmoney.com/center 18 | :return: 期权价格 19 | :rtype: pandas.DataFrame 20 | """ 21 | url = 'http://23.push2.eastmoney.com/api/qt/clist/get' 22 | params = { 23 | 'cb': 'jQuery112409395946290628259_1606225274048', 24 | 'pn': '1', 25 | 'pz': '200000', 26 | 'po': '1', 27 | 'np': '1', 28 | 'ut': 'bd1d9ddb04089700cf9c27f6f7426281', 29 | 'fltt': '2', 30 | 'invt': '2', 31 | 'fid': 'f3', 32 | 'fs': 'm:10,m:140,m:141,m:151', 33 | 'fields': 'f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f22,f28,f11,f62,f128,f136,f115,f152,f133,f108,f163,f161,f162', 34 | '_': '1606225274063', 35 | } 36 | r = requests.get(url, params=params) 37 | data_text = r.text 38 | data_json = json.loads(data_text[data_text.find('{'):-2]) 39 | temp_df = pd.DataFrame(data_json['data']['diff']) 40 | temp_df.columns = [ 41 | '_', 42 | '最新价', 43 | '涨跌幅', 44 | '涨跌额', 45 | '成交量', 46 | '成交额', 47 | '_', 48 | '_', 49 | '_', 50 | '_', 51 | '_', 52 | '代码', 53 | '_', 54 | '名称', 55 | '_', 56 | '_', 57 | '今开', 58 | '_', 59 | '_', 60 | '_', 61 | '_', 62 | '_', 63 | '_', 64 | '_', 65 | '昨结', 66 | '_', 67 | '持仓量', 68 | '_', 69 | '_', 70 | '_', 71 | '_', 72 | '_', 73 | '_', 74 | '_', 75 | '行权价', 76 | '剩余日', 77 | '日增' 78 | ] 79 | temp_df = temp_df[[ 80 | '代码', 81 | '名称', 82 | '最新价', 83 | '涨跌额', 84 | '涨跌幅', 85 | '成交量', 86 | '成交额', 87 | '持仓量', 88 | '行权价', 89 | '剩余日', 90 | '日增', 91 | '昨结', 92 | '今开' 93 | ]] 94 | return temp_df 95 | 96 | 97 | if __name__ == '__main__': 98 | option_daily_hist_em_df = option_current_em() 99 | print(option_daily_hist_em_df) 100 | -------------------------------------------------------------------------------- /akshare/stock_feature/stock_em_account.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2019/12/27 18:02 5 | Desc: 东方财富网-数据中心-特色数据-股票账户统计 6 | 东方财富网-数据中心-特色数据-股票账户统计: 股票账户统计详细数据 7 | http://data.eastmoney.com/cjsj/gpkhsj.html 8 | """ 9 | import demjson 10 | import pandas as pd 11 | import requests 12 | from tqdm import tqdm 13 | 14 | 15 | def _get_page_num_account() -> int: 16 | """ 17 | 东方财富网-数据中心-特色数据-股票账户统计 18 | http://data.eastmoney.com/cjsj/gpkhsj.html 19 | :return: 股票账户统计的总页数 20 | :rtype: int 21 | """ 22 | url = "http://dcfm.eastmoney.com/EM_MutiSvcExpandInterface/api/js/get" 23 | params = { 24 | "type": "GPKHData", 25 | "token": "894050c76af8597a853f5b408b759f5d", 26 | "st": "SDATE", 27 | "sr": "-1", 28 | "p": "1", 29 | "ps": "50", 30 | "js": "var CMvgBzme={pages:(tp),data:(x)}", 31 | "rt": "52589731", 32 | } 33 | r = requests.get(url, params=params) 34 | data_text = r.text 35 | data_json = demjson.decode(data_text[data_text.find("={") + 1:]) 36 | return data_json["pages"] 37 | 38 | 39 | def stock_em_account() -> pd.DataFrame: 40 | """ 41 | 东方财富网-数据中心-特色数据-股票账户统计 42 | http://data.eastmoney.com/cjsj/gpkhsj.html 43 | :return: 股票账户统计数据 44 | :rtype: pandas.DataFrame 45 | """ 46 | url = "http://dcfm.eastmoney.com/EM_MutiSvcExpandInterface/api/js/get" 47 | page_num = _get_page_num_account() 48 | temp_df = pd.DataFrame() 49 | for page in tqdm(range(1, page_num + 1)): 50 | params = { 51 | "type": "GPKHData", 52 | "token": "894050c76af8597a853f5b408b759f5d", 53 | "st": "SDATE", 54 | "sr": "-1", 55 | "p": str(page), 56 | "ps": "50", 57 | "js": "var CMvgBzme={pages:(tp),data:(x)}", 58 | "rt": "52589731", 59 | } 60 | res = requests.get(url, params=params) 61 | data_text = res.text 62 | data_json = demjson.decode(data_text[data_text.find("={") + 1:]) 63 | temp_df = temp_df.append(pd.DataFrame(data_json["data"]), ignore_index=True) 64 | temp_df.columns = [ 65 | "数据日期", 66 | "新增投资者-数量", 67 | "新增投资者-环比", 68 | "新增投资者-同比", 69 | "期末投资者-总量", 70 | "期末投资者-A股账户", 71 | "期末投资者-B股账户", 72 | "上证指数-收盘", 73 | "上证指数-涨跌幅", 74 | "沪深总市值", 75 | "沪深户均市值", 76 | ] 77 | return temp_df 78 | 79 | 80 | if __name__ == "__main__": 81 | stock_em_account_df = stock_em_account() 82 | print(stock_em_account_df) 83 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2021/5/7 16:58 5 | Desc: AkShare's pypi info file 6 | """ 7 | import re 8 | import ast 9 | 10 | import setuptools 11 | 12 | with open("README.md", "r", encoding="utf-8") as f: 13 | long_description = f.read() 14 | 15 | 16 | def get_version_string(): 17 | """ 18 | Get the akshare version number 19 | :return: version number 20 | :rtype: str, e.g. '0.6.24' 21 | """ 22 | with open("akshare/__init__.py", "rb") as _f: 23 | version_line = re.search( 24 | r"__version__\s+=\s+(.*)", _f.read().decode("utf-8") 25 | ).group(1) 26 | return str(ast.literal_eval(version_line)) 27 | 28 | 29 | setuptools.setup( 30 | name="akshare", 31 | version=get_version_string(), 32 | author="Albert King", 33 | author_email="jindaxiang@163.com", 34 | license="MIT", 35 | description="AkShare is an elegant and simple financial data interface library for Python, built for human beings!", 36 | long_description=long_description, 37 | long_description_content_type="text/markdown", 38 | url="https://github.com/jindaxiang/akshare", 39 | packages=setuptools.find_packages(), 40 | install_requires=[ 41 | "beautifulsoup4>=4.9.1", 42 | "lxml>=4.2.1", 43 | "matplotlib>=3.1.1", 44 | "numpy>=1.15.4", 45 | "pandas>=0.25", 46 | "requests>=2.22.0", 47 | "demjson>=2.2.4", 48 | "pillow>=6.2.0", 49 | "pypinyin>=0.35.0", 50 | "websocket-client>=0.56.0", 51 | "html5lib>=1.0.1", 52 | "xlrd==1.2.0", 53 | "tqdm>=4.43.0", 54 | "openpyxl>=3.0.3", 55 | "jsonpath>=0.82", 56 | "tabulate>=0.8.6", 57 | "decorator>=4.4.2", 58 | "py_mini_racer>=0.4.0", 59 | ], 60 | package_data={"": ["*.py", "*.json", "*.pk", "*.js"]}, 61 | keywords=[ 62 | "stock", 63 | "option", 64 | "futures", 65 | "fund", 66 | "bond", 67 | "index", 68 | "air", 69 | "finance", 70 | "spider", 71 | "quant", 72 | "quantitative", 73 | "investment", 74 | "trading", 75 | "algotrading", 76 | "data", 77 | ], 78 | classifiers=[ 79 | "Programming Language :: Python :: 3.7", 80 | "Programming Language :: Python :: 3.8", 81 | "Programming Language :: Python :: 3.9", 82 | "License :: OSI Approved :: MIT License", 83 | "Operating System :: OS Independent", 84 | ], 85 | python_requires=">=3.7", 86 | ) 87 | -------------------------------------------------------------------------------- /akshare/futures/futures_cfmmc.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2021/5/1 16:37 5 | Desc: 中国期货市场监控中心-指数 6 | http://index.cfmmc.com/index/views/index.html 7 | 该数据由中国期货市场监控中心转移到中证商品指数有限责任公司进行管理 8 | 中证商品指数有限责任公司:http://www.cscidx.com/index.html 9 | 截止目前该网站还未更新指数上线 10 | # TODO 等待更新 11 | """ 12 | from io import BytesIO 13 | 14 | import pandas as pd 15 | import requests 16 | from bs4 import BeautifulSoup 17 | 18 | 19 | def futures_index_dict() -> dict: 20 | """ 21 | name and code map 22 | :return: name to code 23 | :rtype: dict 24 | """ 25 | url = "http://index.cfmmc.com/index/views/index.html" 26 | r = requests.get(url) 27 | soup = BeautifulSoup(r.text, "lxml") 28 | name_list = [ 29 | item.text.strip() 30 | for item in soup.find(attrs={"class": "down_box"}).find_all("b")[1:] 31 | ] 32 | code_list = [ 33 | item["indexcode"] 34 | for item in soup.find(attrs={"class": "down_box"}).find_all("b")[1:] 35 | ] 36 | return dict(zip(name_list, code_list)) 37 | 38 | 39 | def futures_index_cfmmc( 40 | index_name: str = "商品综合指数", 41 | start_date: str = "2010-01-01", 42 | end_date: str = "2020-04-06", 43 | ) -> pd.DataFrame: 44 | """ 45 | 中国期货市场监控中心-各类指数数据 46 | http://index.cfmmc.com/index/views/index.html 47 | :param index_name: 指数名称 大类 {"商品期货指数", "农产品期货指数", "商品期货指数", "工业品期货指数", "商品综合指数"}, refer futures_index_dict 48 | :type index_name: str 49 | :param start_date: default "2010-01-01" 50 | :type start_date: str 51 | :param end_date: default "2020-04-06" 52 | :type end_date: str 53 | :return: index data frame 54 | :rtype: pandas.DataFrame 55 | """ 56 | futures_index_map = futures_index_dict() 57 | url = "http://index.cfmmc.com/servlet/indexAction" 58 | params = { 59 | "function": "DowladIndex", 60 | "start": start_date, 61 | "end": end_date, 62 | "code": futures_index_map[index_name], 63 | "codeName": index_name, 64 | } 65 | r = requests.get(url, params=params) 66 | temp_df = pd.read_excel(BytesIO(r.content)) 67 | return temp_df 68 | 69 | 70 | if __name__ == "__main__": 71 | futures_index_dict_temp = futures_index_dict() 72 | futures_index_df = pd.DataFrame.from_dict( 73 | futures_index_dict_temp, orient="index", columns=["index_code"] 74 | ) 75 | print(futures_index_df) 76 | futures_index_cfmmc_df = futures_index_cfmmc( 77 | index_name="林木综合指数", start_date="2010-01-01", end_date="2020-12-30" 78 | ) 79 | print(futures_index_cfmmc_df) 80 | -------------------------------------------------------------------------------- /akshare/bond/bond_china_money.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/10/7 22:43 5 | Desc: 收盘收益率曲线历史数据 6 | http://www.chinamoney.com.cn/chinese/bkcurvclosedyhis/?bondType=CYCC000&reference=1 7 | """ 8 | import pandas as pd 9 | import requests 10 | 11 | 12 | def bond_china_close_return_map() -> pd.DataFrame: 13 | """ 14 | 收盘收益率曲线历史数据 15 | http://www.chinamoney.com.cn/chinese/bkcurvclosedyhis/?bondType=CYCC000&reference=1 16 | :return: 收盘收益率曲线历史数据 17 | :rtype: pandas.DataFrame 18 | """ 19 | url = "http://www.chinamoney.com.cn/ags/ms/cm-u-bk-currency/ClsYldCurvCurvGO" 20 | r = requests.post(url) 21 | data_json = r.json() 22 | temp_df = pd.DataFrame(data_json["records"]) 23 | return temp_df 24 | 25 | 26 | def bond_china_close_return( 27 | symbol: str = "政策性金融债(进出口行)", 28 | start_date: str = "2020-08-30", 29 | end_date: str = "2020-09-30", 30 | ) -> pd.DataFrame: 31 | """ 32 | 收盘收益率曲线历史数据 33 | http://www.chinamoney.com.cn/chinese/bkcurvclosedyhis/?bondType=CYCC000&reference=1 34 | :param symbol: 需要获取的指标 35 | :type symbol: str 36 | :param start_date: 开始日期, 结束日期和开始日期不要超过 1 个月 37 | :type start_date: str 38 | :param end_date: 结束日期, 结束日期和开始日期不要超过 1 个月 39 | :type end_date: str 40 | :return: 收盘收益率曲线历史数据 41 | :rtype: pandas.DataFrame 42 | """ 43 | name_code_df = bond_china_close_return_map() 44 | symbol_code = name_code_df[name_code_df["cnLabel"] == symbol]["value"].values[0] 45 | url = "http://www.chinamoney.com.cn/ags/ms/cm-u-bk-currency/ClsYldCurvHis" 46 | params = { 47 | "lang": "CN", 48 | "reference": "1", 49 | "bondType": symbol_code, 50 | "startDate": start_date, 51 | "endDate": end_date, 52 | "termId": "0.5", 53 | "pageNum": "1", 54 | "pageSize": "5000", 55 | } 56 | r = requests.post(url, params=params) 57 | data_json = r.json() 58 | temp_df = pd.DataFrame(data_json["records"]) 59 | del temp_df["newDateValue"] 60 | temp_df.columns = [ 61 | "到期收益率", 62 | "远期收益率", 63 | "日期", 64 | "期限", 65 | "即期收益率", 66 | ] 67 | temp_df = temp_df[ 68 | [ 69 | "日期", 70 | "期限", 71 | "到期收益率", 72 | "即期收益率", 73 | "远期收益率", 74 | ] 75 | ] 76 | return temp_df 77 | 78 | 79 | if __name__ == "__main__": 80 | bond_china_close_return_df = bond_china_close_return( 81 | symbol="政策性金融债(进出口行)", start_date="2020-08-30", end_date="2020-09-30" 82 | ) 83 | print(bond_china_close_return_df) 84 | -------------------------------------------------------------------------------- /akshare/fortune/cons.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2019/12/10 22:22 5 | Desc: fortune 配置文件 6 | """ 7 | # it-juzi 8 | it_headers = { 9 | "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36", 10 | } 11 | it_url = "https://jfds-1252952517.cos.ap-chengdu.myqcloud.com/akshare/data/data_juzi/juzi.csv" 12 | 13 | # fortune 14 | url_2020 = "http://www.fortunechina.com/fortune500/c/2020-08/10/content_372148.htm" 15 | url_2019 = "http://www.fortunechina.com/fortune500/c/2019-07/22/content_339535.htm" 16 | url_2018 = "http://www.fortunechina.com/fortune500/c/2018-07/19/content_311046.htm" 17 | url_2017 = "http://www.fortunechina.com/fortune500/c/2017-07/20/content_286785.htm" 18 | url_2016 = "http://www.fortunechina.com/fortune500/c/2016-07/20/content_266955.htm" 19 | url_2015 = "http://www.fortunechina.com/fortune500/c/2015-07/22/content_244435.htm" 20 | url_2014 = "http://www.fortunechina.com/fortune500/c/2014-07/07/content_212535.htm" 21 | url_2013 = "http://www.fortunechina.com/fortune500/c/2013-07/08/content_164375.htm" # 分 5 页 22 | url_2012 = "http://www.fortunechina.com/fortune500/c/2012-07/09/content_106535.htm" # 分 5 页 23 | url_2011 = "http://www.fortunechina.com/fortune500/c/2011-07/07/content_62335.htm" # 分 5 页 24 | url_2010 = "http://www.fortunechina.com/fortune500/c/2010-07/09/content_38195.htm" # 分 5 页 25 | url_2009 = "http://www.fortunechina.com/fortune500/c/2009-07/08/content_21391.htm" # 分 10 页 26 | url_2008 = "http://www.fortunechina.com/fortune500/c/2008-10/15/content_12413.htm" # 分 10 页 27 | url_2007 = "http://www.fortunechina.com/fortune500/c/2007-10/15/content_9517.htm" # 分 10 页 28 | url_2006 = "http://www.fortunechina.com/fortune500/c/2006-10/01/content_9539.htm" 29 | url_2005 = "http://www.fortunechina.com/fortune500/c/2005-10/01/content_9561.htm" 30 | url_2004 = "http://www.fortunechina.com/fortune500/c/2004-10/01/content_9581.htm" 31 | url_2003 = "http://www.fortunechina.com/fortune500/c/2003-10/01/content_9595.htm" 32 | url_2002 = "http://www.fortunechina.com/fortune500/c/2002-10/01/content_9605.htm" 33 | url_2001 = "http://www.fortunechina.com/fortune500/c/2001-11/01/content_9614.htm" 34 | url_2000 = "http://www.fortunechina.com/fortune500/c/2000-12/01/content_9624.htm" 35 | url_1999 = "http://www.fortunechina.com/fortune500/c/1999-10/01/content_9626.htm" 36 | url_1998 = "http://www.fortunechina.com/fortune500/c/1998-10/11/content_9640.htm" 37 | url_1997 = "http://www.fortunechina.com/fortune500/c/1997-11/12/content_9657.htm" 38 | url_1996 = "http://www.fortunechina.com/fortune500/c/1996-11/01/content_9659.htm" 39 | -------------------------------------------------------------------------------- /akshare/futures_derivative/nh_index_return.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/10/14 16:52 5 | Desc: 南华期货-商品指数历史走势-收益率指数-数值-http://www.nanhua.net/nhzc/varietytrend.html 6 | 1000 点开始, 用收益率累计 7 | 目标地址: http://www.nanhua.net/ianalysis/varietyindex/index/NHCI.json?t=1574932290494 8 | """ 9 | import time 10 | 11 | import requests 12 | import pandas as pd 13 | 14 | 15 | def num_to_str_data(str_date: int) -> str: 16 | """ 17 | num to str format 18 | :param str_date: time of int format 19 | :type str_date: int 20 | :return: format time 21 | :rtype: str 22 | """ 23 | str_date = str_date / 1000 24 | str_date = time.localtime(str_date) 25 | strp_time = time.strftime("%Y-%m-%d %H:%M:%S", str_date) 26 | return strp_time 27 | 28 | 29 | def get_nh_list_table() -> pd.DataFrame: 30 | """ 31 | 南华期货-南华指数所有品种一览表 32 | :return: 所有品种一览表 33 | :rtype: pandas.DataFrame 34 | """ 35 | url_name = "http://www.nanhua.net/ianalysis/plate-variety.json" 36 | res = requests.get(url_name) 37 | futures_name = [item["name"] for item in res.json()] 38 | futures_code = [item["code"] for item in res.json()] 39 | futures_exchange = [item["exchange"] for item in res.json()] 40 | futures_first_day = [item["firstday"] for item in res.json()] 41 | futures_index_cat = [item["indexcategory"] for item in res.json()] 42 | futures_df = pd.DataFrame( 43 | [ 44 | futures_code, 45 | futures_exchange, 46 | futures_first_day, 47 | futures_index_cat, 48 | futures_name, 49 | ] 50 | ).T 51 | futures_df.columns = ["code", "exchange", "start_date", "category", "name"] 52 | return futures_df 53 | 54 | 55 | def nh_return_index(code: str = "Y") -> pd.DataFrame: 56 | """ 57 | 南华期货-南华指数单品种所有历史数据 58 | :param code: str 通过 get_nh_list 提供 59 | :return: pandas.Series 60 | """ 61 | if code in get_nh_list_table()["code"].tolist(): 62 | t = time.time() 63 | base_url = f"http://www.nanhua.net/ianalysis/varietyindex/index/{code}.json?t={int(round(t * 1000))}" 64 | r = requests.get(base_url) 65 | date = [num_to_str_data(item[0]).split(" ")[0] for item in r.json()] 66 | data = [item[1] for item in r.json()] 67 | df_all = pd.DataFrame([date, data]).T 68 | df_all.columns = ["date", "value"] 69 | df_all.index = pd.to_datetime(df_all["date"]) 70 | del df_all["date"] 71 | return df_all 72 | 73 | 74 | if __name__ == "__main__": 75 | nh_return_index_df = nh_return_index() 76 | print(nh_return_index_df) 77 | -------------------------------------------------------------------------------- /akshare/bond/bond_em.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2021/3/15 14:58 5 | Desc: 东方财富网-数据中心-经济数据-中美国债收益率 6 | http://data.eastmoney.com/cjsj/zmgzsyl.html 7 | """ 8 | import pandas as pd 9 | import requests 10 | from tqdm import tqdm 11 | 12 | 13 | def bond_zh_us_rate(): 14 | """ 15 | 东方财富网-数据中心-经济数据-中美国债收益率 16 | http://data.eastmoney.com/cjsj/zmgzsyl.html 17 | :return: 中美国债收益率 18 | :rtype: pandas.DataFrame 19 | """ 20 | url = 'http://datacenter.eastmoney.com/api/data/get' 21 | params = { 22 | 'type': 'RPTA_WEB_TREASURYYIELD', 23 | 'sty': 'ALL', 24 | 'st': 'SOLAR_DATE', 25 | 'sr': '-1', 26 | 'token': '894050c76af8597a853f5b408b759f5d', 27 | 'p': '1', 28 | 'ps': '500', 29 | 'pageNo': '1', 30 | 'pageNum': '1', 31 | '_': '1615791534490', 32 | } 33 | r = requests.get(url, params=params) 34 | data_json = r.json() 35 | total_page = data_json['result']['pages'] 36 | big_df = pd.DataFrame() 37 | for page in tqdm(range(1, total_page+1)): 38 | params = { 39 | 'type': 'RPTA_WEB_TREASURYYIELD', 40 | 'sty': 'ALL', 41 | 'st': 'SOLAR_DATE', 42 | 'sr': '-1', 43 | 'token': '894050c76af8597a853f5b408b759f5d', 44 | 'p': page, 45 | 'ps': '500', 46 | 'pageNo': page, 47 | 'pageNum': page, 48 | '_': '1615791534490', 49 | } 50 | r = requests.get(url, params=params) 51 | data_json = r.json() 52 | temp_df = pd.DataFrame(data_json['result']['data']) 53 | big_df = big_df.append(temp_df, ignore_index=True) 54 | big_df.columns = [ 55 | '日期', 56 | '中国国债收益率2年', 57 | '中国国债收益率5年', 58 | '中国国债收益率10年', 59 | '中国国债收益率30年', 60 | '中国国债收益率10年-2年', 61 | '美国国债收益率2年', 62 | '美国国债收益率5年', 63 | '美国国债收益率10年', 64 | '美国国债收益率30年', 65 | '美国国债收益率10年-2年', 66 | '中国GDP年增率', 67 | '美国GDP年增率', 68 | ] 69 | big_df = big_df[[ 70 | '日期', 71 | '中国国债收益率2年', 72 | '中国国债收益率5年', 73 | '中国国债收益率10年', 74 | '中国国债收益率30年', 75 | '中国国债收益率10年-2年', 76 | '中国GDP年增率', 77 | '美国国债收益率2年', 78 | '美国国债收益率5年', 79 | '美国国债收益率10年', 80 | '美国国债收益率30年', 81 | '美国国债收益率10年-2年', 82 | '美国GDP年增率', 83 | ]] 84 | big_df['日期'] = pd.to_datetime(big_df['日期']).dt.date.astype(str) 85 | return big_df 86 | 87 | 88 | if __name__ == '__main__': 89 | bond_zh_us_rate_df = bond_zh_us_rate() 90 | print(bond_zh_us_rate_df) 91 | -------------------------------------------------------------------------------- /akshare/fund/fund_manager.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2021/3/8 16:30 5 | Desc: 基金经理大全 6 | http://fund.eastmoney.com/manager/default.html 7 | """ 8 | import demjson 9 | import pandas as pd 10 | import requests 11 | from tqdm import tqdm 12 | 13 | 14 | def fund_manager() -> pd.DataFrame: 15 | """ 16 | 天天基金网-基金数据-基金经理大全 17 | http://fund.eastmoney.com/manager/default.html 18 | :return: 基金经理大全 19 | :rtype: pandas.DataFrame 20 | """ 21 | big_df = pd.DataFrame() 22 | url = "http://fund.eastmoney.com/Data/FundDataPortfolio_Interface.aspx" 23 | params = { 24 | "dt": "14", 25 | "mc": "returnjson", 26 | "ft": "all", 27 | "pn": "50", 28 | "pi": "1", 29 | "sc": "abbname", 30 | "st": "asc", 31 | } 32 | r = requests.get(url, params=params) 33 | data_text = r.text 34 | data_json = demjson.decode(data_text.strip("var returnjson= ")) 35 | total_page = data_json["pages"] 36 | for page in tqdm(range(1, total_page + 1)): 37 | url = "http://fund.eastmoney.com/Data/FundDataPortfolio_Interface.aspx" 38 | params = { 39 | "dt": "14", 40 | "mc": "returnjson", 41 | "ft": "all", 42 | "pn": "50", 43 | "pi": str(page), 44 | "sc": "abbname", 45 | "st": "asc", 46 | } 47 | r = requests.get(url, params=params) 48 | data_text = r.text 49 | data_json = demjson.decode(data_text.strip("var returnjson= ")) 50 | temp_df = pd.DataFrame(data_json["data"]) 51 | temp_df.reset_index(inplace=True) 52 | temp_df["index"] = range(1, len(temp_df) + 1) 53 | temp_df.columns = [ 54 | "序号", 55 | "_", 56 | "姓名", 57 | "_", 58 | "所属公司", 59 | "_", 60 | "现任基金", 61 | "累计从业时间", 62 | "现任基金最佳回报", 63 | "_", 64 | "_", 65 | "现任基金资产总规模", 66 | "_", 67 | ] 68 | temp_df = temp_df[ 69 | [ 70 | "序号", 71 | "姓名", 72 | "所属公司", 73 | "现任基金", 74 | "累计从业时间", 75 | "现任基金最佳回报", 76 | "现任基金资产总规模", 77 | ] 78 | ] 79 | big_df = big_df.append(temp_df, ignore_index=True) 80 | big_df["现任基金最佳回报"] = big_df["现任基金最佳回报"].str.split("%", expand=True).iloc[:, 0] 81 | big_df["现任基金资产总规模"] = big_df["现任基金资产总规模"].str.split("亿元", expand=True).iloc[:, 0] 82 | return big_df 83 | 84 | 85 | if __name__ == "__main__": 86 | fund_manager_df = fund_manager() 87 | print(fund_manager_df) 88 | -------------------------------------------------------------------------------- /akshare/index/index_weibo.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2019/12/2 22:24 5 | Desc: 获取微博指数 6 | """ 7 | import re 8 | import datetime 9 | 10 | import pandas as pd 11 | import requests 12 | import matplotlib.pyplot as plt 13 | 14 | from akshare.index.cons import index_weibo_headers # 伪装游览器, 必备 15 | 16 | plt.rcParams["font.sans-serif"] = ["SimHei"] # 显示中文标签 17 | 18 | 19 | def _get_items(word="股票"): 20 | url = "https://data.weibo.com/index/ajax/newindex/searchword" 21 | payload = {"word": word} 22 | res = requests.post(url, data=payload, headers=index_weibo_headers) 23 | return {word: re.findall(r"\d+", res.json()["html"])[0]} 24 | 25 | 26 | def _get_index_data(wid, time_type): 27 | url = "http://data.weibo.com/index/ajax/newindex/getchartdata" 28 | data = { 29 | "wid": wid, 30 | "dateGroup": time_type, 31 | } 32 | res = requests.get(url, params=data, headers=index_weibo_headers) 33 | json_df = res.json() 34 | data = { 35 | "index": json_df["data"][0]["trend"]["x"], 36 | "value": json_df["data"][0]["trend"]["s"], 37 | } 38 | df = pd.DataFrame(data) 39 | return df 40 | 41 | 42 | def _process_index(index): 43 | now = datetime.datetime.now() 44 | curr_year = now.year 45 | curr_date = "%04d%02d%02d" % (now.year, now.month, now.day) 46 | if "月" in index: 47 | tmp = index.replace("日", "").split("月") 48 | date = "%04d%02d%02d" % (curr_year, int(tmp[0]), int(tmp[1])) 49 | if date > curr_date: 50 | date = "%04d%02d%02d" % (curr_year - 1, int(tmp[0]), int(tmp[1])) 51 | return date 52 | return index 53 | 54 | 55 | def weibo_index(word="python", time_type="3month"): 56 | """ 57 | :param word: str 58 | :param time_type: str 1hour, 1day, 1month, 3month 59 | :return: 60 | """ 61 | dict_keyword = _get_items(word) 62 | df_list = [] 63 | for keyword, wid in dict_keyword.items(): 64 | df = _get_index_data(wid, time_type) 65 | if df is not None: 66 | df.columns = ["index", keyword] 67 | df["index"] = df["index"].apply(lambda x: _process_index(x)) 68 | df.set_index("index", inplace=True) 69 | df_list.append(df) 70 | if len(df_list) > 0: 71 | df = pd.concat(df_list, axis=1) 72 | if time_type == "1hour" or "1day": 73 | df.index = pd.to_datetime(df.index) 74 | else: 75 | df.index = pd.to_datetime(df.index, format="%Y%m%d") 76 | return df 77 | 78 | 79 | if __name__ == "__main__": 80 | df_index = weibo_index(word="口罩", time_type="1hour") 81 | print(df_index) 82 | df_index.plot() 83 | plt.show() 84 | -------------------------------------------------------------------------------- /akshare/futures/requests_fun.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/5/7 13:58 5 | Desc: 请求网站内容的函数: 在链接失败后可重复 20 次 6 | """ 7 | import time 8 | from typing import Dict 9 | 10 | import pandas as pd 11 | import requests 12 | 13 | 14 | def requests_link(url: str, encoding: str = "utf-8", method: str = "get", data: Dict = None, headers: Dict = None): 15 | """ 16 | 利用 requests 请求网站, 爬取网站内容, 如网站链接失败, 可重复爬取 20 次 17 | :param url: string 网站地址 18 | :param encoding: string 编码类型: "utf-8", "gbk", "gb2312" 19 | :param method: string 访问方法: "get", "post" 20 | :param data: dict 上传数据: 键值对 21 | :param headers: dict 游览器请求头: 键值对 22 | :return: requests.response 爬取返回内容: response 23 | """ 24 | i = 0 25 | while True: 26 | try: 27 | if method == "get": 28 | r = requests.get(url, timeout=20) 29 | r.encoding = encoding 30 | return r 31 | elif method == "post": 32 | r = requests.post(url, timeout=20, data=data, headers=headers) 33 | r.encoding = encoding 34 | return r 35 | else: 36 | raise ValueError("请提供正确的请求方式") 37 | except: 38 | i += 1 39 | print(f"第{str(i)}次链接失败, 最多尝试 20 次") 40 | time.sleep(5) 41 | if i > 20: 42 | return None 43 | 44 | 45 | def pandas_read_html_link(url: str, encoding: str = "utf-8", method: str = "get", data: Dict = None, headers: Dict = None): 46 | """ 47 | 利用 pandas 提供的 read_html 函数来直接提取网页中的表格内容, 如网站链接失败, 可重复爬取 20 次 48 | :param url: string 网站地址 49 | :param encoding: string 编码类型: "utf-8", "gbk", "gb2312" 50 | :param method: string 访问方法: "get", "post" 51 | :param data: dict 上传数据: 键值对 52 | :param headers: dict 游览器请求头: 键值对 53 | :return: requests.response 爬取返回内容: response 54 | """ 55 | i = 0 56 | while True: 57 | try: 58 | if method == "get": 59 | r = requests.get(url, timeout=20) 60 | r.encoding = encoding 61 | r = pd.read_html(r.text, encoding=encoding) 62 | return r 63 | elif method == "post": 64 | r = requests.post(url, timeout=20, data=data, headers=headers) 65 | r.encoding = encoding 66 | r = pd.read_html(r.text, encoding=encoding) 67 | return r 68 | else: 69 | raise ValueError("请提供正确的请求方式") 70 | except requests.exceptions.Timeout as e: 71 | i += 1 72 | print(f"第{str(i)}次链接失败, 最多尝试20次", e) 73 | time.sleep(5) 74 | if i > 20: 75 | return None 76 | -------------------------------------------------------------------------------- /akshare/news/stock_news.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2021/1/15 16:59 5 | Desc: 个股新闻数据 6 | http://so.eastmoney.com/news/s?keyword=%E4%B8%AD%E5%9B%BD%E4%BA%BA%E5%AF%BF&pageindex=1&searchrange=8192&sortfiled=4 7 | """ 8 | import pandas as pd 9 | import requests 10 | 11 | 12 | def stock_news_em(stock: str = "601628") -> pd.DataFrame: 13 | """ 14 | 东方财富-个股新闻-最近 20 条新闻 15 | http://so.eastmoney.com/news/s?keyword=%E4%B8%AD%E5%9B%BD%E4%BA%BA%E5%AF%BF&pageindex=1&searchrange=8192&sortfiled=4 16 | :param stock: 股票代码 17 | :type stock: str 18 | :return: 个股新闻 19 | :rtype: pandas.DataFrame 20 | """ 21 | url = "http://searchapi.eastmoney.com//bussiness/Web/GetCMSSearchList" 22 | params = { 23 | "type": "8196", 24 | "pageindex": "1", 25 | "pagesize": "20", 26 | "keyword": f"({stock})()", 27 | "name": "zixun", 28 | "_": "1608800267874", 29 | } 30 | headers = { 31 | "Accept": "*/*", 32 | "Accept-Encoding": "gzip, deflate", 33 | "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8", 34 | "Cache-Control": "no-cache", 35 | "Connection": "keep-alive", 36 | "Host": "searchapi.eastmoney.com", 37 | "Pragma": "no-cache", 38 | "Referer": "http://so.eastmoney.com/", 39 | "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36", 40 | } 41 | 42 | r = requests.get(url, params=params, headers=headers) 43 | data_json = r.json() 44 | temp_df = pd.DataFrame(data_json["Data"]) 45 | temp_df.columns = [ 46 | "url", 47 | "title", 48 | "_", 49 | "public_time", 50 | "content", 51 | ] 52 | temp_df['code'] = stock 53 | temp_df = temp_df[ 54 | [ 55 | "code", 56 | "title", 57 | "content", 58 | "public_time", 59 | "url", 60 | ] 61 | ] 62 | temp_df["title"] = ( 63 | temp_df["title"].str.replace(r"\(", "", regex=True).str.replace(r"\)", "", regex=True) 64 | ) 65 | temp_df["content"] = ( 66 | temp_df["content"].str.replace(r"\(", "", regex=True).str.replace(r"\)", "", regex=True) 67 | ) 68 | temp_df["content"] = ( 69 | temp_df["content"].str.replace(r"", "", regex=True).str.replace(r"", "", regex=True) 70 | ) 71 | temp_df["content"] = temp_df["content"].str.replace(r"\u3000", "", regex=True) 72 | temp_df["content"] = temp_df["content"].str.replace(r"\r\n", " ", regex=True) 73 | return temp_df 74 | 75 | 76 | if __name__ == "__main__": 77 | stock_news_em_df = stock_news_em(stock="601318") 78 | print(stock_news_em_df) 79 | -------------------------------------------------------------------------------- /akshare/stock/zh_stock_kcb_report.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/11/22 19:00 5 | Desc: 科创板报告 6 | http://data.eastmoney.com/notices/kcb.html 7 | """ 8 | import json 9 | 10 | import pandas as pd 11 | import requests 12 | from tqdm import tqdm 13 | 14 | 15 | def _zh_stock_kcb_report_page() -> int: 16 | """ 17 | 科创板报告的页数 18 | http://data.eastmoney.com/notices/kcb.html 19 | :return: 科创板报告的页数 20 | :rtype: int 21 | """ 22 | url = "http://data.eastmoney.com/notices/getdata.ashx" 23 | params = { 24 | 'StockCode': '', 25 | 'FirstNodeType': '0', 26 | 'CodeType': 'KCB', 27 | 'PageIndex': '1', 28 | 'PageSize': '5000', 29 | 'jsObj': 'vblwauPF', 30 | 'SecNodeType': '0', 31 | 'Time': '', 32 | 'rt': '53534758', 33 | } 34 | r = requests.get(url, params=params) 35 | data_text = r.text 36 | data_json = json.loads(data_text[data_text.find('{'):-1]) 37 | return data_json['pages'] 38 | 39 | 40 | def zh_stock_kcb_report() -> pd.DataFrame: 41 | """ 42 | 科创板报告内容 43 | http://data.eastmoney.com/notices/kcb.html 44 | :return: 科创板报告内容 45 | :rtype: pandas.DataFrame 46 | """ 47 | big_df = pd.DataFrame() 48 | url = "http://data.eastmoney.com/notices/getdata.ashx" 49 | pages = _zh_stock_kcb_report_page() 50 | for i in tqdm(range(1, pages+1)): 51 | params = { 52 | 'StockCode': '', 53 | 'FirstNodeType': '0', 54 | 'CodeType': 'KCB', 55 | 'PageIndex': str(i), 56 | 'PageSize': '5000', 57 | 'jsObj': 'vblwauPF', 58 | 'SecNodeType': '0', 59 | 'Time': '', 60 | 'rt': '53534758', 61 | } 62 | r = requests.get(url, params=params) 63 | data_text = r.text 64 | data_json = json.loads(data_text[data_text.find('{'):-1]) 65 | temp_df = pd.DataFrame([ 66 | [item['codes'][0]['stock_code'] for item in data_json['data']], 67 | [item['codes'][0]['short_name'] for item in data_json['data']], 68 | [item['title'] for item in data_json['data']], 69 | [item['columns'][0]['column_name'] for item in data_json['data']], 70 | [item['notice_date'] for item in data_json['data']], 71 | [item['art_code'] for item in data_json['data']], 72 | ]).T 73 | big_df = big_df.append(temp_df, ignore_index=True) 74 | big_df.columns = [ 75 | '代码', 76 | '名称', 77 | '公告标题', 78 | '公告类型', 79 | '公告日期', 80 | '公告代码', 81 | ] 82 | return big_df 83 | 84 | 85 | if __name__ == '__main__': 86 | zh_stock_kcb_report_df = zh_stock_kcb_report() 87 | print(zh_stock_kcb_report_df) 88 | -------------------------------------------------------------------------------- /akshare/event/franchise.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/9/28 14:51 5 | Desc: 中国-商业特许经营信息管理 6 | http://txjy.syggs.mofcom.gov.cn/ 7 | 需要输入验证码访问 8 | """ 9 | import re 10 | 11 | import pandas as pd 12 | import requests 13 | from bs4 import BeautifulSoup 14 | from tqdm import tqdm 15 | 16 | 17 | def _get_franchise_china_page_num() -> int: 18 | """ 19 | 特许经营总页数 20 | http://txjy.syggs.mofcom.gov.cn/index.do?method=entpsearch 21 | :return: 特许经营总页数 22 | :rtype: int 23 | """ 24 | url = "http://txjy.syggs.mofcom.gov.cn/index.do" 25 | payload = { 26 | "method": "entps", 27 | "province": "", 28 | "city": "", 29 | "cpf.cpage": "1", 30 | "cpf.pagesize": "100", 31 | } 32 | headers = { 33 | "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36", 34 | } 35 | r = requests.get(url, params=payload, headers=headers) 36 | soup = BeautifulSoup(r.text, "lxml") 37 | page_num = re.findall( 38 | re.compile(r"\d+"), 39 | soup.find(attrs={"class": "inner"}).find_all("a")[-1]["href"], 40 | )[0] 41 | return int(page_num) 42 | 43 | 44 | def franchise_china() -> pd.DataFrame: 45 | """ 46 | 中国-商业特许经营信息管理 47 | http://txjy.syggs.mofcom.gov.cn/ 48 | :return: 中国-商业特许经营的所有企业 49 | :rtype: pandas.DataFrame 50 | """ 51 | url = "http://txjy.syggs.mofcom.gov.cn/index.do" 52 | # file_url 历史数据文件, 主要是为了防止重复访问的速度和资源浪费问题 53 | file_url = "https://jfds-1252952517.cos.ap-chengdu.myqcloud.com/akshare/readme/franchise/franchise_china.csv" 54 | outer_df = pd.read_csv(file_url, encoding="gbk", index_col=0) 55 | try: 56 | for page in tqdm(range(1, int(5))): # 这里的 5 是硬编码, 长期后需要更新 file_url 文件 57 | payload = { 58 | "method": "entps", 59 | "province": "", 60 | "city": "", 61 | "cpf.cpage": str(page), 62 | "cpf.pagesize": "100", 63 | } 64 | headers = { 65 | "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36", 66 | } 67 | r = requests.get(url, params=payload, headers=headers) 68 | temp_df = pd.read_html(r.text)[1] 69 | inner_df = temp_df.iloc[:, 0].str.split(" ", expand=True) 70 | inner_df.columns = ["特许人名称", "备案时间", "地址"] 71 | outer_df = outer_df.append(inner_df, ignore_index=True) 72 | except: 73 | pass 74 | outer_df.drop_duplicates(inplace=True) 75 | return outer_df 76 | 77 | 78 | if __name__ == "__main__": 79 | franchise_china_df = franchise_china() 80 | print(franchise_china_df) 81 | -------------------------------------------------------------------------------- /akshare/index/index_kq_ss.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2021/5/8 16:05 5 | Desc: 柯桥时尚指数 6 | http://ss.kqindex.cn:9559/rinder_web_kqsszs/index/index_page.do 7 | """ 8 | import requests 9 | import pandas as pd 10 | 11 | 12 | def index_kq_fashion(symbol: str = "时尚创意指数") -> pd.DataFrame: 13 | """ 14 | 柯桥时尚指数 15 | http://ss.kqindex.cn:9559/rinder_web_kqsszs/index/index_page.do 16 | :param symbol: choice of {'柯桥时尚指数', '时尚创意指数', '时尚设计人才数', '新花型推出数', '创意产品成交数', '创意企业数量', '时尚活跃度指数', '电商运行数', '时尚平台拓展数', '新产品销售额占比', '企业合作占比', '品牌传播费用', '时尚推广度指数', '国际交流合作次数', '企业参展次数', '外商驻点数量变化', '时尚评价指数'} 17 | :type symbol: str 18 | :return: 柯桥时尚指数及其子项数据 19 | :rtype: pandas.DataFrame 20 | """ 21 | url = "http://api.idx365.com/index/project/34/data" 22 | symbol_map = { 23 | "柯桥时尚指数": "root", 24 | "时尚创意指数": "01", 25 | "时尚设计人才数": "0101", 26 | "新花型推出数": "0102", 27 | "创意产品成交数": "0103", 28 | "创意企业数量": "0104", 29 | "时尚活跃度指数": "02", 30 | "电商运行数": "0201", 31 | "时尚平台拓展数": "0201", 32 | "新产品销售额占比": "0201", 33 | "企业合作占比": "0201", 34 | "品牌传播费用": "0201", 35 | "时尚推广度指数": "03", 36 | "国际交流合作次数": "0301", 37 | "企业参展次数": "0302", 38 | "外商驻点数量变化": "0302", 39 | "时尚评价指数": "04", 40 | } 41 | params = {"structCode": symbol_map[symbol]} 42 | r = requests.get(url, params=params) 43 | data_json = r.json() 44 | temp_df = pd.DataFrame(data_json["data"]) 45 | temp_df.rename( 46 | columns={ 47 | "id": "_", 48 | "indexValue": "指数", 49 | "lastValue": "_", 50 | "projId": "_", 51 | "publishTime": "日期", 52 | "sameValue": "_", 53 | "stageId": "_", 54 | "structCode": "_", 55 | "structName": "_", 56 | "version": "_", 57 | }, 58 | inplace=True, 59 | ) 60 | temp_df = temp_df[ 61 | [ 62 | "日期", 63 | "指数", 64 | ] 65 | ] 66 | temp_df["日期"] = pd.to_datetime(temp_df["日期"]).dt.date 67 | temp_df.sort_values("日期", inplace=True) 68 | temp_df["涨跌值"] = temp_df["指数"].diff() 69 | temp_df["涨跌幅"] = temp_df["指数"].pct_change() 70 | temp_df.sort_values("日期", ascending=False, inplace=True) 71 | return temp_df 72 | 73 | 74 | if __name__ == "__main__": 75 | for item in [ 76 | "柯桥时尚指数", 77 | "时尚创意指数", 78 | "时尚设计人才数", 79 | "新花型推出数", 80 | "创意产品成交数", 81 | "创意企业数量", 82 | "时尚活跃度指数", 83 | "电商运行数", 84 | "时尚平台拓展数", 85 | "新产品销售额占比", 86 | "企业合作占比", 87 | "品牌传播费用", 88 | "时尚推广度指数", 89 | "国际交流合作次数", 90 | "企业参展次数", 91 | "外商驻点数量变化", 92 | "时尚评价指数", 93 | ]: 94 | index_kq_fashion_df = index_kq_fashion(symbol=item) 95 | print(index_kq_fashion_df) 96 | -------------------------------------------------------------------------------- /akshare/bond/bond_summary.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2021/1/6 12:55 5 | Desc: 上登债券信息网-债券成交概览 6 | http://bond.sse.com.cn/data/statistics/overview/turnover/ 7 | """ 8 | from io import BytesIO 9 | 10 | import pandas as pd 11 | import requests 12 | 13 | 14 | def bond_cash_summary_sse(date: str = '20210111') -> pd.DataFrame: 15 | """ 16 | 上登债券信息网-市场数据-市场统计-市场概览-债券现券市场概览 17 | http://bond.sse.com.cn/data/statistics/overview/bondow/ 18 | :param date: 指定日期 19 | :type date: str 20 | :return: 债券成交概览 21 | :rtype: pandas.DataFrame 22 | """ 23 | url = 'http://query.sse.com.cn/commonExcelDd.do' 24 | headers = { 25 | 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9', 26 | 'Referer': 'http://bond.sse.com.cn/', 27 | 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36' 28 | } 29 | params = { 30 | 'sqlId': 'COMMON_SSEBOND_SCSJ_SCTJ_SCGL_ZQXQSCGL_CX_L', 31 | 'TRADE_DATE': f'{date[:4]}-{date[4:6]}-{date[6:]}', 32 | } 33 | r = requests.get(url, params=params, headers=headers) 34 | temp_df = pd.read_excel(BytesIO(r.content)) 35 | temp_df.columns = [ 36 | '债券现货', 37 | '托管只数', 38 | '托管市值', 39 | '托管面值', 40 | '数据日期', 41 | ] 42 | return temp_df 43 | 44 | 45 | def bond_deal_summary_sse(date: str = '20210104') -> pd.DataFrame: 46 | """ 47 | 上登债券信息网-市场数据-市场统计-市场概览-债券成交概览 48 | http://bond.sse.com.cn/data/statistics/overview/turnover/ 49 | :param date: 指定日期 50 | :type date: str 51 | :return: 债券成交概览 52 | :rtype: pandas.DataFrame 53 | """ 54 | url = 'http://query.sse.com.cn/commonExcelDd.do' 55 | headers = { 56 | 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9', 57 | 'Referer': 'http://bond.sse.com.cn/', 58 | 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36' 59 | } 60 | params = { 61 | 'sqlId': 'COMMON_SSEBOND_SCSJ_SCTJ_SCGL_ZQCJGL_CX_L', 62 | 'TRADE_DATE': f'{date[:4]}-{date[4:6]}-{date[6:]}', 63 | } 64 | r = requests.get(url, params=params, headers=headers) 65 | temp_df = pd.read_excel(BytesIO(r.content)) 66 | temp_df.columns = [ 67 | '债券类型', 68 | '当日成交笔数', 69 | '当日成交金额', 70 | '当年成交笔数', 71 | '当年成交金额', 72 | '数据日期', 73 | ] 74 | return temp_df 75 | 76 | 77 | if __name__ == '__main__': 78 | bond_cash_summary_sse_df = bond_cash_summary_sse(date='20210111') 79 | print(bond_cash_summary_sse_df) 80 | bond_summary_sse_df = bond_deal_summary_sse(date='20210111') 81 | print(bond_summary_sse_df) 82 | -------------------------------------------------------------------------------- /akshare/stock_feature/stock_em_qsjy.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/7/5 22:49 5 | Desc: 东方财富网-数据中心-特色数据-券商业绩月报 6 | http://data.eastmoney.com/other/qsjy.html 7 | """ 8 | import demjson 9 | import pandas as pd 10 | import requests 11 | 12 | 13 | def stock_em_qsjy(trade_date: str = "2020-01-01") -> pd.DataFrame: 14 | """ 15 | 东方财富网-数据中心-特色数据-券商业绩月报 16 | http://data.eastmoney.com/other/qsjy.html 17 | :param trade_date: 数据月份,从 2010-06-01 开始, e.g., 需要 2011 年 7 月, 则输入 2011-07-01 18 | :type trade_date: str 19 | :return: 券商业绩月报 20 | :rtype: pandas.DataFrame 21 | """ 22 | url = "http://dcfm.eastmoney.com/em_mutisvcexpandinterface/api/js/get" 23 | params = { 24 | "type": "QSYJBG_MReport", 25 | "token": "70f12f2f4f091e459a279469fe49eca5", 26 | "st": "RQ", 27 | "sr": "-1", 28 | "p": "1", 29 | "ps": "1000", 30 | "js": "var KAHXVKzA={pages:(tp),data:(x)}", 31 | "filter": f"(RQ='{trade_date}T00:00:00')", 32 | "rt": "53132017", 33 | } 34 | r = requests.get(url, params=params) 35 | text_data = r.text 36 | data_json = demjson.decode(text_data[text_data.find("{"):]) 37 | temp_df = pd.DataFrame(data_json["data"]) 38 | temp_df["RQ"] = pd.to_datetime(temp_df["RQ"]) 39 | temp_df["ENDATE"] = pd.to_datetime(temp_df["ENDATE"]) 40 | temp_df.columns = ["开始日期", 41 | "结束日期", 42 | "简称", 43 | "代码", 44 | "当月净利润_净利润", 45 | "当月净利润_同比增长", 46 | "当月净利润_环比增长", 47 | "当年累计净利润_累计净利润", 48 | "_", 49 | "当年累计净利润_同比增长", 50 | "当月营业收入_营业收入", 51 | "当月营业收入_环比增长", 52 | "当月营业收入_同比增长", 53 | "当年累计营业收入_累计营业收入", 54 | "_", 55 | "当年累计营业收入_同比增长", 56 | "净资产_净资产", 57 | "_", 58 | "净资产_同比增长", 59 | ] 60 | temp_df = temp_df[["开始日期", 61 | "结束日期", 62 | "简称", 63 | "代码", 64 | "当月净利润_净利润", 65 | "当月净利润_同比增长", 66 | "当月净利润_环比增长", 67 | "当年累计净利润_累计净利润", 68 | "当年累计净利润_同比增长", 69 | "当月营业收入_营业收入", 70 | "当月营业收入_环比增长", 71 | "当月营业收入_同比增长", 72 | "当年累计营业收入_累计营业收入", 73 | "当年累计营业收入_同比增长", 74 | "净资产_净资产", 75 | "净资产_同比增长", 76 | ]] 77 | return temp_df 78 | 79 | 80 | if __name__ == '__main__': 81 | stock_em_qsjy_df = stock_em_qsjy(trade_date="2020-04-01") 82 | print(stock_em_qsjy_df) 83 | -------------------------------------------------------------------------------- /akshare/bond/zh_bond_sina.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/10/19 9:28 5 | Desc: 新浪财经-债券-沪深债券-实时行情数据和历史行情数据 6 | http://vip.stock.finance.sina.com.cn/mkt/#hs_z 7 | """ 8 | import datetime 9 | import re 10 | 11 | import demjson 12 | import pandas as pd 13 | import requests 14 | from py_mini_racer import py_mini_racer 15 | from tqdm import tqdm 16 | 17 | from akshare.bond.cons import ( 18 | zh_sina_bond_hs_count_url, 19 | zh_sina_bond_hs_payload, 20 | zh_sina_bond_hs_url, 21 | zh_sina_bond_hs_hist_url, 22 | ) 23 | from akshare.stock.cons import hk_js_decode 24 | 25 | 26 | def get_zh_bond_hs_page_count() -> int: 27 | """ 28 | 行情中心首页-债券-沪深债券的总页数 29 | http://vip.stock.finance.sina.com.cn/mkt/#hs_z 30 | :return: 总页数 31 | :rtype: int 32 | """ 33 | params = { 34 | "node": "hs_z", 35 | } 36 | res = requests.get(zh_sina_bond_hs_count_url, params=params) 37 | page_count = int(re.findall(re.compile(r"\d+"), res.text)[0]) / 80 38 | if isinstance(page_count, int): 39 | return page_count 40 | else: 41 | return int(page_count) + 1 42 | 43 | 44 | def bond_zh_hs_spot() -> pd.DataFrame: 45 | """ 46 | 新浪财经-债券-沪深债券的实时行情数据, 大量抓取容易封IP 47 | http://vip.stock.finance.sina.com.cn/mkt/#hs_z 48 | :return: 所有沪深债券在当前时刻的实时行情数据 49 | :rtype: pandas.DataFrame 50 | """ 51 | big_df = pd.DataFrame() 52 | page_count = get_zh_bond_hs_page_count() 53 | zh_sina_bond_hs_payload_copy = zh_sina_bond_hs_payload.copy() 54 | for page in tqdm(range(1, page_count + 1)): 55 | zh_sina_bond_hs_payload_copy.update({"page": page}) 56 | res = requests.get(zh_sina_bond_hs_url, params=zh_sina_bond_hs_payload_copy) 57 | data_json = demjson.decode(res.text) 58 | big_df = big_df.append(pd.DataFrame(data_json), ignore_index=True) 59 | return big_df 60 | 61 | 62 | def bond_zh_hs_daily(symbol: str = "sh010107") -> pd.DataFrame: 63 | """ 64 | 新浪财经-债券-沪深债券的的历史行情数据, 大量抓取容易封IP 65 | http://vip.stock.finance.sina.com.cn/mkt/#hs_z 66 | :param symbol: 沪深债券代码; e.g., sh010107 67 | :type symbol: str 68 | :return: 指定沪深债券代码的日 K 线数据 69 | :rtype: pandas.DataFrame 70 | """ 71 | res = requests.get( 72 | zh_sina_bond_hs_hist_url.format( 73 | symbol, datetime.datetime.now().strftime("%Y_%m_%d") 74 | ) 75 | ) 76 | js_code = py_mini_racer.MiniRacer() 77 | js_code.eval(hk_js_decode) 78 | dict_list = js_code.call( 79 | "d", res.text.split("=")[1].split(";")[0].replace('"', "") 80 | ) # 执行js解密代码 81 | data_df = pd.DataFrame(dict_list) 82 | data_df.index = pd.to_datetime(data_df["date"]) 83 | del data_df["date"] 84 | data_df = data_df.astype("float") 85 | return data_df 86 | 87 | 88 | if __name__ == "__main__": 89 | bond_zh_hs_daily_df = bond_zh_hs_daily(symbol="sh010107") 90 | print(bond_zh_hs_daily_df) 91 | bond_zh_hs_spot_df = bond_zh_hs_spot() 92 | print(bond_zh_hs_spot_df) 93 | -------------------------------------------------------------------------------- /akshare/stock_feature/stock_lh_yybpm.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2021/4/19 16:56 5 | Desc: 同花顺-数据中心-营业部排名 6 | http://data.10jqka.com.cn/market/longhu/ 7 | """ 8 | import requests 9 | import pandas as pd 10 | from tqdm import tqdm 11 | 12 | 13 | def stock_lh_yyb_most() -> pd.DataFrame: 14 | """ 15 | 同花顺-数据中心-营业部排名-上榜次数最多 16 | http://data.10jqka.com.cn/market/longhu/ 17 | :return: 上榜次数最多 18 | :rtype: pandas.DataFrame 19 | """ 20 | big_df = pd.DataFrame() 21 | for page in tqdm(range(1, 11)): 22 | headers = { 23 | 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36' 24 | } 25 | url = f'http://data.10jqka.com.cn/ifmarket/lhbyyb/type/1/tab/sbcs/field/sbcs/sort/desc/page/{page}/' 26 | r = requests.get(url, headers=headers) 27 | temp_df = pd.read_html(r.text)[0] 28 | big_df = big_df.append(temp_df) 29 | big_df.reset_index(inplace=True, drop=True) 30 | return big_df 31 | 32 | 33 | def stock_lh_yyb_capital() -> pd.DataFrame: 34 | """ 35 | 同花顺-数据中心-营业部排名-资金实力最强 36 | http://data.10jqka.com.cn/market/longhu/ 37 | :return: 资金实力最强 38 | :rtype: pandas.DataFrame 39 | """ 40 | big_df = pd.DataFrame() 41 | for page in tqdm(range(1, 11)): 42 | headers = { 43 | 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36' 44 | } 45 | url = f'http://data.10jqka.com.cn/ifmarket/lhbyyb/type/1/tab/zjsl/field/zgczje/sort/desc/page/{page}/' 46 | r = requests.get(url, headers=headers) 47 | temp_df = pd.read_html(r.text)[0] 48 | big_df = big_df.append(temp_df) 49 | big_df.reset_index(inplace=True, drop=True) 50 | return big_df 51 | 52 | 53 | def stock_lh_yyb_control() -> pd.DataFrame: 54 | """ 55 | 同花顺-数据中心-营业部排名-抱团操作实力 56 | http://data.10jqka.com.cn/market/longhu/ 57 | :return: 抱团操作实力 58 | :rtype: pandas.DataFrame 59 | """ 60 | big_df = pd.DataFrame() 61 | for page in tqdm(range(1, 11)): 62 | headers = { 63 | 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36' 64 | } 65 | url = f'http://data.10jqka.com.cn/ifmarket/lhbyyb/type/1/tab/btcz/field/xsjs/sort/desc/page/{page}/' 66 | r = requests.get(url, headers=headers) 67 | temp_df = pd.read_html(r.text)[0] 68 | big_df = big_df.append(temp_df) 69 | big_df.reset_index(inplace=True, drop=True) 70 | return big_df 71 | 72 | 73 | if __name__ == '__main__': 74 | stock_lh_yyb_most_df = stock_lh_yyb_most() 75 | print(stock_lh_yyb_most_df) 76 | 77 | stock_lh_yyb_capital_df = stock_lh_yyb_capital() 78 | print(stock_lh_yyb_capital_df) 79 | 80 | stock_lh_yyb_control_df = stock_lh_yyb_control() 81 | print(stock_lh_yyb_control_df) 82 | -------------------------------------------------------------------------------- /akshare/stock/stock_us_yahoo.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/3/17 10:16 5 | Desc: 6 | """ 7 | import lxml 8 | import pandas 9 | import requests 10 | import time 11 | from datetime import datetime, timedelta 12 | 13 | from lxml import html 14 | 15 | 16 | def format_date(date_datetime): 17 | date_timetuple = date_datetime.timetuple() 18 | date_mktime = time.mktime(date_timetuple) 19 | date_int = int(date_mktime) 20 | date_str = str(date_int) 21 | return date_str 22 | 23 | 24 | def subdomain(symbol, start, end): 25 | format_url = "{0}/history?period1={1}&period2={2}" 26 | tail_url = "&interval=div%7Csplit&filter=div&frequency=1d" 27 | subdomain = format_url.format(symbol, start, end) + tail_url 28 | return subdomain 29 | 30 | 31 | def header(subdomain): 32 | hdrs = { 33 | "authority": "finance.yahoo.com", 34 | "method": "GET", 35 | "path": subdomain, 36 | "scheme": "https", 37 | "accept": "text/html,application/xhtml+xml", 38 | "accept-encoding": "gzip, deflate, br", 39 | "accept-language": "en-US,en;q=0.9", 40 | "cache-control": "no-cache", 41 | "cookie": "cookies", 42 | "dnt": "1", 43 | "pragma": "no-cache", 44 | "sec-fetch-mode": "navigate", 45 | "sec-fetch-site": "same-origin", 46 | "sec-fetch-user": "?1", 47 | "upgrade-insecure-requests": "1", 48 | "user-agent": "Mozilla/5.0", 49 | } 50 | return hdrs 51 | 52 | 53 | def scrape_page(url, header): 54 | page = requests.get(url, headers=header) 55 | element_html = html.fromstring(page.content) 56 | table = element_html.xpath("//table") 57 | table_tree = lxml.etree.tostring(table[0], method="xml") 58 | panda = pandas.read_html(table_tree) 59 | return panda 60 | 61 | 62 | def clean_dividends(symbol, dividends): 63 | index = len(dividends) 64 | dividends = dividends.drop(index - 1) 65 | dividends = dividends.set_index("Date") 66 | dividends = dividends["Dividends"] 67 | dividends = dividends.str.replace(r"\Dividend", "") 68 | dividends = dividends.astype(float) 69 | dividends.name = symbol 70 | return dividends 71 | 72 | 73 | if __name__ == "__main__": 74 | symbol = "AAPL" 75 | # create datetime objects 76 | start = datetime.today() - timedelta(days=9125) 77 | end = datetime.today() 78 | # properly format the date to epoch time 79 | start = format_date(start) 80 | end = format_date(end) 81 | # format the subdomain 82 | sub = subdomain(symbol, start, end) 83 | # customize the request header 84 | hdrs = header(sub) 85 | 86 | # concatenate the subdomain with the base URL 87 | base_url = "https://finance.yahoo.com/quote/" 88 | url = base_url + sub 89 | # scrape the dividend history table from Yahoo Finance 90 | dividends = scrape_page(url, hdrs) 91 | # clean the dividend history table 92 | clean_div = clean_dividends(symbol, dividends[0]) 93 | -------------------------------------------------------------------------------- /akshare/stock_feature/stock_em_yzxdr.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2021/1/28 17:18 5 | Desc: 东方财富网-数据中心-特色数据-一致行动人 6 | http://data.eastmoney.com/yzxdr/ 7 | """ 8 | import demjson 9 | import pandas as pd 10 | import requests 11 | 12 | 13 | def stock_em_yzxdr(date: str = "20200930") -> pd.DataFrame: 14 | """ 15 | 东方财富网-数据中心-特色数据-一致行动人 16 | http://data.eastmoney.com/yzxdr/ 17 | :param date: 每年的季度末时间点 18 | :type date: str 19 | :return: 一致行动人 20 | :rtype: pandas.DataFrame 21 | """ 22 | date = '-'.join([date[:4], date[4:6], date[6:]]) 23 | url = "http://datacenter.eastmoney.com/api/data/get" 24 | params = { 25 | "type": "RPTA_WEB_YZXDRINDEX", 26 | "sty": "ALL", 27 | "source": "WEB", 28 | "p": "1", 29 | "ps": "500", 30 | "st": "noticedate", 31 | "sr": "-1", 32 | "var": "mwUyirVm", 33 | "filter": f"(enddate='{date}')", 34 | "rt": "53575609", 35 | } 36 | r = requests.get(url, params=params) 37 | data_text = r.text 38 | data_json = demjson.decode(data_text[data_text.find("{"): -1]) 39 | total_pages = data_json['result']['pages'] 40 | big_df = pd.DataFrame() 41 | for page in range(1, total_pages+1): 42 | params = { 43 | "type": "RPTA_WEB_YZXDRINDEX", 44 | "sty": "ALL", 45 | "source": "WEB", 46 | "p": str(page), 47 | "ps": "500", 48 | "st": "noticedate", 49 | "sr": "-1", 50 | "var": "mwUyirVm", 51 | "filter": f"(enddate='{date}')", 52 | "rt": "53575609", 53 | } 54 | r = requests.get(url, params=params) 55 | data_text = r.text 56 | data_json = demjson.decode(data_text[data_text.find("{"): -1]) 57 | temp_df = pd.DataFrame(data_json["result"]["data"]) 58 | big_df = big_df.append(temp_df, ignore_index=True) 59 | big_df.reset_index(inplace=True) 60 | big_df["index"] = range(1, len(big_df) + 1) 61 | big_df.columns = [ 62 | "序号", 63 | "一致行动人", 64 | "股票代码", 65 | "股东排名", 66 | "公告日期", 67 | "股票简称", 68 | "持股数量", 69 | "持股比例", 70 | "_", 71 | "_", 72 | "行业", 73 | "_", 74 | "_", 75 | "数据日期", 76 | "股票市场", 77 | ] 78 | big_df['数据日期'] = pd.to_datetime(big_df['数据日期']) 79 | big_df['公告日期'] = pd.to_datetime(big_df['公告日期']) 80 | 81 | big_df = big_df[ 82 | [ 83 | "序号", 84 | "一致行动人", 85 | "股票代码", 86 | "股东排名", 87 | "公告日期", 88 | "股票简称", 89 | "持股数量", 90 | "持股比例", 91 | "行业", 92 | "数据日期", 93 | "股票市场", 94 | ] 95 | ] 96 | return big_df 97 | 98 | 99 | if __name__ == "__main__": 100 | stock_em_yzxdr_df = stock_em_yzxdr(date="20201231") 101 | print(stock_em_yzxdr_df) 102 | -------------------------------------------------------------------------------- /docs/answer.md: -------------------------------------------------------------------------------- 1 | # [AKShare](https://github.com/jindaxiang/akshare) 答疑专栏 2 | 3 | ## 专栏介绍 4 | 5 | 本专栏的主要目的是为了解决在使用 [AkShare](https://github.com/jindaxiang/akshare) 中遇到的各种问题,主题包括但不限于:环境配置、AkShare 安装和升级、数据接口请求、代理配置等等。 6 | 7 | ## 常见问题 8 | 9 | 1. 安装 AkShare 的速度慢,下载时间久 10 | 11 | 1. 请使用国内的源来安装 AkShare 12 | 1. 基于 Python 的代码如下: 13 | ```pip install akshare -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host=mirrors.aliyun.com --upgrade ``` 14 | 2. 基于 Anaconda 的代码如下: 15 | ```pip install akshare -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host=mirrors.aliyun.com --user --upgrade``` 16 | 2. 使用代理安装,由于相关限制,在这里对代理的安装和使用不做介绍,请自行搜索配置。 17 | 18 | 2. 运行任意接口发现报错,错误类似:`AttributeError: module 'akshare' has no attribute 'xxx'` 19 | 20 | 1. 检查 Python 的版本需要在 Python 3.6 以上,推荐使用 Python 3.7.5 及以上版本 21 | 2. 检查是否安装了最新版本的 AkShare,如果不是最新版本,请先升级至最新版 22 | 3. 检查在文档中是否具有该 `xxx` 接口,特定情况下有可能会改变接口的命名或者移除某些接口 23 | 4. 检查所运行的 Python 文件名命名问题,不能用如下命名:`akshare.py` 与本地安装包冲突 24 | 25 | 3. 不能获取指定的日期期间的数据,比如从 20200401 至 20200415 的数据 26 | 27 | 1. 由于目标网页的大部分的接口一次性返回所有数据,所以在 AkShare 的部分接口函数中没有设置类似 `start_date` 和 `end_date` 的参数 28 | 2. 如果要获取指定日期间的数据,请在调用接口后自行处理 29 | 30 | 4. 接口报错出现类似错误提示: `ReadTimeout: HTTPConnectionPool(host="www.xxx.com")` 31 | 32 | 1. 重新运行接口函数 33 | 2. 更换 IP 地址,可以使用代理访问 34 | 3. 降低数据访问的频率 35 | 36 | 5. 接口报错出现类似错误提示:`cannot import name 'StringIO' from 'pandas.compat'` 37 | 38 | 1. 建议安装 pandas 版本大于 **0.25.2**,建议 pandas 版本大于 **1.0** 39 | 2. 升级命令如下: `pip install akshare --upgrade` 40 | 41 | 6. 出现数据返回错位,如日期数据和价格数据返回错位的情况 42 | 43 | 1. 多运行几次,是否是网络稳定问题 44 | 2. 切换 IP 后重试 45 | 3. 可以在 [GitHub Issues](https://github.com/jindaxiang/akshare/issues) 中反馈 46 | 47 | 7. 全球疫情历史数据接口获取不到数据 48 | 49 | 1. 由于 GitHub 服务器在国外,访问此数据接口最好使用代理访问 50 | 2. 如没有代理的情况下,多重复请求几次 51 | 52 | 8. 返回值字段错位 53 | 54 | 1. 升级 pandas 到最新版本 55 | 56 | 9. Linux 系统显示 `execjs._exceptions.RuntimeUnavailableError: Could not find an available JavaScript runtime.` 57 | 58 | 1. 需要安装 `nodejs` 59 | 2. 参考[文章](https://blog.csdn.net/qq_36853469/article/details/106401389) 60 | 61 | 10. 将数据在 IDE 全显示,避免折叠显示不全的情况 62 | 63 | 1. 全局设置 `pandas`,使用方法: 64 | 65 | ```python 66 | import pandas as pd 67 | import akshare as ak 68 | # 列名与数据对其显示 69 | pd.set_option('display.unicode.ambiguous_as_wide', True) 70 | pd.set_option('display.unicode.east_asian_width', True) 71 | # 显示所有列 72 | pd.set_option('display.max_columns', None) 73 | # 显示所有行 74 | pd.set_option('display.max_rows', None) 75 | stock_zh_index_daily_df = ak.stock_zh_index_daily(symbol="sz399552") 76 | print(stock_zh_index_daily_df) 77 | ``` 78 | 79 | 11. 出现 `AttributeError: 'MiniRacer' object has no attribute 'ext'` 报错 80 | 1. 安装 64 位的 Python 81 | 82 | 12. 无法下载疫情的海外数据 83 | 1. 访问 [IPAddress](https://www.ipaddress.com/) 84 | 2. 查询 ```raw.githubusercontent.com``` 的真实 IP 地址 85 | 3. 找到系统 host 86 | 1. Windows 10 在目录 ```C:\Windows\System32\drivers\etc``` 87 | 2. Ubuntu 18.04 在目录 ```/etc/hosts``` 88 | 4. 修改 host 89 | 1. 添加如下内容: ```199.232.28.133 raw.githubusercontent.com``` 90 | 2. 此处 ```199.232.28.133``` 为查找到的真实 IP -------------------------------------------------------------------------------- /akshare/bond/bond_bank.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2019/9/30 13:58 5 | Desc: 6 | 获取中国银行间市场交易商协会(http://www.nafmii.org.cn/)中孔雀开屏(http://zhuce.nafmii.org.cn/fans/publicQuery/manager) 7 | 的债券基本信息数据 8 | """ 9 | import pandas as pd 10 | import requests 11 | 12 | from akshare.futures.cons import BOND_BANK_URL, bond_bank_headers 13 | 14 | 15 | # pd.set_option("display.max_columns", None) 16 | 17 | 18 | def get_bond_bank(page_num=1): 19 | """ 20 | 获取中国银行间市场交易商协会(http://www.nafmii.org.cn/)中孔雀开屏(http://zhuce.nafmii.org.cn/fans/publicQuery/manager) 21 | 的债券基本信息数据 22 | :param page_num: 输入数字页码 23 | :return: pandas.DataFrame 24 | firstIssueAmount instNo ... projPhase releaseTime 25 | 5 50000001337193 ... 60 2019-09-17 00:00:00 26 | 20 50000001424511 ... 60 2019-09-17 00:00:00 27 | 4 50000000900081 ... 60 2019-09-17 00:00:00 28 | 3 60000001628024 ... 20 2019-09-17 00:00:00 29 | 5 60000001611820 ... 20 2019-09-17 00:00:00 30 | 5 50000001494880 ... 20 2019-09-17 00:00:00 31 | 10 60000001175908 ... 60 2019-09-17 00:00:00 32 | 5 50000001216207 ... 60 2019-09-17 00:00:00 33 | 6 50000001138819 ... 60 2019-09-17 00:00:00 34 | 2.5 60000001592028 ... 20 2019-09-17 00:00:00 35 | 20 60000001414457 ... 60 2019-09-17 00:00:00 36 | 10 60000001335845 ... 60 2019-09-17 00:00:00 37 | 10 60000001181672 ... 60 2019-09-17 00:00:00 38 | 5 50000000871600 ... 60 2019-09-17 00:00:00 39 | 4.9 50000001116601 ... 60 2019-09-17 00:00:00 40 | 10 60000001577858 ... 20 2019-09-17 00:00:00 41 | 5 50000001426201 ... 60 2019-09-17 00:00:00 42 | 2.5 60000001608635 ... 20 2019-09-17 00:00:00 43 | 15 60000001425846 ... 60 2019-09-17 00:00:00 44 | 2 50000001364547 ... 60 2019-09-17 00:00:00 45 | """ 46 | temp_df = pd.DataFrame() 47 | payload = { 48 | "regFileName": "", 49 | "itemType": "", 50 | "startTime": "", 51 | "endTime": "", 52 | "entityName": "", 53 | "leadManager": "", 54 | "regPrdtType": "", 55 | "page": int(page_num), 56 | "rows": 20, 57 | } 58 | r = requests.post(BOND_BANK_URL, data=payload, headers=bond_bank_headers) 59 | data_json = r.json() # 数据类型为 json 格式 60 | for item in data_json["rows"]: # 遍历 json 的具体格式 61 | temp_df = temp_df.append( 62 | pd.DataFrame.from_dict(item, orient="index").T, sort=False 63 | ) 64 | temp_df.reset_index(inplace=True, drop=True) # 重新设置索引 65 | temp_df.drop_duplicates(inplace=True) 66 | return temp_df[ 67 | [ 68 | "firstIssueAmount", 69 | "isReg", 70 | "regFileName", 71 | "regPrdtType", 72 | "releaseTime", 73 | "projPhase", 74 | ] 75 | ] 76 | 77 | 78 | if __name__ == "__main__": 79 | df = get_bond_bank(2) 80 | print(df) 81 | -------------------------------------------------------------------------------- /docs/data/qhkc/tools.md: -------------------------------------------------------------------------------- 1 | # 工具 2 | 3 | ## 龙虎牛熊多头合约池 4 | 5 | ### 接口名称 6 | 7 | long_pool 8 | 9 | ### 接口描述 10 | 11 | 龙虎牛熊多头合约池接口 12 | 13 | ### 请求参数 14 | 15 | |参数名|说明|举例| 16 | |:----- |:-----|----- | 17 | |date |查询日期 |2018-08-08| 18 | 19 | ### 返回参数 20 | 21 | |参数名|类型|说明| 22 | |:----- |:-----|----- | 23 | |symbol |string |品种编码 | 24 | |code |string |合约代号 | 25 | 26 | ### 示例代码 27 | 28 | ```python 29 | from akshare import pro_api 30 | pro = pro_api(token="在此处输入您的 token, 可以联系奇货可查网站管理员获取") 31 | long_pool_df = pro.long_pool(date="2018-08-08") 32 | print(long_pool_df) 33 | ``` 34 | 35 | ### 返回示例 36 | 37 | ``` 38 | code symbol 39 | 0 rb1810 RB 40 | 1 rb1901 RB 41 | 2 j1809 J 42 | 3 j1901 J 43 | 4 ap1810 AP 44 | 5 ap1901 AP 45 | 6 ap1903 AP 46 | 7 ap1905 AP 47 | 8 cf1809 CF 48 | 9 fg1809 FG 49 | 10 ma1809 MA 50 | 11 rm1901 RM 51 | 12 sf1901 SF 52 | 13 sm1901 SM 53 | 14 sr1809 SR 54 | 15 sr1905 SR 55 | 16 ta1808 TA 56 | 17 ta1903 TA 57 | 18 cu1811 CU 58 | 19 cu1905 CU 59 | 20 al1808 AL 60 | 21 zn1808 ZN 61 | 22 ni1809 NI 62 | 23 au1812 AU 63 | 24 b1901 B 64 | 25 c1905 C 65 | 26 cs1901 CS 66 | 27 jd1809 JD 67 | 28 jd1901 JD 68 | 29 m1809 M 69 | 30 pp1809 PP 70 | 31 pp1901 PP 71 | 32 v1901 V 72 | ``` 73 | 74 | ## 龙虎牛熊空头合约池 75 | 76 | ### 接口名称 77 | 78 | short_pool 79 | 80 | ### 接口描述 81 | 82 | 龙虎牛熊空头合约池 83 | 84 | ### 请求参数 85 | 86 | |参数名|说明|举例| 87 | |:----- |:-----|----- | 88 | |date |查询日期 |2018-08-08| 89 | 90 | ### 返回参数 91 | 92 | |参数名|类型|说明| 93 | |:----- |:-----|----- | 94 | |symbol |string |品种编码 | 95 | |code |string |合约代号 | 96 | 97 | ### 示例代码 98 | 99 | ```python 100 | from akshare import pro_api 101 | pro = pro_api(token="在此处输入您的 token, 可以联系奇货可查网站管理员获取") 102 | short_pool_df = pro.short_pool(date="2018-08-08") 103 | print(short_pool_df) 104 | ``` 105 | 106 | ### 返回示例 107 | 108 | ``` 109 | code symbol 110 | 0 i1901 I 111 | 1 hc1810 HC 112 | 2 ap1811 AP 113 | 3 cf1901 CF 114 | 4 oi1809 OI 115 | 5 oi1905 OI 116 | 6 rm1905 RM 117 | 7 sf1809 SF 118 | 8 ta1811 TA 119 | 9 zc1809 ZC 120 | 10 zc1811 ZC 121 | 11 zc1901 ZC 122 | 12 cu1809 CU 123 | 13 cu1810 CU 124 | 14 cu1901 CU 125 | 15 al1811 AL 126 | 16 al1812 AL 127 | 17 zn1810 ZN 128 | 18 pb1810 PB 129 | 19 sn1809 SN 130 | 20 ag1812 AG 131 | 21 fu1901 FU 132 | 22 ru1809 RU 133 | 23 ru1811 RU 134 | 24 ru1901 RU 135 | 25 ru1905 RU 136 | 26 a1901 A 137 | 27 c1811 C 138 | 28 cs1809 CS 139 | 29 l1809 L 140 | 30 l1901 L 141 | 31 m1811 M 142 | 32 m1901 M 143 | 33 p1809 P 144 | 34 p1905 P 145 | 35 v1809 V 146 | 36 y1809 Y 147 | 37 y1901 Y 148 | 38 y1905 Y 149 | 39 if1808 IF 150 | 40 if1809 IF 151 | 41 ih1808 IH 152 | ``` 153 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # Configuration file for the Sphinx documentation builder. 2 | # sphinx-build -b html . bulid 3 | # This file only contains a selection of the most common options. For a full 4 | # list see the documentation: 5 | # https://www.sphinx-doc.org/en/master/usage/configuration.html 6 | 7 | # -- Path setup -------------------------------------------------------------- 8 | 9 | # If extensions (or modules to document with autodoc) are in another directory, 10 | # add these directories to sys.path here. If the directory is relative to the 11 | # documentation root, use os.path.abspath to make it absolute, like shown here. 12 | 13 | # sys.path.insert(0, os.path.abspath('.')) 14 | import recommonmark 15 | from datetime import datetime 16 | from recommonmark.transform import AutoStructify 17 | import sphinx_rtd_theme 18 | 19 | 20 | latex_engine = 'xelatex' 21 | latex_use_xindy = False 22 | latex_elements = { 23 | 'preamble': '\\usepackage[UTF8]{ctex}\n', 24 | } 25 | 26 | 27 | source_suffix = ['.rst', '.md'] 28 | 29 | github_doc_root = 'https://github.com/rtfd/recommonmark/tree/master/doc/' 30 | 31 | # -- Project information ----------------------------------------------------- 32 | 33 | project = 'AKShare' 34 | copyright = f'2019–{datetime.now().year}, AKShare developers' 35 | author = 'Albert King' 36 | version = "1.0.0" 37 | 38 | templates_path = ['_templates'] 39 | 40 | # The full version, including alpha/beta/rc tags 41 | release = '1.0.0' 42 | 43 | # -- General configuration --------------------------------------------------- 44 | 45 | # Add any Sphinx extension module names here, as strings. They can be 46 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 47 | # ones. 48 | extensions = ["recommonmark", 'sphinx_markdown_tables', "sphinx_rtd_theme"] 49 | 50 | # Add any paths that contain templates here, relative to this directory. 51 | 52 | 53 | # The language for content autogenerated by Sphinx. Refer to documentation 54 | # for a list of supported languages. 55 | # 56 | # This is also used if you do content translation via gettext catalogs. 57 | # Usually you set "language" from the command line for these cases. 58 | language = 'zh_CN' 59 | 60 | # List of patterns, relative to source directory, that match files and 61 | # directories to ignore when looking for source files. 62 | # This pattern also affects html_static_path and html_extra_path. 63 | exclude_patterns = ['_build', '**.ipynb_checkpoints'] 64 | 65 | # -- Options for HTML output ------------------------------------------------- 66 | 67 | # The theme to use for HTML and HTML Help pages. See the documentation for 68 | # a list of builtin themes. 69 | # 70 | html_theme = 'sphinx_rtd_theme' 71 | 72 | # Add any paths that contain custom static files (such as style sheets) here, 73 | # relative to this directory. They are copied after the builtin static files, 74 | # so a file named "default.css" will overwrite the builtin "default.css". 75 | 76 | 77 | master_doc = 'index' 78 | 79 | 80 | def setup(app): 81 | app.add_config_value('recommonmark_config', { 82 | 'url_resolver': lambda url: github_doc_root + url, 83 | 'auto_toc_tree_section': 'Contents', 84 | }, True) 85 | app.add_transform(AutoStructify) 86 | -------------------------------------------------------------------------------- /docs/data/tool/tool.md: -------------------------------------------------------------------------------- 1 | ## [AKShare](https://github.com/jindaxiang/akshare) 工具箱 2 | 3 | ### 交易日历 4 | 5 | 接口: tool_trade_date_hist_sina 6 | 7 | 目标地址: https://finance.sina.com.cn/realstock/company/klc_td_sh.txt 8 | 9 | 描述: 获取新浪财经的股票交易日历数据 10 | 11 | 限量: 单次返回从 1990-12-19 到 2020-12-31 之间的股票交易日历数据 12 | 13 | 输入参数 14 | 15 | | 名称 | 类型 | 必选 | 描述 | 16 | | -------- | ---- | ---- | --- | 17 | | - | - | - | - | 18 | 19 | 输出参数 20 | 21 | | 名称 | 类型 | 默认显示 | 描述 | 22 | | --------------- | ----- | -------- | ---------------- | 23 | | trade_date | str | Y | 从 1990-12-19 至 2020-12-31 的股票交易日数据 | 24 | 25 | 接口示例 26 | 27 | ```python 28 | import akshare as ak 29 | tool_trade_date_hist_sina_df = ak.tool_trade_date_hist_sina() 30 | print(tool_trade_date_hist_sina_df) 31 | ``` 32 | 33 | 数据示例 34 | 35 | ``` 36 | trade_date 37 | 0 1990-12-19 38 | 1 1990-12-20 39 | 2 1990-12-21 40 | 3 1990-12-24 41 | 4 1990-12-25 42 | ... 43 | 7337 2020-12-25 44 | 7338 2020-12-28 45 | 7339 2020-12-29 46 | 7340 2020-12-30 47 | 7341 2020-12-31 48 | ``` 49 | 50 | ### GitHub 51 | 52 | #### Github Star list 53 | 54 | 接口: tool_github_star_list 55 | 56 | 目标地址: https://api.github.com/graphql 57 | 58 | 描述: 获取具体 GitHub 上某个 Repo 的 Star 用户列表 59 | 60 | 限量: 单次返回本 Repo 的所有 Star 用户,由于 API 限制,大型项目速度慢 61 | 62 | 输入参数 63 | 64 | | 名称 | 类型 | 必选 | 描述 | 65 | | -------- | ---- | ---- | --- | 66 | | word | str | Y | owner="PiotrDabkowski"; owner of the repo; https://github.com/**PiotrDabkowski**/Js2Py | 67 | | indicator | str | Y | name="Js2Py"; repo name; https://github.com/PiotrDabkowski/**Js2Py** | 68 | 69 | 输出参数 70 | 71 | | 名称 | 类型 | 默认显示 | 描述 | 72 | | --------------- | ----- | -------- | ---------------- | 73 | | - | - | -| a list of username | 74 | 75 | 接口示例 76 | 77 | ```python 78 | import akshare as ak 79 | result_list = ak.tool_github_star_list(owner="PiotrDabkowski", name="Js2Py") 80 | print(result_list) 81 | ``` 82 | 83 | 数据示例 84 | 85 | ``` 86 | ['ai-rex', 'paranoidi', 'kwcto', 'CoolOppo', ---] 87 | ``` 88 | 89 | #### Github User Email 90 | 91 | 接口: tool_github_email_address 92 | 93 | 目标地址: https://api.github.com/graphql 94 | 95 | 描述: 获取 GitHub 上用户的邮箱地址 96 | 97 | 限量: 单次返回具体用户的邮箱, 若该用户没用邮箱, 则返回空值, 注意 IP 提取限制 98 | 99 | 输入参数 100 | 101 | | 名称 | 类型 | 必选 | 描述 | 102 | | -------- | ---- | ---- | --- | 103 | | username | str | Y | username="PiotrDabkowski"; owner of the repo; https://github.com/**PiotrDabkowski**/Js2Py | 104 | 105 | 输出参数 106 | 107 | | 名称 | 类型 | 默认显示 | 描述 | 108 | | --------------- | ----- | -------- | ---------------- | 109 | | - | - | -| the email address of the user | 110 | 111 | 接口示例 112 | 113 | ```python 114 | import akshare as ak 115 | address = ak.tool_github_email_address(username="lateautumn4lin") 116 | print(address) 117 | ``` 118 | 119 | 数据示例 120 | 121 | ``` 122 | hanqiulun1123@gmail.com 123 | ``` 124 | -------------------------------------------------------------------------------- /akshare/stock/stock_weibo_nlp.py: -------------------------------------------------------------------------------- 1 | # -*- coding:utf-8 -*- 2 | # /usr/bin/env python 3 | """ 4 | Date: 2020/8/27 17:00 5 | Desc: 金十数据中心-实时监控-微博舆情报告 6 | https://datacenter.jin10.com/market 7 | 报告内容:时间期限可选择2小时、6小时、12小时、1天、1周、1月。 8 | 该表格展示的是在对应的时间期限内,个股在微博讨论中的人气排行指数。 9 | 红色颜色越深,表明该股票讨论热度越高,其当前的涨幅更大。 10 | 绿色颜色越深,表明该股票讨论的热度越低,其当前的跌幅更大。 11 | """ 12 | import time 13 | from typing import Dict 14 | 15 | import pandas as pd 16 | import requests 17 | 18 | 19 | def stock_js_weibo_nlp_time() -> Dict: 20 | """ 21 | https://datacenter.jin10.com/market 22 | :return: 特定时间表示的字典 23 | :rtype: dict 24 | """ 25 | url = "https://datacenter-api.jin10.com/weibo/config" 26 | payload = {"_": int(time.time() * 1000)} 27 | headers = { 28 | "authority": "datacenter-api.jin10.com", 29 | "pragma": "no-cache", 30 | "cache-control": "no-cache", 31 | "accept": "*/*", 32 | "x-app-id": "rU6QIu7JHe2gOUeR", 33 | "sec-fetch-dest": "empty", 34 | "x-csrf-token": "", 35 | "x-version": "1.0.0", 36 | "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.116 Safari/537.36", 37 | "origin": "https://datacenter.jin10.com", 38 | "sec-fetch-site": "same-site", 39 | "sec-fetch-mode": "cors", 40 | "referer": "https://datacenter.jin10.com/market", 41 | "accept-language": "zh-CN,zh;q=0.9,en;q=0.8", 42 | } 43 | 44 | r = requests.get(url, headers=headers, data=payload) 45 | return r.json()["data"]["timescale"] 46 | 47 | 48 | def stock_js_weibo_report(time_period: str = "CNHOUR12") -> pd.DataFrame: 49 | """ 50 | 金十数据中心-实时监控-微博舆情报告 51 | https://datacenter.jin10.com/market 52 | :param time_period: {'CNHOUR2': '2小时', 'CNHOUR6': '6小时', 'CNHOUR12': '12小时', 'CNHOUR24': '1天', 'CNDAY7': '1周', 'CNDAY30': '1月'} 53 | :type time_period: str 54 | :return: 指定时间段的微博舆情报告 55 | :rtype: pandas.DataFrame 56 | """ 57 | url = "https://datacenter-api.jin10.com/weibo/list" 58 | payload = { 59 | "timescale": time_period, 60 | "_": int(time.time() * 1000) 61 | } 62 | headers = { 63 | 'authority': 'datacenter-api.jin10.com', 64 | 'pragma': 'no-cache', 65 | 'cache-control': 'no-cache', 66 | 'accept': '*/*', 67 | 'x-app-id': 'rU6QIu7JHe2gOUeR', 68 | 'sec-fetch-dest': 'empty', 69 | 'x-csrf-token': '', 70 | 'x-version': '1.0.0', 71 | 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.116 Safari/537.36', 72 | 'origin': 'https://datacenter.jin10.com', 73 | 'sec-fetch-site': 'same-site', 74 | 'sec-fetch-mode': 'cors', 75 | 'referer': 'https://datacenter.jin10.com/market', 76 | 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8' 77 | } 78 | 79 | r = requests.get(url, params=payload, headers=headers) 80 | return pd.DataFrame(r.json()["data"]) 81 | 82 | 83 | if __name__ == '__main__': 84 | stock_js_weibo_nlp_time_map = stock_js_weibo_nlp_time() 85 | print(stock_js_weibo_nlp_time_map) 86 | get_news_df = stock_js_weibo_report(time_period="CNHOUR6") 87 | print(get_news_df) 88 | --------------------------------------------------------------------------------