akshare-proxy-patch 0.5.0__tar.gz → 0.5.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {akshare_proxy_patch-0.5.0 → akshare_proxy_patch-0.5.1}/PKG-INFO +54 -59
- akshare_proxy_patch-0.5.1/README.md +164 -0
- {akshare_proxy_patch-0.5.0 → akshare_proxy_patch-0.5.1}/akshare_proxy_patch/__init__.py +6 -84
- akshare_proxy_patch-0.5.1/akshare_proxy_patch/akshare_src/func_new.py +97 -0
- {akshare_proxy_patch-0.5.0 → akshare_proxy_patch-0.5.1}/akshare_proxy_patch.egg-info/PKG-INFO +54 -59
- {akshare_proxy_patch-0.5.0 → akshare_proxy_patch-0.5.1}/akshare_proxy_patch.egg-info/SOURCES.txt +1 -5
- {akshare_proxy_patch-0.5.0 → akshare_proxy_patch-0.5.1}/pyproject.toml +1 -1
- {akshare_proxy_patch-0.5.0 → akshare_proxy_patch-0.5.1}/setup.py +1 -1
- akshare_proxy_patch-0.5.0/README.md +0 -169
- akshare_proxy_patch-0.5.0/akshare_proxy_patch/akshare_src/fund/__init__.py +0 -0
- akshare_proxy_patch-0.5.0/akshare_proxy_patch/akshare_src/fund/fund_em.py +0 -1348
- akshare_proxy_patch-0.5.0/akshare_proxy_patch/akshare_src/fund/fund_fhsp_em.py +0 -309
- akshare_proxy_patch-0.5.0/akshare_proxy_patch/akshare_src/stock/__init__.py +0 -0
- akshare_proxy_patch-0.5.0/akshare_proxy_patch/akshare_src/stock/stock_fund_em.py +0 -1331
- {akshare_proxy_patch-0.5.0 → akshare_proxy_patch-0.5.1}/LICENSE +0 -0
- {akshare_proxy_patch-0.5.0 → akshare_proxy_patch-0.5.1}/akshare_proxy_patch/akshare_src/__init__.py +0 -0
- {akshare_proxy_patch-0.5.0 → akshare_proxy_patch-0.5.1}/akshare_proxy_patch/akshare_src/func.py +0 -0
- {akshare_proxy_patch-0.5.0 → akshare_proxy_patch-0.5.1}/akshare_proxy_patch/yfinance.py +0 -0
- {akshare_proxy_patch-0.5.0 → akshare_proxy_patch-0.5.1}/akshare_proxy_patch.egg-info/dependency_links.txt +0 -0
- {akshare_proxy_patch-0.5.0 → akshare_proxy_patch-0.5.1}/akshare_proxy_patch.egg-info/requires.txt +0 -0
- {akshare_proxy_patch-0.5.0 → akshare_proxy_patch-0.5.1}/akshare_proxy_patch.egg-info/top_level.txt +0 -0
- {akshare_proxy_patch-0.5.0 → akshare_proxy_patch-0.5.1}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: akshare-proxy-patch
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.1
|
|
4
4
|
Summary: 针对 AkShare 和 efinance 的底层补丁,自动为东财等接口注入代理认证头,从而避免 `stock_zh_a_spot_em` 等方法报错。
|
|
5
5
|
Home-page: https://github.com/helloyie/akshare-proxy-patch
|
|
6
6
|
Author: cheapproxy.net
|
|
@@ -21,14 +21,15 @@ Dynamic: requires-python
|
|
|
21
21
|
|
|
22
22
|
# AkShare Proxy Patch
|
|
23
23
|
|
|
24
|
-
> 针对 [akshare](https://github.com/akfamily/akshare)、[efinance](https://github.com/Micro-sheep/efinance)、[yfinance](https://github.com/ranaroussi/yfinance) 的🐒插件补丁,解决 `stock_zh_a_spot_em`、`stock_zh_a_hist`、`get_realtime_quotes`
|
|
24
|
+
> 针对 [akshare](https://github.com/akfamily/akshare)、[efinance](https://github.com/Micro-sheep/efinance)、[yfinance](https://github.com/ranaroussi/yfinance)、[aktools](https://github.com/akfamily/aktools)、[daily_stock_analysis](https://github.com/ZhuLinsen/daily_stock_analysis/) 的🐒插件补丁,解决 `stock_zh_a_spot_em`、`stock_zh_a_hist`、`get_realtime_quotes` 等东财接口报错问题和 Yahoo `YFRateLimitError` 问题。并对 `akshare` 部分接口进行多线程加速处理。
|
|
25
25
|
|
|
26
26
|
## ✨ 特性
|
|
27
27
|
|
|
28
|
-
- 解决 `akshare` 的 `stock_zh_a_spot_em`、`stock_zh_a_hist` 接口报错问题
|
|
28
|
+
- 解决 `akshare` 或 `aktools` 的 `stock_zh_a_spot_em`、`stock_zh_a_hist` 接口报错问题
|
|
29
29
|
- 解决 `efinance` 的 `get_realtime_quotes` 等接口报错问题
|
|
30
30
|
- 解决 `yfinance` Yahoo接口国内无法使用问题
|
|
31
|
-
-
|
|
31
|
+
- 解决 `daily_stock_analysis` 的数据获取报错问题
|
|
32
|
+
- 多线程加速 `stock_zh_a_spot_em` 等 `akshare` 接口
|
|
32
33
|
|
|
33
34
|
## 📦 安装
|
|
34
35
|
|
|
@@ -37,18 +38,19 @@ Dynamic: requires-python
|
|
|
37
38
|
2. 安装 `akshare-proxy-patch` 插件
|
|
38
39
|
|
|
39
40
|
```
|
|
40
|
-
pip install akshare-proxy-patch==0.5.
|
|
41
|
+
pip install akshare-proxy-patch==0.5.1
|
|
41
42
|
```
|
|
42
43
|
|
|
43
44
|
## 🚀 使用方法(akshare / efinance / yfinance)
|
|
44
45
|
|
|
45
46
|
1. [点击前往插件官网](https://ak.cheapproxy.net/dashboard/akshare) 获取 `TOKEN`。
|
|
46
47
|
|
|
47
|
-
2. `akshare` 或 `efinance` 用户:在 **Python
|
|
48
|
+
2. `akshare` 或 `efinance` 用户:在 **Python 文件最顶部** 添加如下代码,并替换 `你的TOKEN`。
|
|
48
49
|
|
|
49
50
|
```
|
|
50
51
|
# python 文件顶部添加如下代码
|
|
51
|
-
#
|
|
52
|
+
# 重要:插件引入和调用一定要放到最顶部!不能在 akshare 或 efinance 之后引入!
|
|
53
|
+
|
|
52
54
|
import akshare_proxy_patch
|
|
53
55
|
|
|
54
56
|
akshare_proxy_patch.install_patch(
|
|
@@ -61,12 +63,14 @@ akshare_proxy_patch.install_patch(
|
|
|
61
63
|
"push2.eastmoney.com",
|
|
62
64
|
"push2his.eastmoney.com",
|
|
63
65
|
"emweb.securities.eastmoney.com",
|
|
66
|
+
"searchapi.eastmoney.com/api/suggest/get",
|
|
67
|
+
"push2delay.eastmoney.com/api/qt/clist/get"
|
|
64
68
|
],
|
|
65
69
|
fast=True
|
|
66
70
|
)
|
|
67
71
|
|
|
68
72
|
# --------------------------
|
|
69
|
-
#
|
|
73
|
+
# 后续你的业务代码保持不变
|
|
70
74
|
# --------------------------
|
|
71
75
|
|
|
72
76
|
# 假如你使用 akshare
|
|
@@ -78,11 +82,12 @@ import efinance as ef
|
|
|
78
82
|
ef.stock.get_realtime_quotes()
|
|
79
83
|
```
|
|
80
84
|
|
|
81
|
-
3. `yfinance` 用户:在 Python 文件顶部添加如下代码,并替换 `你的TOKEN
|
|
85
|
+
3. `yfinance` 用户:在 Python 文件顶部添加如下代码,并替换 `你的TOKEN`,不需要使用 AI 魔改。
|
|
82
86
|
|
|
83
87
|
```
|
|
84
88
|
# python 文件顶部添加如下代码
|
|
85
|
-
#
|
|
89
|
+
# 重要:插件引入和调用一定要放到最顶部!不能在 akshare 或 efinance 之后引入!
|
|
90
|
+
|
|
86
91
|
import akshare_proxy_patch
|
|
87
92
|
|
|
88
93
|
akshare_proxy_patch.install_yfinance_patch(
|
|
@@ -92,7 +97,7 @@ akshare_proxy_patch.install_yfinance_patch(
|
|
|
92
97
|
)
|
|
93
98
|
|
|
94
99
|
# --------------------------
|
|
95
|
-
#
|
|
100
|
+
# 后续你的业务代码保持不变
|
|
96
101
|
# --------------------------
|
|
97
102
|
|
|
98
103
|
import yfinance as yf
|
|
@@ -100,59 +105,44 @@ import yfinance as yf
|
|
|
100
105
|
data = yf.download("AAPL", start="2017-01-01", end="2017-04-30")
|
|
101
106
|
```
|
|
102
107
|
|
|
103
|
-
4.
|
|
108
|
+
4. 尽量用 [efinance](https://github.com/Micro-sheep/efinance) 替代 akshare 的部分函数配合插件获取数据,效率更高,更省积分。
|
|
104
109
|
|
|
105
110
|
## install_patch 参数说明
|
|
106
111
|
|
|
107
|
-
-
|
|
108
|
-
-
|
|
109
|
-
-
|
|
110
|
-
- 授权凭证
|
|
111
|
-
-
|
|
112
|
-
-
|
|
113
|
-
-
|
|
114
|
-
-
|
|
115
|
-
- 可点击 `
|
|
116
|
-
-
|
|
117
|
-
-
|
|
118
|
-
-
|
|
119
|
-
- `
|
|
120
|
-
- `stock_sector_fund_flow_rank`
|
|
121
|
-
- `fund_money_fund_info_em`
|
|
122
|
-
- `fund_graded_fund_info_em`
|
|
123
|
-
- `fund_etf_fund_info_em`
|
|
124
|
-
- `fund_fh_em`
|
|
125
|
-
- `fund_cf_em`
|
|
126
|
-
- `fund_fh_rank_em`
|
|
112
|
+
- `ip`
|
|
113
|
+
- 网关,不可修改
|
|
114
|
+
- `auth_token`
|
|
115
|
+
- TOKEN 授权凭证
|
|
116
|
+
- `retry`
|
|
117
|
+
- 重试次数,默认为30,建议保持不变
|
|
118
|
+
- `hook_domains`
|
|
119
|
+
- 封控的域名列表,插件会 hook 住这些域名的请求,解除封控。已默认涵盖常见函数的域名。
|
|
120
|
+
- 可点击 `akshare` 或 `efinance` 函数查看接口源码对应的 `URL` 并添加到该列表。
|
|
121
|
+
- 如只用到 `stock_zh_a_spot_em` 这个接口,`hook_domains` 可设置为 `["https://82.push2.eastmoney.com/api/qt/clist/get"]`。
|
|
122
|
+
- `fast`
|
|
123
|
+
- 是否启用 `akshare` 多线程加速,默认开启,加速函数列表如下
|
|
124
|
+
- 所有用到 `fetch_paginated_data` 分页函数的接口,如 `stock_zh_a_spot_em`、`stock_sh_a_spot_em`、`stock_board_industry_cons_em` 等
|
|
127
125
|
|
|
128
126
|
## 如何在 aktools 内集成插件?
|
|
129
127
|
|
|
130
128
|
- `aktools` 想要集成插件,需下载 [akt.py](https://github.com/HelloYie/akshare-proxy-patch/blob/master/examples/aktools/akt.py) 文件,并填入您的 `TOKEN`。
|
|
131
129
|
- 然后执行 `python akt.py` 即可启动一个 `http://127.0.0.1:8080/` 服务。只是启动方式不同而已,使用请参考 [aktools 官方文档](https://github.com/akfamily/aktools)。
|
|
132
130
|
|
|
133
|
-
##
|
|
134
|
-
|
|
135
|
-
- 尽量使用 `efinance` 替代 `akshare` 来获取数据, `efinance` 内置多线程,效率更高,更省积分。
|
|
136
|
-
- 在大规模快速获取数据时,仍需要多进程来提升效率。 参考 `examples/并发获取股票行情/` 目录下的 `main.py` 和 `worker.py` 示例,修改 `worker.py` 中的 `auth_token`,执行 `python main.py` 即可。
|
|
137
|
-
- `main.py` 负责分割任务和启动多个 `worker.py` 进程,`worker.py` 中引入插件并执行数据获取逻辑,最后将结果合并保存。
|
|
138
|
-
|
|
139
|
-
## 如何灵活禁用/启用插件?
|
|
131
|
+
## 如何在 daily_stock_analysis 内集成插件?
|
|
140
132
|
|
|
141
|
-
|
|
133
|
+
- [daily_stock_analysis](https://github.com/ZhuLinsen/daily_stock_analysis) 本身集成了 `akshare`、`efinance` 等数据源,如遇数据源报错,可以通过引入插件来解决。
|
|
134
|
+
- 在 [daily_stock_analysis](https://github.com/ZhuLinsen/daily_stock_analysis) 项目中,找到入口 Python 文件 `main.py`,在文件顶部引入插件:
|
|
142
135
|
|
|
143
136
|
```
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
下面是插件启用 --> 禁用 --> 再次启用的例子:
|
|
137
|
+
# 找到 daily_stock_analysis main.py 的这行(第一行)代码,在其下方引入插件
|
|
138
|
+
from __future__ import annotations
|
|
148
139
|
|
|
149
|
-
|
|
150
|
-
##### 1. 启用插件
|
|
140
|
+
# 引入插件
|
|
151
141
|
import akshare_proxy_patch
|
|
152
142
|
|
|
153
143
|
akshare_proxy_patch.install_patch(
|
|
154
144
|
"101.201.173.125",
|
|
155
|
-
auth_token=
|
|
145
|
+
auth_token="你的TOKEN",
|
|
156
146
|
retry=30,
|
|
157
147
|
# 封控的域名列表,可自行调整
|
|
158
148
|
hook_domains=[
|
|
@@ -160,31 +150,36 @@ akshare_proxy_patch.install_patch(
|
|
|
160
150
|
"push2.eastmoney.com",
|
|
161
151
|
"push2his.eastmoney.com",
|
|
162
152
|
"emweb.securities.eastmoney.com",
|
|
153
|
+
"searchapi.eastmoney.com/api/suggest/get",
|
|
154
|
+
"push2delay.eastmoney.com/api/qt/clist/get"
|
|
163
155
|
],
|
|
164
156
|
fast=True
|
|
165
157
|
)
|
|
166
|
-
|
|
167
|
-
|
|
158
|
+
# daily_stock_analysis main.py 的其他后续代码
|
|
159
|
+
# 插件引入成功后正常启动该项目即可
|
|
168
160
|
|
|
169
|
-
|
|
170
|
-
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## 股票数量很多,如何快速拉取数据?
|
|
164
|
+
|
|
165
|
+
- 尽量使用 `efinance` 替代 `akshare` 来获取数据, `efinance` 内置多线程,效率更高,更省积分。
|
|
166
|
+
- 在大规模快速获取数据时,可使用多进程提升效率。 可以参考 [多进程获取所有股票的历史K线](https://github.com/HelloYie/akshare-proxy-patch/blob/master/examples/all_quote_history/main.py),修改 `auth_token`,执行 `python main.py` 测试。
|
|
167
|
+
|
|
168
|
+
## 如何灵活禁用/启用插件?
|
|
171
169
|
|
|
172
|
-
|
|
173
|
-
try:
|
|
174
|
-
df = ak.fund_etf_hist_em()
|
|
175
|
-
except Exception as e:
|
|
176
|
-
print('插件被禁用了,这里可能会报错')
|
|
170
|
+
加入如下代码后插件就会被禁用,[点击查看禁用/启用插件示例](https://github.com/HelloYie/akshare-proxy-patch/blob/master/examples/disable/disable.py):
|
|
177
171
|
|
|
178
|
-
|
|
172
|
+
```
|
|
173
|
+
akshare_proxy_patch.uninstall_patch()
|
|
179
174
|
```
|
|
180
175
|
|
|
181
176
|
## 我没使用 akshare 或 efinance,能集成插件吗?
|
|
182
177
|
|
|
183
178
|
- 如果使用 Python 语言的 `requests` 库请求接口,插件能自动 hook 住请求,正常工作。
|
|
184
|
-
- 如果您使用其他语言或 python 的其他库,可 [手动提取代理](http://101.201.173.125:47001/api/akshare-auth?token=XXX&version=0.5.
|
|
179
|
+
- 如果您使用其他语言或 python 的其他库,可 [手动提取代理](http://101.201.173.125:47001/api/akshare-auth?token=XXX&version=0.5.1) 自行实现封控解除。
|
|
185
180
|
|
|
186
181
|
## 使用问题交流群
|
|
187
182
|
|
|
188
183
|
如使用时遇到问题,或对插件有什么意见或建议,可进群交流:
|
|
189
184
|
|
|
190
|
-

|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# AkShare Proxy Patch
|
|
2
|
+
|
|
3
|
+
> 针对 [akshare](https://github.com/akfamily/akshare)、[efinance](https://github.com/Micro-sheep/efinance)、[yfinance](https://github.com/ranaroussi/yfinance)、[aktools](https://github.com/akfamily/aktools)、[daily_stock_analysis](https://github.com/ZhuLinsen/daily_stock_analysis/) 的🐒插件补丁,解决 `stock_zh_a_spot_em`、`stock_zh_a_hist`、`get_realtime_quotes` 等东财接口报错问题和 Yahoo `YFRateLimitError` 问题。并对 `akshare` 部分接口进行多线程加速处理。
|
|
4
|
+
|
|
5
|
+
## ✨ 特性
|
|
6
|
+
|
|
7
|
+
- 解决 `akshare` 或 `aktools` 的 `stock_zh_a_spot_em`、`stock_zh_a_hist` 接口报错问题
|
|
8
|
+
- 解决 `efinance` 的 `get_realtime_quotes` 等接口报错问题
|
|
9
|
+
- 解决 `yfinance` Yahoo接口国内无法使用问题
|
|
10
|
+
- 解决 `daily_stock_analysis` 的数据获取报错问题
|
|
11
|
+
- 多线程加速 `stock_zh_a_spot_em` 等 `akshare` 接口
|
|
12
|
+
|
|
13
|
+
## 📦 安装
|
|
14
|
+
|
|
15
|
+
1. 安装并升级官方 [akshare](https://github.com/akfamily/akshare) 或 [efinance](https://github.com/Micro-sheep/efinance) 包
|
|
16
|
+
|
|
17
|
+
2. 安装 `akshare-proxy-patch` 插件
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
pip install akshare-proxy-patch==0.5.1
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## 🚀 使用方法(akshare / efinance / yfinance)
|
|
24
|
+
|
|
25
|
+
1. [点击前往插件官网](https://ak.cheapproxy.net/dashboard/akshare) 获取 `TOKEN`。
|
|
26
|
+
|
|
27
|
+
2. `akshare` 或 `efinance` 用户:在 **Python 文件最顶部** 添加如下代码,并替换 `你的TOKEN`。
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
# python 文件顶部添加如下代码
|
|
31
|
+
# 重要:插件引入和调用一定要放到最顶部!不能在 akshare 或 efinance 之后引入!
|
|
32
|
+
|
|
33
|
+
import akshare_proxy_patch
|
|
34
|
+
|
|
35
|
+
akshare_proxy_patch.install_patch(
|
|
36
|
+
"101.201.173.125",
|
|
37
|
+
auth_token="你的TOKEN",
|
|
38
|
+
retry=30,
|
|
39
|
+
# 封控的域名列表,可自行调整
|
|
40
|
+
hook_domains=[
|
|
41
|
+
"fund.eastmoney.com",
|
|
42
|
+
"push2.eastmoney.com",
|
|
43
|
+
"push2his.eastmoney.com",
|
|
44
|
+
"emweb.securities.eastmoney.com",
|
|
45
|
+
"searchapi.eastmoney.com/api/suggest/get",
|
|
46
|
+
"push2delay.eastmoney.com/api/qt/clist/get"
|
|
47
|
+
],
|
|
48
|
+
fast=True
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
# --------------------------
|
|
52
|
+
# 后续你的业务代码保持不变
|
|
53
|
+
# --------------------------
|
|
54
|
+
|
|
55
|
+
# 假如你使用 akshare
|
|
56
|
+
import akshare as ak
|
|
57
|
+
df = ak.stock_zh_a_spot_em()
|
|
58
|
+
|
|
59
|
+
# 假如你使用 efinance
|
|
60
|
+
import efinance as ef
|
|
61
|
+
ef.stock.get_realtime_quotes()
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
3. `yfinance` 用户:在 Python 文件顶部添加如下代码,并替换 `你的TOKEN`,不需要使用 AI 魔改。
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
# python 文件顶部添加如下代码
|
|
68
|
+
# 重要:插件引入和调用一定要放到最顶部!不能在 akshare 或 efinance 之后引入!
|
|
69
|
+
|
|
70
|
+
import akshare_proxy_patch
|
|
71
|
+
|
|
72
|
+
akshare_proxy_patch.install_yfinance_patch(
|
|
73
|
+
"101.201.173.125",
|
|
74
|
+
auth_token="你的TOKEN",
|
|
75
|
+
retry=30,
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
# --------------------------
|
|
79
|
+
# 后续你的业务代码保持不变
|
|
80
|
+
# --------------------------
|
|
81
|
+
|
|
82
|
+
import yfinance as yf
|
|
83
|
+
|
|
84
|
+
data = yf.download("AAPL", start="2017-01-01", end="2017-04-30")
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
4. 尽量用 [efinance](https://github.com/Micro-sheep/efinance) 替代 akshare 的部分函数配合插件获取数据,效率更高,更省积分。
|
|
88
|
+
|
|
89
|
+
## install_patch 参数说明
|
|
90
|
+
|
|
91
|
+
- `ip`
|
|
92
|
+
- 网关,不可修改
|
|
93
|
+
- `auth_token`
|
|
94
|
+
- TOKEN 授权凭证
|
|
95
|
+
- `retry`
|
|
96
|
+
- 重试次数,默认为30,建议保持不变
|
|
97
|
+
- `hook_domains`
|
|
98
|
+
- 封控的域名列表,插件会 hook 住这些域名的请求,解除封控。已默认涵盖常见函数的域名。
|
|
99
|
+
- 可点击 `akshare` 或 `efinance` 函数查看接口源码对应的 `URL` 并添加到该列表。
|
|
100
|
+
- 如只用到 `stock_zh_a_spot_em` 这个接口,`hook_domains` 可设置为 `["https://82.push2.eastmoney.com/api/qt/clist/get"]`。
|
|
101
|
+
- `fast`
|
|
102
|
+
- 是否启用 `akshare` 多线程加速,默认开启,加速函数列表如下
|
|
103
|
+
- 所有用到 `fetch_paginated_data` 分页函数的接口,如 `stock_zh_a_spot_em`、`stock_sh_a_spot_em`、`stock_board_industry_cons_em` 等
|
|
104
|
+
|
|
105
|
+
## 如何在 aktools 内集成插件?
|
|
106
|
+
|
|
107
|
+
- `aktools` 想要集成插件,需下载 [akt.py](https://github.com/HelloYie/akshare-proxy-patch/blob/master/examples/aktools/akt.py) 文件,并填入您的 `TOKEN`。
|
|
108
|
+
- 然后执行 `python akt.py` 即可启动一个 `http://127.0.0.1:8080/` 服务。只是启动方式不同而已,使用请参考 [aktools 官方文档](https://github.com/akfamily/aktools)。
|
|
109
|
+
|
|
110
|
+
## 如何在 daily_stock_analysis 内集成插件?
|
|
111
|
+
|
|
112
|
+
- [daily_stock_analysis](https://github.com/ZhuLinsen/daily_stock_analysis) 本身集成了 `akshare`、`efinance` 等数据源,如遇数据源报错,可以通过引入插件来解决。
|
|
113
|
+
- 在 [daily_stock_analysis](https://github.com/ZhuLinsen/daily_stock_analysis) 项目中,找到入口 Python 文件 `main.py`,在文件顶部引入插件:
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
# 找到 daily_stock_analysis main.py 的这行(第一行)代码,在其下方引入插件
|
|
117
|
+
from __future__ import annotations
|
|
118
|
+
|
|
119
|
+
# 引入插件
|
|
120
|
+
import akshare_proxy_patch
|
|
121
|
+
|
|
122
|
+
akshare_proxy_patch.install_patch(
|
|
123
|
+
"101.201.173.125",
|
|
124
|
+
auth_token="你的TOKEN",
|
|
125
|
+
retry=30,
|
|
126
|
+
# 封控的域名列表,可自行调整
|
|
127
|
+
hook_domains=[
|
|
128
|
+
"fund.eastmoney.com",
|
|
129
|
+
"push2.eastmoney.com",
|
|
130
|
+
"push2his.eastmoney.com",
|
|
131
|
+
"emweb.securities.eastmoney.com",
|
|
132
|
+
"searchapi.eastmoney.com/api/suggest/get",
|
|
133
|
+
"push2delay.eastmoney.com/api/qt/clist/get"
|
|
134
|
+
],
|
|
135
|
+
fast=True
|
|
136
|
+
)
|
|
137
|
+
# daily_stock_analysis main.py 的其他后续代码
|
|
138
|
+
# 插件引入成功后正常启动该项目即可
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## 股票数量很多,如何快速拉取数据?
|
|
143
|
+
|
|
144
|
+
- 尽量使用 `efinance` 替代 `akshare` 来获取数据, `efinance` 内置多线程,效率更高,更省积分。
|
|
145
|
+
- 在大规模快速获取数据时,可使用多进程提升效率。 可以参考 [多进程获取所有股票的历史K线](https://github.com/HelloYie/akshare-proxy-patch/blob/master/examples/all_quote_history/main.py),修改 `auth_token`,执行 `python main.py` 测试。
|
|
146
|
+
|
|
147
|
+
## 如何灵活禁用/启用插件?
|
|
148
|
+
|
|
149
|
+
加入如下代码后插件就会被禁用,[点击查看禁用/启用插件示例](https://github.com/HelloYie/akshare-proxy-patch/blob/master/examples/disable/disable.py):
|
|
150
|
+
|
|
151
|
+
```
|
|
152
|
+
akshare_proxy_patch.uninstall_patch()
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## 我没使用 akshare 或 efinance,能集成插件吗?
|
|
156
|
+
|
|
157
|
+
- 如果使用 Python 语言的 `requests` 库请求接口,插件能自动 hook 住请求,正常工作。
|
|
158
|
+
- 如果您使用其他语言或 python 的其他库,可 [手动提取代理](http://101.201.173.125:47001/api/akshare-auth?token=XXX&version=0.5.1) 自行实现封控解除。
|
|
159
|
+
|
|
160
|
+
## 使用问题交流群
|
|
161
|
+
|
|
162
|
+
如使用时遇到问题,或对插件有什么意见或建议,可进群交流:
|
|
163
|
+
|
|
164
|
+

|
|
@@ -4,21 +4,6 @@ import time
|
|
|
4
4
|
import random
|
|
5
5
|
import threading
|
|
6
6
|
|
|
7
|
-
from .akshare_src.func import fetch_paginated_data as _patched_fetch_paginated_data
|
|
8
|
-
from .akshare_src.stock.stock_fund_em import (
|
|
9
|
-
stock_individual_fund_flow_rank as _patched_stock_individual_fund_flow_rank,
|
|
10
|
-
stock_sector_fund_flow_rank as _patched_stock_sector_fund_flow_rank,
|
|
11
|
-
)
|
|
12
|
-
from .akshare_src.fund.fund_em import (
|
|
13
|
-
fund_money_fund_info_em as _patched_fund_money_fund_info_em,
|
|
14
|
-
fund_graded_fund_info_em as _patched_fund_graded_fund_info_em,
|
|
15
|
-
fund_etf_fund_info_em as _patched_fund_etf_fund_info_em,
|
|
16
|
-
)
|
|
17
|
-
from .akshare_src.fund.fund_fhsp_em import (
|
|
18
|
-
fund_fh_em as _patched_fund_fh_em,
|
|
19
|
-
fund_cf_em as _patched_fund_cf_em,
|
|
20
|
-
fund_fh_rank_em as _patched_fund_fh_rank_em,
|
|
21
|
-
)
|
|
22
7
|
|
|
23
8
|
# 1. 导入必要的库
|
|
24
9
|
try:
|
|
@@ -30,7 +15,7 @@ except ImportError:
|
|
|
30
15
|
|
|
31
16
|
import requests as std_requests
|
|
32
17
|
|
|
33
|
-
__version__ = "0.5.
|
|
18
|
+
__version__ = "0.5.1"
|
|
34
19
|
|
|
35
20
|
# 授权接口固定使用标准 requests,避免干扰
|
|
36
21
|
_auth_session = std_requests.Session()
|
|
@@ -190,6 +175,11 @@ def install_fast_patch():
|
|
|
190
175
|
"""
|
|
191
176
|
try:
|
|
192
177
|
akshare = importlib.import_module("akshare")
|
|
178
|
+
try:
|
|
179
|
+
from .akshare_src.func_new import fetch_paginated_data as _patched_fetch_paginated_data
|
|
180
|
+
except:
|
|
181
|
+
from .akshare_src.func import fetch_paginated_data as _patched_fetch_paginated_data
|
|
182
|
+
|
|
193
183
|
# 覆盖已加载的 akshare 模块的 fetch_paginated_data
|
|
194
184
|
for name, mod in list(sys.modules.items()):
|
|
195
185
|
if mod and name.startswith("akshare"):
|
|
@@ -198,74 +188,6 @@ def install_fast_patch():
|
|
|
198
188
|
mod, "fetch_paginated_data"
|
|
199
189
|
)
|
|
200
190
|
setattr(mod, "fetch_paginated_data", _patched_fetch_paginated_data)
|
|
201
|
-
|
|
202
|
-
origin_backup[("akshare", "stock_individual_fund_flow_rank")] = getattr(
|
|
203
|
-
akshare, "stock_individual_fund_flow_rank"
|
|
204
|
-
)
|
|
205
|
-
setattr(
|
|
206
|
-
akshare,
|
|
207
|
-
"stock_individual_fund_flow_rank",
|
|
208
|
-
_patched_stock_individual_fund_flow_rank,
|
|
209
|
-
)
|
|
210
|
-
|
|
211
|
-
origin_backup[("akshare", "stock_sector_fund_flow_rank")] = getattr(
|
|
212
|
-
akshare, "stock_sector_fund_flow_rank"
|
|
213
|
-
)
|
|
214
|
-
setattr(
|
|
215
|
-
akshare,
|
|
216
|
-
"stock_sector_fund_flow_rank",
|
|
217
|
-
_patched_stock_sector_fund_flow_rank,
|
|
218
|
-
)
|
|
219
|
-
|
|
220
|
-
origin_backup[("akshare", "fund_money_fund_info_em")] = getattr(
|
|
221
|
-
akshare, "fund_money_fund_info_em"
|
|
222
|
-
)
|
|
223
|
-
setattr(
|
|
224
|
-
akshare,
|
|
225
|
-
"fund_money_fund_info_em",
|
|
226
|
-
_patched_fund_money_fund_info_em,
|
|
227
|
-
)
|
|
228
|
-
|
|
229
|
-
origin_backup[("akshare", "fund_graded_fund_info_em")] = getattr(
|
|
230
|
-
akshare, "fund_graded_fund_info_em"
|
|
231
|
-
)
|
|
232
|
-
setattr(
|
|
233
|
-
akshare,
|
|
234
|
-
"fund_graded_fund_info_em",
|
|
235
|
-
_patched_fund_graded_fund_info_em,
|
|
236
|
-
)
|
|
237
|
-
|
|
238
|
-
origin_backup[("akshare", "fund_etf_fund_info_em")] = getattr(
|
|
239
|
-
akshare, "fund_etf_fund_info_em"
|
|
240
|
-
)
|
|
241
|
-
setattr(
|
|
242
|
-
akshare,
|
|
243
|
-
"fund_etf_fund_info_em",
|
|
244
|
-
_patched_fund_etf_fund_info_em,
|
|
245
|
-
)
|
|
246
|
-
|
|
247
|
-
origin_backup[("akshare", "fund_fh_em")] = getattr(akshare, "fund_fh_em")
|
|
248
|
-
setattr(
|
|
249
|
-
akshare,
|
|
250
|
-
"fund_fh_em",
|
|
251
|
-
_patched_fund_fh_em,
|
|
252
|
-
)
|
|
253
|
-
|
|
254
|
-
origin_backup[("akshare", "fund_cf_em")] = getattr(akshare, "fund_cf_em")
|
|
255
|
-
setattr(
|
|
256
|
-
akshare,
|
|
257
|
-
"fund_cf_em",
|
|
258
|
-
_patched_fund_cf_em,
|
|
259
|
-
)
|
|
260
|
-
|
|
261
|
-
origin_backup[("akshare", "fund_fh_rank_em")] = getattr(
|
|
262
|
-
akshare, "fund_fh_rank_em"
|
|
263
|
-
)
|
|
264
|
-
setattr(
|
|
265
|
-
akshare,
|
|
266
|
-
"fund_fh_rank_em",
|
|
267
|
-
_patched_fund_fh_rank_em,
|
|
268
|
-
)
|
|
269
191
|
except Exception as e:
|
|
270
192
|
print("启动快速模式失败:", e)
|
|
271
193
|
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# !/usr/bin/env python
|
|
2
|
+
"""
|
|
3
|
+
Date: 2025/3/10 18:00
|
|
4
|
+
Desc: 通用帮助函数
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import math
|
|
8
|
+
import random
|
|
9
|
+
import time
|
|
10
|
+
from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
11
|
+
from typing import List, Dict
|
|
12
|
+
|
|
13
|
+
import pandas as pd
|
|
14
|
+
|
|
15
|
+
from akshare.utils import http
|
|
16
|
+
from akshare.utils.tqdm import get_tqdm
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _get_page(url: str, params: Dict):
|
|
20
|
+
"""
|
|
21
|
+
取一页东方财富分页数据;每次新建连接,失败时按 http.request_with_retry 的策略重试
|
|
22
|
+
:return: 响应对象
|
|
23
|
+
:rtype: requests.Response
|
|
24
|
+
"""
|
|
25
|
+
r = http.request_with_retry("get", url, params=params, fresh_session=True)
|
|
26
|
+
r.raise_for_status()
|
|
27
|
+
return r
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def fetch_paginated_data(url: str, base_params: Dict):
|
|
31
|
+
"""
|
|
32
|
+
东方财富-分页获取数据并合并结果
|
|
33
|
+
https://quote.eastmoney.com/f1.html?newcode=0.000001
|
|
34
|
+
:param url: 股票代码
|
|
35
|
+
:type url: str
|
|
36
|
+
:param base_params: 基础请求参数
|
|
37
|
+
:type base_params: dict
|
|
38
|
+
:return: 合并后的数据
|
|
39
|
+
:rtype: pandas.DataFrame
|
|
40
|
+
"""
|
|
41
|
+
# 复制参数以避免修改原始参数
|
|
42
|
+
params = base_params.copy()
|
|
43
|
+
# 获取第一页数据,用于确定分页信息
|
|
44
|
+
r = _get_page(url, params)
|
|
45
|
+
data_json = r.json()
|
|
46
|
+
# 计算分页信息
|
|
47
|
+
per_page_num = len(data_json["data"]["diff"])
|
|
48
|
+
total_page = math.ceil(data_json["data"]["total"] / per_page_num)
|
|
49
|
+
# 存储所有页面数据
|
|
50
|
+
temp_list = []
|
|
51
|
+
# 添加第一页数据
|
|
52
|
+
temp_list.append(pd.DataFrame(data_json["data"]["diff"]))
|
|
53
|
+
# 获取进度条
|
|
54
|
+
tqdm = get_tqdm()
|
|
55
|
+
# 并发获取剩余页面;每个任务使用独立参数,避免线程间共享可变状态。
|
|
56
|
+
def fetch_page(page: int):
|
|
57
|
+
page_params = base_params.copy()
|
|
58
|
+
page_params.update({"pn": page})
|
|
59
|
+
# 保留原有随机延迟策略,降低请求过于频繁的概率。
|
|
60
|
+
time.sleep(random.uniform(0.5, 1.5))
|
|
61
|
+
r = _get_page(url, page_params)
|
|
62
|
+
return pd.DataFrame(r.json()["data"]["diff"])
|
|
63
|
+
|
|
64
|
+
pages = range(2, total_page + 1)
|
|
65
|
+
if pages:
|
|
66
|
+
# 固定并发上限,避免页数较多时创建过多线程。
|
|
67
|
+
with ThreadPoolExecutor(max_workers=min(8, len(pages))) as executor:
|
|
68
|
+
futures = {executor.submit(fetch_page, page): page for page in pages}
|
|
69
|
+
page_results = {}
|
|
70
|
+
for future in tqdm(as_completed(futures), total=len(futures), leave=False):
|
|
71
|
+
page_results[futures[future]] = future.result()
|
|
72
|
+
# 按页码恢复原顺序,保持合并及相同排序键下的数据顺序不受并发完成顺序影响。
|
|
73
|
+
temp_list.extend(page_results[page] for page in pages)
|
|
74
|
+
# 合并所有数据
|
|
75
|
+
temp_df = pd.concat(temp_list, ignore_index=True)
|
|
76
|
+
temp_df["f3"] = pd.to_numeric(temp_df["f3"], errors="coerce")
|
|
77
|
+
temp_df = temp_df.sort_values(by=["f3"], ascending=False, ignore_index=True)
|
|
78
|
+
temp_df = temp_df.reset_index()
|
|
79
|
+
temp_df["index"] = temp_df["index"].astype(int) + 1
|
|
80
|
+
return temp_df
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def set_df_columns(df: pd.DataFrame, cols: List[str]) -> pd.DataFrame:
|
|
84
|
+
"""
|
|
85
|
+
设置 pandas.DataFrame 为空的情况
|
|
86
|
+
:param df: 需要设置命名的数据框
|
|
87
|
+
:type df: pandas.DataFrame
|
|
88
|
+
:param cols: 字段的列表
|
|
89
|
+
:type cols: list
|
|
90
|
+
:return: 重新设置后的数据
|
|
91
|
+
:rtype: pandas.DataFrame
|
|
92
|
+
"""
|
|
93
|
+
if df.shape == (0, 0):
|
|
94
|
+
return pd.DataFrame(data=[], columns=cols)
|
|
95
|
+
else:
|
|
96
|
+
df.columns = cols
|
|
97
|
+
return df
|