akshare-proxy-patch 0.4.2__tar.gz → 0.5.0__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.4.2 → akshare_proxy_patch-0.5.0}/PKG-INFO +41 -53
- {akshare_proxy_patch-0.4.2 → akshare_proxy_patch-0.5.0}/README.md +40 -52
- {akshare_proxy_patch-0.4.2 → akshare_proxy_patch-0.5.0}/akshare_proxy_patch/__init__.py +128 -2
- akshare_proxy_patch-0.5.0/akshare_proxy_patch/akshare_src/__init__.py +0 -0
- akshare_proxy_patch-0.5.0/akshare_proxy_patch/akshare_src/func.py +90 -0
- 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 +1348 -0
- akshare_proxy_patch-0.5.0/akshare_proxy_patch/akshare_src/fund/fund_fhsp_em.py +309 -0
- 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 +1331 -0
- {akshare_proxy_patch-0.4.2 → akshare_proxy_patch-0.5.0}/akshare_proxy_patch.egg-info/PKG-INFO +41 -53
- akshare_proxy_patch-0.5.0/akshare_proxy_patch.egg-info/SOURCES.txt +18 -0
- {akshare_proxy_patch-0.4.2 → akshare_proxy_patch-0.5.0}/pyproject.toml +1 -1
- {akshare_proxy_patch-0.4.2 → akshare_proxy_patch-0.5.0}/setup.py +1 -1
- akshare_proxy_patch-0.4.2/akshare_proxy_patch.egg-info/SOURCES.txt +0 -11
- {akshare_proxy_patch-0.4.2 → akshare_proxy_patch-0.5.0}/LICENSE +0 -0
- {akshare_proxy_patch-0.4.2 → akshare_proxy_patch-0.5.0}/akshare_proxy_patch/yfinance.py +0 -0
- {akshare_proxy_patch-0.4.2 → akshare_proxy_patch-0.5.0}/akshare_proxy_patch.egg-info/dependency_links.txt +0 -0
- {akshare_proxy_patch-0.4.2 → akshare_proxy_patch-0.5.0}/akshare_proxy_patch.egg-info/requires.txt +0 -0
- {akshare_proxy_patch-0.4.2 → akshare_proxy_patch-0.5.0}/akshare_proxy_patch.egg-info/top_level.txt +0 -0
- {akshare_proxy_patch-0.4.2 → akshare_proxy_patch-0.5.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: akshare-proxy-patch
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
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,13 +21,14 @@ 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` 等接口报错问题和 Yahoo `YFRateLimitError`
|
|
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` 等接口报错问题和 Yahoo `YFRateLimitError` 问题。并对 `akshare` 部分接口进行多线程加速处理。
|
|
25
25
|
|
|
26
26
|
## ✨ 特性
|
|
27
27
|
|
|
28
|
-
- 解决 `akshare` 接口报错问题
|
|
29
|
-
- 解决 `efinance`
|
|
30
|
-
- 解决 `yfinance` Yahoo
|
|
28
|
+
- 解决 `akshare` 的 `stock_zh_a_spot_em`、`stock_zh_a_hist` 接口报错问题
|
|
29
|
+
- 解决 `efinance` 的 `get_realtime_quotes` 等接口报错问题
|
|
30
|
+
- 解决 `yfinance` Yahoo接口国内无法使用问题
|
|
31
|
+
- 加速 `stock_zh_a_spot_em`、`stock_individual_fund_flow_rank` 等 `akshare` 接口
|
|
31
32
|
|
|
32
33
|
## 📦 安装
|
|
33
34
|
|
|
@@ -36,7 +37,7 @@ Dynamic: requires-python
|
|
|
36
37
|
2. 安装 `akshare-proxy-patch` 插件
|
|
37
38
|
|
|
38
39
|
```
|
|
39
|
-
pip install akshare-proxy-patch==0.
|
|
40
|
+
pip install akshare-proxy-patch==0.5.0
|
|
40
41
|
```
|
|
41
42
|
|
|
42
43
|
## 🚀 使用方法(akshare / efinance / yfinance)
|
|
@@ -47,7 +48,7 @@ pip install akshare-proxy-patch==0.4.1
|
|
|
47
48
|
|
|
48
49
|
```
|
|
49
50
|
# python 文件顶部添加如下代码
|
|
50
|
-
#
|
|
51
|
+
# 插件引入和调用一定要放到最顶部!不能在 akshare 或 efinance 之后引入!
|
|
51
52
|
import akshare_proxy_patch
|
|
52
53
|
|
|
53
54
|
akshare_proxy_patch.install_patch(
|
|
@@ -61,6 +62,7 @@ akshare_proxy_patch.install_patch(
|
|
|
61
62
|
"push2his.eastmoney.com",
|
|
62
63
|
"emweb.securities.eastmoney.com",
|
|
63
64
|
],
|
|
65
|
+
fast=True
|
|
64
66
|
)
|
|
65
67
|
|
|
66
68
|
# --------------------------
|
|
@@ -80,7 +82,7 @@ ef.stock.get_realtime_quotes()
|
|
|
80
82
|
|
|
81
83
|
```
|
|
82
84
|
# python 文件顶部添加如下代码
|
|
83
|
-
#
|
|
85
|
+
# 插件引入和调用一定要放到最顶部!不能在 akshare 或 efinance 之后引入!
|
|
84
86
|
import akshare_proxy_patch
|
|
85
87
|
|
|
86
88
|
akshare_proxy_patch.install_yfinance_patch(
|
|
@@ -98,7 +100,9 @@ import yfinance as yf
|
|
|
98
100
|
data = yf.download("AAPL", start="2017-01-01", end="2017-04-30")
|
|
99
101
|
```
|
|
100
102
|
|
|
101
|
-
|
|
103
|
+
4. [尽量用 `efinance` 替代 `akshare` 的部分函数获取数据,效率更高,更省积分](https://github.com/Micro-sheep/efinance)
|
|
104
|
+
|
|
105
|
+
## install_patch 参数说明
|
|
102
106
|
|
|
103
107
|
- 参数1:网关
|
|
104
108
|
- 默认为 `101.201.173.125` 不可修改
|
|
@@ -110,13 +114,34 @@ data = yf.download("AAPL", start="2017-01-01", end="2017-04-30")
|
|
|
110
114
|
- 接口 `URL` 包含数组中的其中一条,就会走插件。
|
|
111
115
|
- 可点击 `ak` 或 `ef` 函数查看接口源码对应的 `URL`,根据封控情况细化可以降低积分消耗。
|
|
112
116
|
- 如只封控 `stock_zh_a_spot_em` 这个接口,`hook_domains` 可设置为 `["https://82.push2.eastmoney.com/api/qt/clist/get"]`。
|
|
117
|
+
- 参数5:是否启用快速模式,加速列表如下:
|
|
118
|
+
- 所有包含 `fetch_paginated_data` 函数的接口,如 `stock_zh_a_spot_em`
|
|
119
|
+
- `stock_individual_fund_flow_rank`
|
|
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`
|
|
127
|
+
|
|
128
|
+
## 如何在 aktools 内集成插件?
|
|
129
|
+
|
|
130
|
+
- `aktools` 想要集成插件,需下载 [akt.py](https://github.com/HelloYie/akshare-proxy-patch/blob/master/examples/aktools/akt.py) 文件,并填入您的 `TOKEN`。
|
|
131
|
+
- 然后执行 `python akt.py` 即可启动一个 `http://127.0.0.1:8080/` 服务。只是启动方式不同而已,使用请参考 [aktools 官方文档](https://github.com/akfamily/aktools)。
|
|
132
|
+
|
|
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` 中引入插件并执行数据获取逻辑,最后将结果合并保存。
|
|
113
138
|
|
|
114
139
|
## 如何灵活禁用/启用插件?
|
|
115
140
|
|
|
116
141
|
加入如下代码后插件就会被禁用:
|
|
117
142
|
|
|
118
143
|
```
|
|
119
|
-
|
|
144
|
+
akshare_proxy_patch.uninstall_patch()
|
|
120
145
|
```
|
|
121
146
|
|
|
122
147
|
下面是插件启用 --> 禁用 --> 再次启用的例子:
|
|
@@ -136,12 +161,13 @@ akshare_proxy_patch.install_patch(
|
|
|
136
161
|
"push2his.eastmoney.com",
|
|
137
162
|
"emweb.securities.eastmoney.com",
|
|
138
163
|
],
|
|
164
|
+
fast=True
|
|
139
165
|
)
|
|
140
166
|
import akshare as ak
|
|
141
167
|
df = ak.fund_etf_hist_em()
|
|
142
168
|
|
|
143
169
|
###### 2. 禁用插件
|
|
144
|
-
|
|
170
|
+
akshare_proxy_patch.uninstall_patch()
|
|
145
171
|
|
|
146
172
|
# 禁用后测试
|
|
147
173
|
try:
|
|
@@ -152,51 +178,13 @@ except Exception as e:
|
|
|
152
178
|
##### 3. 再次启用插件,重复上述 1、2 的代码即可
|
|
153
179
|
```
|
|
154
180
|
|
|
155
|
-
##
|
|
156
|
-
|
|
157
|
-
`aktools` 想要集成插件,需要新建一个 `akt.py` 替换官方的 `python -m aktools` 启动命令,下面是 `akt.py` 内容:
|
|
158
|
-
|
|
159
|
-
```
|
|
160
|
-
# 添加插件
|
|
161
|
-
import akshare_proxy_patch
|
|
162
|
-
|
|
163
|
-
akshare_proxy_patch.install_patch(
|
|
164
|
-
"101.201.173.125",
|
|
165
|
-
auth_token="你的TOKEN",
|
|
166
|
-
retry=30,
|
|
167
|
-
# 封控的域名列表,可自行调整
|
|
168
|
-
hook_domains=[
|
|
169
|
-
"fund.eastmoney.com",
|
|
170
|
-
"push2.eastmoney.com",
|
|
171
|
-
"push2his.eastmoney.com",
|
|
172
|
-
"emweb.securities.eastmoney.com",
|
|
173
|
-
],
|
|
174
|
-
)
|
|
175
|
-
|
|
176
|
-
# 启动 aktools
|
|
177
|
-
import uvicorn
|
|
178
|
-
|
|
179
|
-
if __name__ == '__main__':
|
|
180
|
-
uvicorn.run(
|
|
181
|
-
"aktools.main:app",
|
|
182
|
-
host="0.0.0.0",
|
|
183
|
-
port=8080,
|
|
184
|
-
reload=False,
|
|
185
|
-
# 根据 CPU 核心数调整,推荐 2×核心数 + 1
|
|
186
|
-
workers=4,
|
|
187
|
-
log_level="info"
|
|
188
|
-
)
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
然后执行 `python akt.py` 即可启动一个 `http://127.0.0.1:8080/` 服务。只是启动方式不同而已,使用请参考 [aktools 官方文档](https://github.com/akfamily/aktools)。
|
|
192
|
-
|
|
193
|
-
## ❓ 我没使用 akshare 或 efinance,能集成插件吗?
|
|
181
|
+
## 我没使用 akshare 或 efinance,能集成插件吗?
|
|
194
182
|
|
|
195
183
|
- 如果使用 Python 语言的 `requests` 库请求接口,插件能自动 hook 住请求,正常工作。
|
|
196
|
-
- 如果您使用其他语言或 python 的其他库,可 [手动提取代理](http://101.201.173.125:47001/api/akshare-auth?token=XXX&version=0.
|
|
184
|
+
- 如果您使用其他语言或 python 的其他库,可 [手动提取代理](http://101.201.173.125:47001/api/akshare-auth?token=XXX&version=0.5.0) 自行实现封控解除。
|
|
197
185
|
|
|
198
|
-
##
|
|
186
|
+
## 使用问题交流群
|
|
199
187
|
|
|
200
188
|
如使用时遇到问题,或对插件有什么意见或建议,可进群交流:
|
|
201
189
|
|
|
202
|
-

|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
# AkShare Proxy Patch
|
|
2
2
|
|
|
3
|
-
> 针对 [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` 等接口报错问题和 Yahoo `YFRateLimitError`
|
|
3
|
+
> 针对 [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` 等接口报错问题和 Yahoo `YFRateLimitError` 问题。并对 `akshare` 部分接口进行多线程加速处理。
|
|
4
4
|
|
|
5
5
|
## ✨ 特性
|
|
6
6
|
|
|
7
|
-
- 解决 `akshare` 接口报错问题
|
|
8
|
-
- 解决 `efinance`
|
|
9
|
-
- 解决 `yfinance` Yahoo
|
|
7
|
+
- 解决 `akshare` 的 `stock_zh_a_spot_em`、`stock_zh_a_hist` 接口报错问题
|
|
8
|
+
- 解决 `efinance` 的 `get_realtime_quotes` 等接口报错问题
|
|
9
|
+
- 解决 `yfinance` Yahoo接口国内无法使用问题
|
|
10
|
+
- 加速 `stock_zh_a_spot_em`、`stock_individual_fund_flow_rank` 等 `akshare` 接口
|
|
10
11
|
|
|
11
12
|
## 📦 安装
|
|
12
13
|
|
|
@@ -15,7 +16,7 @@
|
|
|
15
16
|
2. 安装 `akshare-proxy-patch` 插件
|
|
16
17
|
|
|
17
18
|
```
|
|
18
|
-
pip install akshare-proxy-patch==0.
|
|
19
|
+
pip install akshare-proxy-patch==0.5.0
|
|
19
20
|
```
|
|
20
21
|
|
|
21
22
|
## 🚀 使用方法(akshare / efinance / yfinance)
|
|
@@ -26,7 +27,7 @@ pip install akshare-proxy-patch==0.4.1
|
|
|
26
27
|
|
|
27
28
|
```
|
|
28
29
|
# python 文件顶部添加如下代码
|
|
29
|
-
#
|
|
30
|
+
# 插件引入和调用一定要放到最顶部!不能在 akshare 或 efinance 之后引入!
|
|
30
31
|
import akshare_proxy_patch
|
|
31
32
|
|
|
32
33
|
akshare_proxy_patch.install_patch(
|
|
@@ -40,6 +41,7 @@ akshare_proxy_patch.install_patch(
|
|
|
40
41
|
"push2his.eastmoney.com",
|
|
41
42
|
"emweb.securities.eastmoney.com",
|
|
42
43
|
],
|
|
44
|
+
fast=True
|
|
43
45
|
)
|
|
44
46
|
|
|
45
47
|
# --------------------------
|
|
@@ -59,7 +61,7 @@ ef.stock.get_realtime_quotes()
|
|
|
59
61
|
|
|
60
62
|
```
|
|
61
63
|
# python 文件顶部添加如下代码
|
|
62
|
-
#
|
|
64
|
+
# 插件引入和调用一定要放到最顶部!不能在 akshare 或 efinance 之后引入!
|
|
63
65
|
import akshare_proxy_patch
|
|
64
66
|
|
|
65
67
|
akshare_proxy_patch.install_yfinance_patch(
|
|
@@ -77,7 +79,9 @@ import yfinance as yf
|
|
|
77
79
|
data = yf.download("AAPL", start="2017-01-01", end="2017-04-30")
|
|
78
80
|
```
|
|
79
81
|
|
|
80
|
-
|
|
82
|
+
4. [尽量用 `efinance` 替代 `akshare` 的部分函数获取数据,效率更高,更省积分](https://github.com/Micro-sheep/efinance)
|
|
83
|
+
|
|
84
|
+
## install_patch 参数说明
|
|
81
85
|
|
|
82
86
|
- 参数1:网关
|
|
83
87
|
- 默认为 `101.201.173.125` 不可修改
|
|
@@ -89,13 +93,34 @@ data = yf.download("AAPL", start="2017-01-01", end="2017-04-30")
|
|
|
89
93
|
- 接口 `URL` 包含数组中的其中一条,就会走插件。
|
|
90
94
|
- 可点击 `ak` 或 `ef` 函数查看接口源码对应的 `URL`,根据封控情况细化可以降低积分消耗。
|
|
91
95
|
- 如只封控 `stock_zh_a_spot_em` 这个接口,`hook_domains` 可设置为 `["https://82.push2.eastmoney.com/api/qt/clist/get"]`。
|
|
96
|
+
- 参数5:是否启用快速模式,加速列表如下:
|
|
97
|
+
- 所有包含 `fetch_paginated_data` 函数的接口,如 `stock_zh_a_spot_em`
|
|
98
|
+
- `stock_individual_fund_flow_rank`
|
|
99
|
+
- `stock_sector_fund_flow_rank`
|
|
100
|
+
- `fund_money_fund_info_em`
|
|
101
|
+
- `fund_graded_fund_info_em`
|
|
102
|
+
- `fund_etf_fund_info_em`
|
|
103
|
+
- `fund_fh_em`
|
|
104
|
+
- `fund_cf_em`
|
|
105
|
+
- `fund_fh_rank_em`
|
|
106
|
+
|
|
107
|
+
## 如何在 aktools 内集成插件?
|
|
108
|
+
|
|
109
|
+
- `aktools` 想要集成插件,需下载 [akt.py](https://github.com/HelloYie/akshare-proxy-patch/blob/master/examples/aktools/akt.py) 文件,并填入您的 `TOKEN`。
|
|
110
|
+
- 然后执行 `python akt.py` 即可启动一个 `http://127.0.0.1:8080/` 服务。只是启动方式不同而已,使用请参考 [aktools 官方文档](https://github.com/akfamily/aktools)。
|
|
111
|
+
|
|
112
|
+
## 如何多进程使用,快速拉取数据?
|
|
113
|
+
|
|
114
|
+
- 尽量使用 `efinance` 替代 `akshare` 来获取数据, `efinance` 内置多线程,效率更高,更省积分。
|
|
115
|
+
- 在大规模快速获取数据时,仍需要多进程来提升效率。 参考 `examples/并发获取股票行情/` 目录下的 `main.py` 和 `worker.py` 示例,修改 `worker.py` 中的 `auth_token`,执行 `python main.py` 即可。
|
|
116
|
+
- `main.py` 负责分割任务和启动多个 `worker.py` 进程,`worker.py` 中引入插件并执行数据获取逻辑,最后将结果合并保存。
|
|
92
117
|
|
|
93
118
|
## 如何灵活禁用/启用插件?
|
|
94
119
|
|
|
95
120
|
加入如下代码后插件就会被禁用:
|
|
96
121
|
|
|
97
122
|
```
|
|
98
|
-
|
|
123
|
+
akshare_proxy_patch.uninstall_patch()
|
|
99
124
|
```
|
|
100
125
|
|
|
101
126
|
下面是插件启用 --> 禁用 --> 再次启用的例子:
|
|
@@ -115,12 +140,13 @@ akshare_proxy_patch.install_patch(
|
|
|
115
140
|
"push2his.eastmoney.com",
|
|
116
141
|
"emweb.securities.eastmoney.com",
|
|
117
142
|
],
|
|
143
|
+
fast=True
|
|
118
144
|
)
|
|
119
145
|
import akshare as ak
|
|
120
146
|
df = ak.fund_etf_hist_em()
|
|
121
147
|
|
|
122
148
|
###### 2. 禁用插件
|
|
123
|
-
|
|
149
|
+
akshare_proxy_patch.uninstall_patch()
|
|
124
150
|
|
|
125
151
|
# 禁用后测试
|
|
126
152
|
try:
|
|
@@ -131,51 +157,13 @@ except Exception as e:
|
|
|
131
157
|
##### 3. 再次启用插件,重复上述 1、2 的代码即可
|
|
132
158
|
```
|
|
133
159
|
|
|
134
|
-
##
|
|
135
|
-
|
|
136
|
-
`aktools` 想要集成插件,需要新建一个 `akt.py` 替换官方的 `python -m aktools` 启动命令,下面是 `akt.py` 内容:
|
|
137
|
-
|
|
138
|
-
```
|
|
139
|
-
# 添加插件
|
|
140
|
-
import akshare_proxy_patch
|
|
141
|
-
|
|
142
|
-
akshare_proxy_patch.install_patch(
|
|
143
|
-
"101.201.173.125",
|
|
144
|
-
auth_token="你的TOKEN",
|
|
145
|
-
retry=30,
|
|
146
|
-
# 封控的域名列表,可自行调整
|
|
147
|
-
hook_domains=[
|
|
148
|
-
"fund.eastmoney.com",
|
|
149
|
-
"push2.eastmoney.com",
|
|
150
|
-
"push2his.eastmoney.com",
|
|
151
|
-
"emweb.securities.eastmoney.com",
|
|
152
|
-
],
|
|
153
|
-
)
|
|
154
|
-
|
|
155
|
-
# 启动 aktools
|
|
156
|
-
import uvicorn
|
|
157
|
-
|
|
158
|
-
if __name__ == '__main__':
|
|
159
|
-
uvicorn.run(
|
|
160
|
-
"aktools.main:app",
|
|
161
|
-
host="0.0.0.0",
|
|
162
|
-
port=8080,
|
|
163
|
-
reload=False,
|
|
164
|
-
# 根据 CPU 核心数调整,推荐 2×核心数 + 1
|
|
165
|
-
workers=4,
|
|
166
|
-
log_level="info"
|
|
167
|
-
)
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
然后执行 `python akt.py` 即可启动一个 `http://127.0.0.1:8080/` 服务。只是启动方式不同而已,使用请参考 [aktools 官方文档](https://github.com/akfamily/aktools)。
|
|
171
|
-
|
|
172
|
-
## ❓ 我没使用 akshare 或 efinance,能集成插件吗?
|
|
160
|
+
## 我没使用 akshare 或 efinance,能集成插件吗?
|
|
173
161
|
|
|
174
162
|
- 如果使用 Python 语言的 `requests` 库请求接口,插件能自动 hook 住请求,正常工作。
|
|
175
|
-
- 如果您使用其他语言或 python 的其他库,可 [手动提取代理](http://101.201.173.125:47001/api/akshare-auth?token=XXX&version=0.
|
|
163
|
+
- 如果您使用其他语言或 python 的其他库,可 [手动提取代理](http://101.201.173.125:47001/api/akshare-auth?token=XXX&version=0.5.0) 自行实现封控解除。
|
|
176
164
|
|
|
177
|
-
##
|
|
165
|
+
## 使用问题交流群
|
|
178
166
|
|
|
179
167
|
如使用时遇到问题,或对插件有什么意见或建议,可进群交流:
|
|
180
168
|
|
|
181
|
-

|
|
@@ -1,7 +1,24 @@
|
|
|
1
|
+
import importlib
|
|
2
|
+
import sys
|
|
1
3
|
import time
|
|
2
4
|
import random
|
|
3
5
|
import threading
|
|
4
|
-
|
|
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
|
+
)
|
|
5
22
|
|
|
6
23
|
# 1. 导入必要的库
|
|
7
24
|
try:
|
|
@@ -13,7 +30,7 @@ except ImportError:
|
|
|
13
30
|
|
|
14
31
|
import requests as std_requests
|
|
15
32
|
|
|
16
|
-
__version__ = "0.
|
|
33
|
+
__version__ = "0.5.0"
|
|
17
34
|
|
|
18
35
|
# 授权接口固定使用标准 requests,避免干扰
|
|
19
36
|
_auth_session = std_requests.Session()
|
|
@@ -24,6 +41,8 @@ target_browsers = [
|
|
|
24
41
|
if isinstance(b, str) and (b.startswith("chrome") or b.startswith("edge"))
|
|
25
42
|
]
|
|
26
43
|
|
|
44
|
+
origin_backup = {}
|
|
45
|
+
|
|
27
46
|
|
|
28
47
|
class AuthCache:
|
|
29
48
|
def __init__(self):
|
|
@@ -75,6 +94,7 @@ def install_patch(
|
|
|
75
94
|
hook_domains=default_hook_domains,
|
|
76
95
|
timeout=5,
|
|
77
96
|
cookie="",
|
|
97
|
+
fast=True,
|
|
78
98
|
):
|
|
79
99
|
# --- 核心改进:备份原始 Session 避开递归死循环 ---
|
|
80
100
|
if not hasattr(std_requests, "_OriginalSession"):
|
|
@@ -160,6 +180,95 @@ def install_patch(
|
|
|
160
180
|
curl_requests.get = patched_get
|
|
161
181
|
curl_requests.post = patched_post
|
|
162
182
|
|
|
183
|
+
if fast:
|
|
184
|
+
install_fast_patch()
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def install_fast_patch():
|
|
188
|
+
"""
|
|
189
|
+
一些函数使用多线程替代分页请求,提升效率
|
|
190
|
+
"""
|
|
191
|
+
try:
|
|
192
|
+
akshare = importlib.import_module("akshare")
|
|
193
|
+
# 覆盖已加载的 akshare 模块的 fetch_paginated_data
|
|
194
|
+
for name, mod in list(sys.modules.items()):
|
|
195
|
+
if mod and name.startswith("akshare"):
|
|
196
|
+
if hasattr(mod, "fetch_paginated_data"):
|
|
197
|
+
origin_backup[(name, "fetch_paginated_data")] = getattr(
|
|
198
|
+
mod, "fetch_paginated_data"
|
|
199
|
+
)
|
|
200
|
+
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
|
+
except Exception as e:
|
|
270
|
+
print("启动快速模式失败:", e)
|
|
271
|
+
|
|
163
272
|
|
|
164
273
|
def install_yfinance_patch(
|
|
165
274
|
auth_ip, auth_token="", retry=30, hook_domains=["finance.yahoo.com"]
|
|
@@ -167,3 +276,20 @@ def install_yfinance_patch(
|
|
|
167
276
|
from .yfinance import install_yfinance_patch_main
|
|
168
277
|
|
|
169
278
|
install_yfinance_patch_main(auth_ip, auth_token, retry, hook_domains)
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
def uninstall_patch():
|
|
282
|
+
"""
|
|
283
|
+
卸载插件,恢复原始状态
|
|
284
|
+
"""
|
|
285
|
+
import requests
|
|
286
|
+
|
|
287
|
+
# 恢复 requests 模块到原始状态
|
|
288
|
+
importlib.reload(requests)
|
|
289
|
+
try:
|
|
290
|
+
# 还原 akshare 模块
|
|
291
|
+
for (mod_name, func_name), original_func in origin_backup.items():
|
|
292
|
+
if mod_name in sys.modules:
|
|
293
|
+
setattr(sys.modules[mod_name], func_name, original_func)
|
|
294
|
+
except Exception as e:
|
|
295
|
+
print("还原 akshare 模块失败:", e)
|
|
File without changes
|
|
@@ -0,0 +1,90 @@
|
|
|
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.request import request_with_retry
|
|
16
|
+
from akshare.utils.tqdm import get_tqdm
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def fetch_paginated_data(url: str, base_params: Dict, timeout: int = 15):
|
|
20
|
+
"""
|
|
21
|
+
东方财富-分页获取数据并合并结果
|
|
22
|
+
https://quote.eastmoney.com/f1.html?newcode=0.000001
|
|
23
|
+
:param url: 股票代码
|
|
24
|
+
:type url: str
|
|
25
|
+
:param base_params: 基础请求参数
|
|
26
|
+
:type base_params: dict
|
|
27
|
+
:param timeout: 请求超时时间
|
|
28
|
+
:type timeout: str
|
|
29
|
+
:return: 合并后的数据
|
|
30
|
+
:rtype: pandas.DataFrame
|
|
31
|
+
"""
|
|
32
|
+
# 复制参数以避免修改原始参数
|
|
33
|
+
params = base_params.copy()
|
|
34
|
+
# 获取第一页数据,用于确定分页信息
|
|
35
|
+
r = request_with_retry(url, params=params, timeout=timeout)
|
|
36
|
+
data_json = r.json()
|
|
37
|
+
# 计算分页信息
|
|
38
|
+
per_page_num = len(data_json["data"]["diff"])
|
|
39
|
+
total_page = math.ceil(data_json["data"]["total"] / per_page_num)
|
|
40
|
+
# 存储所有页面数据
|
|
41
|
+
temp_list = []
|
|
42
|
+
# 添加第一页数据
|
|
43
|
+
temp_list.append(pd.DataFrame(data_json["data"]["diff"]))
|
|
44
|
+
# 获取剩余页面数据
|
|
45
|
+
remaining_pages = list(range(2, total_page + 1))
|
|
46
|
+
if remaining_pages:
|
|
47
|
+
tqdm = get_tqdm()
|
|
48
|
+
|
|
49
|
+
def fetch_page(page: int) -> pd.DataFrame:
|
|
50
|
+
current_params = base_params.copy()
|
|
51
|
+
current_params.update({"pn": page})
|
|
52
|
+
time.sleep(random.uniform(0.5, 1.5))
|
|
53
|
+
r = request_with_retry(url, params=current_params, timeout=timeout)
|
|
54
|
+
page_json = r.json()
|
|
55
|
+
return pd.DataFrame(page_json["data"]["diff"])
|
|
56
|
+
|
|
57
|
+
with ThreadPoolExecutor(max_workers=min(8, len(remaining_pages))) as executor:
|
|
58
|
+
future_to_page = {
|
|
59
|
+
executor.submit(fetch_page, page): page for page in remaining_pages
|
|
60
|
+
}
|
|
61
|
+
for future in tqdm(
|
|
62
|
+
as_completed(future_to_page), total=len(remaining_pages), leave=False
|
|
63
|
+
):
|
|
64
|
+
inner_temp_df = future.result()
|
|
65
|
+
temp_list.append(inner_temp_df)
|
|
66
|
+
|
|
67
|
+
# 合并所有数据
|
|
68
|
+
temp_df = pd.concat(temp_list, ignore_index=True)
|
|
69
|
+
temp_df["f3"] = pd.to_numeric(temp_df["f3"], errors="coerce")
|
|
70
|
+
temp_df.sort_values(by=["f3"], ascending=False, inplace=True, ignore_index=True)
|
|
71
|
+
temp_df.reset_index(inplace=True)
|
|
72
|
+
temp_df["index"] = temp_df["index"].astype(int) + 1
|
|
73
|
+
return temp_df
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def set_df_columns(df: pd.DataFrame, cols: List[str]) -> pd.DataFrame:
|
|
77
|
+
"""
|
|
78
|
+
设置 pandas.DataFrame 为空的情况
|
|
79
|
+
:param df: 需要设置命名的数据框
|
|
80
|
+
:type df: pandas.DataFrame
|
|
81
|
+
:param cols: 字段的列表
|
|
82
|
+
:type cols: list
|
|
83
|
+
:return: 重新设置后的数据
|
|
84
|
+
:rtype: pandas.DataFrame
|
|
85
|
+
"""
|
|
86
|
+
if df.shape == (0, 0):
|
|
87
|
+
return pd.DataFrame(data=[], columns=cols)
|
|
88
|
+
else:
|
|
89
|
+
df.columns = cols
|
|
90
|
+
return df
|
|
File without changes
|