├── .gitignore ├── LICENSE ├── README.md ├── doc └── images │ ├── apiOne.png │ ├── apiThree.png │ ├── apiTwo.png │ ├── gongzhonghao.png │ ├── qqGroup.png │ └── waizaowang.png ├── requirements.txt ├── setup.py ├── stock └── api │ └── stock_api.py └── waizao ├── __init__.py ├── api ├── __init__.py ├── spider_api.py └── stock_api.py ├── api_demo.py └── export_tool.py /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | *.class 3 | *.iml 4 | target 5 | bin 6 | waizao.egg-info 7 | dist 8 | __pycache__ 9 | #如果是第一次往仓库中提交的话,设置完这个就可以看到效果.在提交的时候,这些文件都不会显示在提交列表中.如果不是第一次提交,需要将之前仓库中需要忽略的文件删除掉,然后再提交.gitignore文件. -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 歪枣网 2 | 3 |

4 | 5 | 财经数据接口 6 | 7 |

8 | 9 |

10 | 歪枣网,提供全面、准确、稳定的财经数据 11 |

12 | 13 | ## 前言 14 | 15 | 本人80后理工科程序猿一枚,2015年初随波入流,进入股市。到目前为止,总收益仍有亏损,但股市虐我千百遍,我待股市如初恋。 16 | 理想很丰满,现实很骨干。也许在股市这条道路上不会顺畅,但我会坚持。
17 | 我不是专家、不是财经达人,我只是千千万万散户中的一位。我会用文字来记录我对股市的理解,记录我增长的理财知识,记录一位普通的小散在股市中的成长经历。 18 | 我会定期更新我建立的投资体系、近期积累的金融知识、股市投资的持仓盈亏等,不断成长,与诸位共勉。
19 | 一些指数类的ETF,尤其是像创业板、沪深300这类宽基指数,波动相对稳定,存在一定周期性,挖掘财经数据是存在一定价值的,这是歪哥相信的,也是一直在探索的。
20 | 21 | ## 项目介绍 22 | 23 | 歪枣网终于和大家见面了,非常感谢有大家的一路支持!
24 | 歪枣网提供的财经数据下载接口,主要用于财经研究,解决大家在财经研究中数据获取的问题。
25 | 通过歪枣网,能快速获取沪深股票、港股、大盘指数、基金净值、基金排行等财经数据,财经接口将提供Txt、Gson、Csv文件等多种数据形式,方便分析人员快速分析数据。
26 | 力求给大家提供更高效、全面、稳定的财经数据服务,让大家不用再担心财经数据源,专心进行策略研究,提升投资收益。
27 | 希望歪枣网提供的财经数据接口能给大家在投资上带来些许方便,在探索财富奥秘、追求财富自由的道路上,也希望有大家相伴。 28 | 29 | ## 财经数据 30 | 31 | 采集数据范围包括沪深京A股、沪深京B股、港股、美股、黄金、汇率、Reits、沪深指数、香港指数、全球指数、债券指数、场内基金、沪深债券、行业板块、概念板块、地域板块等范围列表。
32 | 其中行业数据包括行业板块、概念板块、地域板块;场内基金包括ETF基金和LOF基金。
33 | 主要数据包括:
34 | 35 | - 股票分钟数据,包括一分钟数据 36 | - 股票时线数据,包括5分钟、15分钟、30分钟、60分钟数据。 37 | - 股票日线数据,包括日线、周线、月线数据 38 | - 成分股数据,包括行业板块成分股、主要指数成分股数据。 39 | - 每日行情数据,每天股票各种指标数据采集,内盘、外盘、资金流向等 40 | - 分时成交Level2数据 41 | - 实时数据,提供交易日当天实时交易数据
42 | 更多数据请访问网站:[歪枣网](http://www.waizaowang.com/) 43 | 44 | 历史分钟数据下载地址 45 | 为了降低服务器压力,将历史股票K线数据按一分钟、五分钟、十五分钟、三十分钟、六十分钟为粒度,上传到了百度网盘。打开可以自由下载。 46 | 链接:https://pan.baidu.com/s/1JrIFmzPmiVYehRSqctfNdA 47 | 提取码:vdes 48 | 49 | ## 项目特点 50 | 51 | 主要功能包括:
52 | 1、选择模式,网站左上角菜单栏可以选择模式,包括文档模式、浏览模式、图表模式。 53 | 54 | - 文档模式:提供接口十分详细的说明文档,详细展示了接口的入参、出参,包括字段的含义以及相关说明。 55 | - 浏览模式:提供可视化获取数据的操作界面,用户获取数据完全可以在界面上操作,并且根据用户的操作,在页面下方可以实时生成获取数据的代码。 56 | - 图表模式:提供股票数据的绘图功能,包括生成曲线图和柱状图。 57 | 58 | 2、支持过滤条件,可以灵活的设置过滤条件,定制返回数据,不需要用户二次开发去过滤数据。
59 | 3、接口搜索,展示所有接口信息,可以使用 Ctrl+F 快捷键,搜索你所需要的数据字段。
60 | 4、支持的请求类型,支持GET方法和POST方法,且两种请求方式的路径和入参均相同。
61 | 5、接口更新信息,包括接口更新周期、接口最后更新时间、接口更新耗时会在页面上更新。

62 | ![image](./doc/images/apiOne.png) 63 | ![image](./doc/images/apiTwo.png) 64 | ![image](./doc/images/apiThree.png) 65 | 66 | ## 项目地址 67 | 68 | 目前项目托管在 Gitee 和 Github 平台上中,欢迎大家 Star 和 Fork 支持~
69 | 70 | ### Java SDK : 71 | 72 | Gitee地址:https://gitee.com/waizao/StockApiJava
73 | Github地址:https://github.com/waizao/StockApiJava
74 | 75 | #### 初始化: 76 | 77 | ``` maven 78 | 79 | io.gitee.waizao 80 | openapi 81 | 1.1.4 82 | 83 | ``` 84 | 85 | ### Python SDK: 86 | 87 | Gitee地址:https://gitee.com/waizao/StockApiPython
88 | Github地址::https://github.com/waizao/StockApiPython
89 | 90 | #### 初始化: 91 | 92 | ```shell 93 | pip install waizao -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host=mirrors.aliyun.com --upgrade 94 | ``` 95 | 96 | ## 关注&交流 97 | 98 | 为了方便小伙伴们沟通交流,创建了QQ群 (加群备注:歪枣网) 99 | ,目前项目还存在很多不足之处,欢迎各位大佬进群进行交流,为了防止广告进入,希望加群的时候能添加备注,谢谢~
100 | 如遇问题联系作者,邮箱:waizaowang@163.com
101 | [网站说明文档](https://ccn9lag3l54q.feishu.cn/wiki/KxFlwcXzhi4WRVkCAN4cnyhennb)
102 | 103 | | QQ群【推荐】 | 104 | |------------------------------------------------------------------------------------------| 105 | | | 106 | 107 | 108 | 109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /doc/images/apiOne.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waizao/StockApiPython/9da07a0fcabfc6e1356b46f60630bb94d7f067ca/doc/images/apiOne.png -------------------------------------------------------------------------------- /doc/images/apiThree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waizao/StockApiPython/9da07a0fcabfc6e1356b46f60630bb94d7f067ca/doc/images/apiThree.png -------------------------------------------------------------------------------- /doc/images/apiTwo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waizao/StockApiPython/9da07a0fcabfc6e1356b46f60630bb94d7f067ca/doc/images/apiTwo.png -------------------------------------------------------------------------------- /doc/images/gongzhonghao.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waizao/StockApiPython/9da07a0fcabfc6e1356b46f60630bb94d7f067ca/doc/images/gongzhonghao.png -------------------------------------------------------------------------------- /doc/images/qqGroup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waizao/StockApiPython/9da07a0fcabfc6e1356b46f60630bb94d7f067ca/doc/images/qqGroup.png -------------------------------------------------------------------------------- /doc/images/waizaowang.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waizao/StockApiPython/9da07a0fcabfc6e1356b46f60630bb94d7f067ca/doc/images/waizaowang.png -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pandas>=0.25 2 | requests>=2.22.0 -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding:utf-8 -*- 3 | """ 4 | Date: 2024/3/30 18:30 5 | Desc: AKShare's PYPI info file 6 | """ 7 | 8 | import ast 9 | import re 10 | 11 | 12 | import setuptools 13 | with open("README.md", "r", encoding="utf-8") as f: 14 | long_description = f.read() 15 | 16 | 17 | def get_version_string() -> str: 18 | """ 19 | get the version of waizaowang 20 | :return: version number 21 | :rtype: str, e.g. '0.6.24' 22 | """ 23 | with open("waizao/__init__.py", "rb") as _f: 24 | version_line = re.search( 25 | pattern=r"__version__\s+=\s+(.*)", string=_f.read().decode("utf-8") 26 | ).group(1) 27 | return str(ast.literal_eval(version_line)) 28 | 29 | 30 | setuptools.setup( 31 | name="waizao", 32 | version=get_version_string(), 33 | author="waizaowang", 34 | author_email="waizaowang@163.com", 35 | description="Simple financial data interface library for Python!", 36 | long_description=long_description, 37 | long_description_content_type="text/markdown", 38 | url="http://waizaowang.com/", 39 | packages=setuptools.find_packages(), 40 | install_requires=[ 41 | "pandas>=0.25", 42 | "requests>=2.22.0", 43 | ], 44 | package_data={"": ["*.py", "*.json", "*.pk", "*.js", "*.zip"]}, 45 | keywords=[ 46 | "waizao", 47 | "futures", 48 | "fund", 49 | "bond", 50 | "index", 51 | "finance", 52 | "spider", 53 | "quant", 54 | "quantitative", 55 | "investment", 56 | "trading", 57 | "data", 58 | ], 59 | classifiers=[ 60 | "Programming Language :: Python :: 3.8", 61 | "Programming Language :: Python :: 3.9", 62 | "Programming Language :: Python :: 3.10", 63 | "Programming Language :: Python :: 3.11", 64 | "Programming Language :: Python :: 3.12", 65 | "License :: OSI Approved :: MIT License", 66 | "Operating System :: OS Independent", 67 | ], 68 | python_requires=">=3.8", 69 | ) 70 | -------------------------------------------------------------------------------- /waizao/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | 歪枣网终于和大家见面了,非常感谢有大家的一路支持! 3 | 歪枣网提供的财经数据下载接口,主要用于财经研究,解决大家在财经研究中数据获取的问题。 4 | 通过歪枣网,能快速获取沪深股票、港股、大盘指数、基金净值、基金排行等财经数据,财经接口将提供Txt、Gson、Csv文件等多种数据形式,方便分析人员快速分析数据。 5 | 力求给大家提供更高效、全面、稳定的财经数据服务,让大家不用再担心财经数据源,专心进行策略研究,提升投资收益。 6 | 希望歪枣网提供的财经数据接口能给大家在投资上带来些许方便,在探索财富奥秘、追求财富自由的道路上,也希望有大家相伴。 7 | """ 8 | 9 | __version__ = "1.1.3" 10 | __author__ = "waizaowang" 11 | 12 | import sys 13 | import warnings 14 | 15 | import pandas as pd 16 | 17 | pd_main_version = int(pd.__version__.split('.')[0]) 18 | 19 | if pd_main_version < 2: 20 | warnings.warn( 21 | "为了支持更多特性,请将 Pandas 升级到 2.1.0 及以上版本!" 22 | ) 23 | 24 | if sys.version_info < (3, 9): 25 | warnings.warn( 26 | "为了支持更多特性,请将 Python 升级到 3.9.0 及以上版本!" 27 | ) 28 | 29 | del sys 30 | -------------------------------------------------------------------------------- /waizao/api/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/waizao/StockApiPython/9da07a0fcabfc6e1356b46f60630bb94d7f067ca/waizao/api/__init__.py -------------------------------------------------------------------------------- /waizao/api/spider_api.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding:utf-8 -*- 3 | """ 4 | Date: 2024/1/1 18:11 5 | Desc: 歪枣网,财经数据库 6 | http://www.waizaowang.com/ 7 | """ 8 | import re 9 | import time 10 | 11 | import requests 12 | 13 | 14 | def get_pankou(codes="sz000001,sh600000,bj833171"): 15 | """ 16 | 买卖五档,盘口数据 17 | 纯爬虫接口,完全免费使用,歪枣网不校验权限也不存储任何数据,若用于商业,请合规使用。 18 | :param codes : 传入股票代码 19 | """ 20 | 21 | root_url = "https://hq.sinajs.cn/rn=%s&list=%s" % (str(int(time.time() * 1000)), codes) 22 | response = requests.get(root_url, 23 | headers={ 24 | "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36", 25 | 'host': 'hq.sinajs.cn', 26 | 'referer': 'https://finance.sina.com.cn/' 27 | }) 28 | text = response.content.decode('GBK') 29 | reg = re.compile(r'\="(.*?)\";') 30 | data = reg.findall(text) 31 | data_list = [] 32 | for index, row in enumerate(data): 33 | if len(row) > 1: 34 | data_list.append([astr for astr in row.split(',')[:33]]) 35 | return data_list 36 | 37 | if __name__ == "__main__": 38 | print("sz000001,sh600000,bj833171") 39 | -------------------------------------------------------------------------------- /waizao/api_demo.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from waizao import export_tool 4 | from waizao.api import spider_api 5 | from waizao.api import stock_api 6 | 7 | """ 8 | 1、stock_api.py中函数名与歪枣网开发文档中接口请求URL名称保持一致,方便查找。采用驼峰命名法 9 | 2、spider_api.py中定义了一些行情数据抓取方法 10 | """ 11 | 12 | if __name__ == '__main__': 13 | print("StockApiDemo") 14 | token: str = "" # 歪枣网(www.waizaowang.com)上登录后获取Token 15 | 16 | #买卖五档,盘口数据 17 | data_list: [] = spider_api.get_pankou("sz000001,sh600000,bj833171") 18 | print(data_list) 19 | 20 | # 请求日线数据,返回JSON格式 21 | data: str = stock_api.getDayKLine( 22 | 1, 23 | "all", # 请求A股所有股票 24 | 101, 25 | 1, 26 | "2024-02-01", # code选择all的场景下,开始日期和结束日期必须相同,表示返回市场上当天所有股票的数据 27 | "2024-02-01", 28 | "all", # 返回全部字段,也可以定制字段 29 | 1, # 返回Json数据类型 30 | token, 31 | "", 32 | "get") # get请求 33 | 34 | # 生成Json文件 35 | file = os.path.join(os.path.abspath(os.path.dirname(__file__)), "waizaowang_export.json") 36 | export_tool.toFile(file, data) 37 | 38 | # 将Json格式数据转换为DataFrame格式数据 39 | result = export_tool.toDataFrame(data) 40 | 41 | # 请求日线数据,返回JSON格式 42 | data: str = stock_api.getDayKLine( 43 | 1, 44 | "000001,000002", # 请求部分股票 45 | 101, 46 | 1, 47 | "2024-01-01", 48 | "2025-01-01", 49 | "all", # 返回全部字段,也可以定制字段 50 | 5, # 返回DataFrame格式数据类型 51 | token, 52 | "", 53 | "post") # post请求 54 | result = export_tool.dataFrame(data) 55 | 56 | # 请求日线数据,返回csv格式文件 57 | data: str = stock_api.getDayKLine( 58 | 1, 59 | "000001,000002", # 请求部分股票 60 | 101, 61 | 1, 62 | "2024-01-01", 63 | "2025-01-01", 64 | "all", # 返回全部字段,也可以定制字段 65 | 4, # 返回Csv格式文件 66 | token, 67 | "", 68 | "post") # post请求 69 | # 生成Csv文件 70 | file = os.path.join(os.path.abspath(os.path.dirname(__file__)), "waizaowang_export.csv") 71 | export_tool.toFile(file, data) 72 | 73 | # 请求日线数据,返回txt格式数据 74 | data: str = stock_api.getDayKLine( 75 | 1, 76 | "000001,000002", # 请求部分股票 77 | 101, 78 | 1, 79 | "2024-01-01", 80 | "2025-01-01", 81 | "all", # 返回全部字段,也可以定制字段 82 | 0, # 返回Csv格式文件 83 | token, 84 | "", 85 | "post") # post请求 86 | 87 | print(data) 88 | -------------------------------------------------------------------------------- /waizao/export_tool.py: -------------------------------------------------------------------------------- 1 | import json 2 | 3 | import pandas as pd 4 | 5 | 6 | def toFile(file: str, data: str): 7 | """ 8 | 将请求返回的字符串数据写到文件中,包括Csv、Json、Txt文件 9 | :param file: 文件路径 10 | :param data: 字符串 11 | """ 12 | with open(file, "w", encoding='utf-8') as file: 13 | file.write(data) 14 | 15 | 16 | def toDataFrame(data: str) -> pd.DataFrame: 17 | """ 18 | 将请求返回的Json格式数据转换为DataFrame格式 19 | :param data: Json格式数据 20 | """ 21 | return pd.DataFrame(json.loads(data)["data"]) 22 | 23 | 24 | def dataFrame(data: str) -> pd.DataFrame: 25 | """ 26 | 将请求返回的DataFrame格式数据重新转换为DataFrame格式 27 | :param data: DataFrame格式数据(数据中zh为中文标题,en为英文标题) 28 | """ 29 | json_data = json.loads(data) 30 | temp_df = pd.DataFrame(json_data["data"]) 31 | temp_df.columns = json_data["zh"] # 请求数据对应的字段名称 32 | return temp_df 33 | 34 | 35 | if __name__ == '__main__': 36 | print("StockApiDemo") 37 | --------------------------------------------------------------------------------