akshare-proxy-patch 0.4.1__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.1 → akshare_proxy_patch-0.5.0}/PKG-INFO +62 -31
- akshare_proxy_patch-0.5.0/README.md +169 -0
- {akshare_proxy_patch-0.4.1 → akshare_proxy_patch-0.5.0}/akshare_proxy_patch/__init__.py +135 -4
- 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.1 → akshare_proxy_patch-0.5.0}/akshare_proxy_patch.egg-info/PKG-INFO +62 -31
- akshare_proxy_patch-0.5.0/akshare_proxy_patch.egg-info/SOURCES.txt +18 -0
- {akshare_proxy_patch-0.4.1 → akshare_proxy_patch-0.5.0}/pyproject.toml +1 -1
- {akshare_proxy_patch-0.4.1 → akshare_proxy_patch-0.5.0}/setup.py +1 -1
- akshare_proxy_patch-0.4.1/README.md +0 -138
- akshare_proxy_patch-0.4.1/akshare_proxy_patch.egg-info/SOURCES.txt +0 -11
- {akshare_proxy_patch-0.4.1 → akshare_proxy_patch-0.5.0}/LICENSE +0 -0
- {akshare_proxy_patch-0.4.1 → akshare_proxy_patch-0.5.0}/akshare_proxy_patch/yfinance.py +0 -0
- {akshare_proxy_patch-0.4.1 → akshare_proxy_patch-0.5.0}/akshare_proxy_patch.egg-info/dependency_links.txt +0 -0
- {akshare_proxy_patch-0.4.1 → akshare_proxy_patch-0.5.0}/akshare_proxy_patch.egg-info/requires.txt +0 -0
- {akshare_proxy_patch-0.4.1 → akshare_proxy_patch-0.5.0}/akshare_proxy_patch.egg-info/top_level.txt +0 -0
- {akshare_proxy_patch-0.4.1 → 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,17 +37,18 @@ 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)
|
|
43
44
|
|
|
44
45
|
1. [点击前往插件官网](https://ak.cheapproxy.net/dashboard/akshare) 获取 `TOKEN`。
|
|
45
46
|
|
|
46
|
-
2. `akshare` 或 `efinance` 用户:在 **Python
|
|
47
|
+
2. `akshare` 或 `efinance` 用户:在 **Python 文件最顶部**添加如下代码,并替换 `你的TOKEN`。调用非常简单,不需要使用 AI 魔改。
|
|
47
48
|
|
|
48
49
|
```
|
|
49
50
|
# python 文件顶部添加如下代码
|
|
51
|
+
# 插件引入和调用一定要放到最顶部!不能在 akshare 或 efinance 之后引入!
|
|
50
52
|
import akshare_proxy_patch
|
|
51
53
|
|
|
52
54
|
akshare_proxy_patch.install_patch(
|
|
@@ -60,6 +62,7 @@ akshare_proxy_patch.install_patch(
|
|
|
60
62
|
"push2his.eastmoney.com",
|
|
61
63
|
"emweb.securities.eastmoney.com",
|
|
62
64
|
],
|
|
65
|
+
fast=True
|
|
63
66
|
)
|
|
64
67
|
|
|
65
68
|
# --------------------------
|
|
@@ -79,6 +82,7 @@ ef.stock.get_realtime_quotes()
|
|
|
79
82
|
|
|
80
83
|
```
|
|
81
84
|
# python 文件顶部添加如下代码
|
|
85
|
+
# 插件引入和调用一定要放到最顶部!不能在 akshare 或 efinance 之后引入!
|
|
82
86
|
import akshare_proxy_patch
|
|
83
87
|
|
|
84
88
|
akshare_proxy_patch.install_yfinance_patch(
|
|
@@ -96,7 +100,9 @@ import yfinance as yf
|
|
|
96
100
|
data = yf.download("AAPL", start="2017-01-01", end="2017-04-30")
|
|
97
101
|
```
|
|
98
102
|
|
|
99
|
-
|
|
103
|
+
4. [尽量用 `efinance` 替代 `akshare` 的部分函数获取数据,效率更高,更省积分](https://github.com/Micro-sheep/efinance)
|
|
104
|
+
|
|
105
|
+
## install_patch 参数说明
|
|
100
106
|
|
|
101
107
|
- 参数1:网关
|
|
102
108
|
- 默认为 `101.201.173.125` 不可修改
|
|
@@ -108,18 +114,45 @@ data = yf.download("AAPL", start="2017-01-01", end="2017-04-30")
|
|
|
108
114
|
- 接口 `URL` 包含数组中的其中一条,就会走插件。
|
|
109
115
|
- 可点击 `ak` 或 `ef` 函数查看接口源码对应的 `URL`,根据封控情况细化可以降低积分消耗。
|
|
110
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` 中引入插件并执行数据获取逻辑,最后将结果合并保存。
|
|
138
|
+
|
|
139
|
+
## 如何灵活禁用/启用插件?
|
|
140
|
+
|
|
141
|
+
加入如下代码后插件就会被禁用:
|
|
111
142
|
|
|
112
|
-
|
|
143
|
+
```
|
|
144
|
+
akshare_proxy_patch.uninstall_patch()
|
|
145
|
+
```
|
|
113
146
|
|
|
114
|
-
|
|
147
|
+
下面是插件启用 --> 禁用 --> 再次启用的例子:
|
|
115
148
|
|
|
116
149
|
```
|
|
117
|
-
|
|
150
|
+
##### 1. 启用插件
|
|
118
151
|
import akshare_proxy_patch
|
|
119
152
|
|
|
120
153
|
akshare_proxy_patch.install_patch(
|
|
121
154
|
"101.201.173.125",
|
|
122
|
-
auth_token=
|
|
155
|
+
auth_token='你的TOKEN',
|
|
123
156
|
retry=30,
|
|
124
157
|
# 封控的域名列表,可自行调整
|
|
125
158
|
hook_domains=[
|
|
@@ -128,32 +161,30 @@ akshare_proxy_patch.install_patch(
|
|
|
128
161
|
"push2his.eastmoney.com",
|
|
129
162
|
"emweb.securities.eastmoney.com",
|
|
130
163
|
],
|
|
164
|
+
fast=True
|
|
131
165
|
)
|
|
166
|
+
import akshare as ak
|
|
167
|
+
df = ak.fund_etf_hist_em()
|
|
132
168
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
reload=False,
|
|
142
|
-
# 根据 CPU 核心数调整,推荐 2×核心数 + 1
|
|
143
|
-
workers=4,
|
|
144
|
-
log_level="info"
|
|
145
|
-
)
|
|
146
|
-
```
|
|
169
|
+
###### 2. 禁用插件
|
|
170
|
+
akshare_proxy_patch.uninstall_patch()
|
|
171
|
+
|
|
172
|
+
# 禁用后测试
|
|
173
|
+
try:
|
|
174
|
+
df = ak.fund_etf_hist_em()
|
|
175
|
+
except Exception as e:
|
|
176
|
+
print('插件被禁用了,这里可能会报错')
|
|
147
177
|
|
|
148
|
-
|
|
178
|
+
##### 3. 再次启用插件,重复上述 1、2 的代码即可
|
|
179
|
+
```
|
|
149
180
|
|
|
150
|
-
##
|
|
181
|
+
## 我没使用 akshare 或 efinance,能集成插件吗?
|
|
151
182
|
|
|
152
183
|
- 如果使用 Python 语言的 `requests` 库请求接口,插件能自动 hook 住请求,正常工作。
|
|
153
|
-
- 如果您使用其他语言或 python 的其他库,可 [手动提取代理](http://101.201.173.125:47001/api/akshare-auth?token
|
|
184
|
+
- 如果您使用其他语言或 python 的其他库,可 [手动提取代理](http://101.201.173.125:47001/api/akshare-auth?token=XXX&version=0.5.0) 自行实现封控解除。
|
|
154
185
|
|
|
155
|
-
##
|
|
186
|
+
## 使用问题交流群
|
|
156
187
|
|
|
157
188
|
如使用时遇到问题,或对插件有什么意见或建议,可进群交流:
|
|
158
189
|
|
|
159
|
-

|
|
@@ -0,0 +1,169 @@
|
|
|
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) 的🐒插件补丁,解决 `stock_zh_a_spot_em`、`stock_zh_a_hist`、`get_realtime_quotes` 等接口报错问题和 Yahoo `YFRateLimitError` 问题。并对 `akshare` 部分接口进行多线程加速处理。
|
|
4
|
+
|
|
5
|
+
## ✨ 特性
|
|
6
|
+
|
|
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` 接口
|
|
11
|
+
|
|
12
|
+
## 📦 安装
|
|
13
|
+
|
|
14
|
+
1. 安装并升级官方 [akshare](https://github.com/akfamily/akshare) 或 [efinance](https://github.com/Micro-sheep/efinance) 包
|
|
15
|
+
|
|
16
|
+
2. 安装 `akshare-proxy-patch` 插件
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
pip install akshare-proxy-patch==0.5.0
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## 🚀 使用方法(akshare / efinance / yfinance)
|
|
23
|
+
|
|
24
|
+
1. [点击前往插件官网](https://ak.cheapproxy.net/dashboard/akshare) 获取 `TOKEN`。
|
|
25
|
+
|
|
26
|
+
2. `akshare` 或 `efinance` 用户:在 **Python 文件最顶部**添加如下代码,并替换 `你的TOKEN`。调用非常简单,不需要使用 AI 魔改。
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
# python 文件顶部添加如下代码
|
|
30
|
+
# 插件引入和调用一定要放到最顶部!不能在 akshare 或 efinance 之后引入!
|
|
31
|
+
import akshare_proxy_patch
|
|
32
|
+
|
|
33
|
+
akshare_proxy_patch.install_patch(
|
|
34
|
+
"101.201.173.125",
|
|
35
|
+
auth_token="你的TOKEN",
|
|
36
|
+
retry=30,
|
|
37
|
+
# 封控的域名列表,可自行调整
|
|
38
|
+
hook_domains=[
|
|
39
|
+
"fund.eastmoney.com",
|
|
40
|
+
"push2.eastmoney.com",
|
|
41
|
+
"push2his.eastmoney.com",
|
|
42
|
+
"emweb.securities.eastmoney.com",
|
|
43
|
+
],
|
|
44
|
+
fast=True
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
# --------------------------
|
|
48
|
+
# 后续你的正常业务代码保持不变
|
|
49
|
+
# --------------------------
|
|
50
|
+
|
|
51
|
+
# 假如你使用 akshare
|
|
52
|
+
import akshare as ak
|
|
53
|
+
df = ak.stock_zh_a_spot_em()
|
|
54
|
+
|
|
55
|
+
# 假如你使用 efinance
|
|
56
|
+
import efinance as ef
|
|
57
|
+
ef.stock.get_realtime_quotes()
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
3. `yfinance` 用户:在 Python 文件顶部添加如下代码,并替换 `你的TOKEN`。调用非常简单,不需要使用 AI 魔改。
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
# python 文件顶部添加如下代码
|
|
64
|
+
# 插件引入和调用一定要放到最顶部!不能在 akshare 或 efinance 之后引入!
|
|
65
|
+
import akshare_proxy_patch
|
|
66
|
+
|
|
67
|
+
akshare_proxy_patch.install_yfinance_patch(
|
|
68
|
+
"101.201.173.125",
|
|
69
|
+
auth_token="你的TOKEN",
|
|
70
|
+
retry=30,
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
# --------------------------
|
|
74
|
+
# 后续你的正常业务代码保持不变
|
|
75
|
+
# --------------------------
|
|
76
|
+
|
|
77
|
+
import yfinance as yf
|
|
78
|
+
|
|
79
|
+
data = yf.download("AAPL", start="2017-01-01", end="2017-04-30")
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
4. [尽量用 `efinance` 替代 `akshare` 的部分函数获取数据,效率更高,更省积分](https://github.com/Micro-sheep/efinance)
|
|
83
|
+
|
|
84
|
+
## install_patch 参数说明
|
|
85
|
+
|
|
86
|
+
- 参数1:网关
|
|
87
|
+
- 默认为 `101.201.173.125` 不可修改
|
|
88
|
+
- 参数2:TOKEN
|
|
89
|
+
- 授权凭证
|
|
90
|
+
- 参数3:重试次数
|
|
91
|
+
- 默认为30,建议保持不变
|
|
92
|
+
- 参数4:封控的域名列表
|
|
93
|
+
- 接口 `URL` 包含数组中的其中一条,就会走插件。
|
|
94
|
+
- 可点击 `ak` 或 `ef` 函数查看接口源码对应的 `URL`,根据封控情况细化可以降低积分消耗。
|
|
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` 中引入插件并执行数据获取逻辑,最后将结果合并保存。
|
|
117
|
+
|
|
118
|
+
## 如何灵活禁用/启用插件?
|
|
119
|
+
|
|
120
|
+
加入如下代码后插件就会被禁用:
|
|
121
|
+
|
|
122
|
+
```
|
|
123
|
+
akshare_proxy_patch.uninstall_patch()
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
下面是插件启用 --> 禁用 --> 再次启用的例子:
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
##### 1. 启用插件
|
|
130
|
+
import akshare_proxy_patch
|
|
131
|
+
|
|
132
|
+
akshare_proxy_patch.install_patch(
|
|
133
|
+
"101.201.173.125",
|
|
134
|
+
auth_token='你的TOKEN',
|
|
135
|
+
retry=30,
|
|
136
|
+
# 封控的域名列表,可自行调整
|
|
137
|
+
hook_domains=[
|
|
138
|
+
"fund.eastmoney.com",
|
|
139
|
+
"push2.eastmoney.com",
|
|
140
|
+
"push2his.eastmoney.com",
|
|
141
|
+
"emweb.securities.eastmoney.com",
|
|
142
|
+
],
|
|
143
|
+
fast=True
|
|
144
|
+
)
|
|
145
|
+
import akshare as ak
|
|
146
|
+
df = ak.fund_etf_hist_em()
|
|
147
|
+
|
|
148
|
+
###### 2. 禁用插件
|
|
149
|
+
akshare_proxy_patch.uninstall_patch()
|
|
150
|
+
|
|
151
|
+
# 禁用后测试
|
|
152
|
+
try:
|
|
153
|
+
df = ak.fund_etf_hist_em()
|
|
154
|
+
except Exception as e:
|
|
155
|
+
print('插件被禁用了,这里可能会报错')
|
|
156
|
+
|
|
157
|
+
##### 3. 再次启用插件,重复上述 1、2 的代码即可
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## 我没使用 akshare 或 efinance,能集成插件吗?
|
|
161
|
+
|
|
162
|
+
- 如果使用 Python 语言的 `requests` 库请求接口,插件能自动 hook 住请求,正常工作。
|
|
163
|
+
- 如果您使用其他语言或 python 的其他库,可 [手动提取代理](http://101.201.173.125:47001/api/akshare-auth?token=XXX&version=0.5.0) 自行实现封控解除。
|
|
164
|
+
|
|
165
|
+
## 使用问题交流群
|
|
166
|
+
|
|
167
|
+
如使用时遇到问题,或对插件有什么意见或建议,可进群交流:
|
|
168
|
+
|
|
169
|
+

|
|
@@ -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):
|
|
@@ -69,7 +88,13 @@ default_hook_domains = [
|
|
|
69
88
|
|
|
70
89
|
|
|
71
90
|
def install_patch(
|
|
72
|
-
auth_ip,
|
|
91
|
+
auth_ip,
|
|
92
|
+
auth_token="",
|
|
93
|
+
retry=30,
|
|
94
|
+
hook_domains=default_hook_domains,
|
|
95
|
+
timeout=5,
|
|
96
|
+
cookie="",
|
|
97
|
+
fast=True,
|
|
73
98
|
):
|
|
74
99
|
# --- 核心改进:备份原始 Session 避开递归死循环 ---
|
|
75
100
|
if not hasattr(std_requests, "_OriginalSession"):
|
|
@@ -106,7 +131,7 @@ def install_patch(
|
|
|
106
131
|
continue
|
|
107
132
|
|
|
108
133
|
headers = kwargs.get("headers") or {}
|
|
109
|
-
headers["
|
|
134
|
+
headers["Cookie"] = cookie or auth_res.get("cookie", "")
|
|
110
135
|
kwargs["headers"] = headers
|
|
111
136
|
kwargs["proxies"] = {
|
|
112
137
|
"http": auth_res["proxy"],
|
|
@@ -155,6 +180,95 @@ def install_patch(
|
|
|
155
180
|
curl_requests.get = patched_get
|
|
156
181
|
curl_requests.post = patched_post
|
|
157
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
|
+
|
|
158
272
|
|
|
159
273
|
def install_yfinance_patch(
|
|
160
274
|
auth_ip, auth_token="", retry=30, hook_domains=["finance.yahoo.com"]
|
|
@@ -162,3 +276,20 @@ def install_yfinance_patch(
|
|
|
162
276
|
from .yfinance import install_yfinance_patch_main
|
|
163
277
|
|
|
164
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
|