针对 AkShare 和 efinance 的底层补丁,自动为东财等接口注入代理认证头,从而避免 `stock_zh_a_spot_em` 等方法报错。
Project description
AkShare Proxy Patch
针对 akshare、efinance、yfinance 的🐒插件补丁,解决
stock_zh_a_spot_em、stock_zh_a_hist、get_realtime_quotes等接口报错问题和 YahooYFRateLimitError问题。
✨ 特性
- 解决
akshare接口报错问题 - 解决
efinance接口报错问题 - 解决
yfinanceYahoo接口报错问题
📦 安装
pip install akshare-proxy-patch==0.4.1
🚀 使用方法(akshare / efinance / yfinance)
-
点击前往插件官网 获取
TOKEN。 -
akshare或efinance用户:在 Python 文件顶部添加如下代码,并替换你的TOKEN。调用非常简单,不需要使用 AI 魔改。
# python 文件顶部添加如下代码
import akshare_proxy_patch
akshare_proxy_patch.install_patch(
"101.201.173.125",
auth_token="你的TOKEN",
retry=30,
# 封控的域名列表,可自行调整
hook_domains=[
"fund.eastmoney.com",
"push2.eastmoney.com",
"push2his.eastmoney.com",
"emweb.securities.eastmoney.com",
],
)
# --------------------------
# 后续你的正常业务代码保持不变
# --------------------------
# 假如你使用 akshare
import akshare as ak
df = ak.stock_zh_a_spot_em()
# 假如你使用 efinance
import efinance as ef
ef.stock.get_realtime_quotes()
yfinance用户:在 Python 文件顶部添加如下代码,并替换你的TOKEN。调用非常简单,不需要使用 AI 魔改。
# python 文件顶部添加如下代码
import akshare_proxy_patch
akshare_proxy_patch.install_yfinance_patch(
"101.201.173.125",
auth_token="你的TOKEN",
retry=30,
)
# --------------------------
# 后续你的正常业务代码保持不变
# --------------------------
import yfinance as yf
data = yf.download("AAPL", start="2017-01-01", end="2017-04-30")
📖 install_patch 参数说明
- 参数1:网关
- 默认为
101.201.173.125不可修改
- 默认为
- 参数2:TOKEN
- 授权凭证
- 参数3:重试次数
- 默认为30,建议保持不变
- 参数4:封控的域名列表
- 接口
URL包含数组中的其中一条,就会走插件。 - 可点击
ak或ef函数查看接口源码对应的URL,根据封控情况细化可以降低积分消耗。 - 如只封控
stock_zh_a_spot_em这个接口,hook_domains可设置为["https://82.push2.eastmoney.com/api/qt/clist/get"]。
- 接口
🛠️ 如何在 aktools 内集成插件?
aktools 想要集成插件,需要新建一个 akt.py 替换官方的 python -m aktools 启动命令,下面是 akt.py 内容:
# 添加插件
import akshare_proxy_patch
akshare_proxy_patch.install_patch(
"101.201.173.125",
auth_token="你的TOKEN",
retry=30,
# 封控的域名列表,可自行调整
hook_domains=[
"fund.eastmoney.com",
"push2.eastmoney.com",
"push2his.eastmoney.com",
"emweb.securities.eastmoney.com",
],
)
# 启动 aktools
import uvicorn
if __name__ == '__main__':
uvicorn.run(
"aktools.main:app",
host="0.0.0.0",
port=8080,
reload=False,
# 根据 CPU 核心数调整,推荐 2×核心数 + 1
workers=4,
log_level="info"
)
然后执行 python akt.py 即可启动一个 http://127.0.0.1:8080/ 服务。只是启动方式不同而已,使用请参考 aktools 官方文档。
❓ 我没使用 akshare 或 efinance,能集成插件吗?
- 如果使用 Python 语言的
requests库请求接口,插件能自动 hook 住请求,正常工作。 - 如果您使用其他语言或 python 的其他库,可 手动提取代理 自行实现封控解除。
💬 使用问题交流群
如使用时遇到问题,或对插件有什么意见或建议,可进群交流:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters