Skip to main content

针对 AkShare 和 efinance 的底层补丁,自动为东财等接口注入代理认证头,从而避免 `stock_zh_a_spot_em` 等方法报错。

Project description

AkShare Proxy Patch

针对 akshareefinanceyfinance 的🐒插件补丁,解决 stock_zh_a_spot_emstock_zh_a_histget_realtime_quotes 等接口报错问题和 Yahoo YFRateLimitError 问题。

✨ 特性

  • 解决 akshare 接口报错问题
  • 解决 efinance 接口报错问题
  • 解决 yfinance Yahoo接口报错问题

📦 安装

  1. 安装并升级官方 akshareefinance

  2. 安装 akshare-proxy-patch 插件

pip install akshare-proxy-patch==0.4.1

🚀 使用方法(akshare / efinance / yfinance)

  1. 点击前往插件官网 获取 TOKEN

  2. akshareefinance 用户:在 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()
  1. 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 包含数组中的其中一条,就会走插件。
    • 可点击 akef 函数查看接口源码对应的 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 的其他库,可 手动提取代理 自行实现封控解除。

💬 使用问题交流群

如使用时遇到问题,或对插件有什么意见或建议,可进群交流:

Knfv1JVAEBWyuaZc79CJKJALR7BVUgpH.webp

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

akshare_proxy_patch-0.4.1.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

akshare_proxy_patch-0.4.1-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file akshare_proxy_patch-0.4.1.tar.gz.

File metadata

  • Download URL: akshare_proxy_patch-0.4.1.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for akshare_proxy_patch-0.4.1.tar.gz
Algorithm Hash digest
SHA256 ffbcd1ed71fee959e8f6e75e123aec22a3a5230ea5ed398d62aa746e8ba3ef43
MD5 76eefdff74e6a159e44aa9cc1eb0e434
BLAKE2b-256 7319f9380062399149d07114d3cc8a37859c4199b010bce7bab81689b098ae4b

See more details on using hashes here.

File details

Details for the file akshare_proxy_patch-0.4.1-py3-none-any.whl.

File metadata

File hashes

Hashes for akshare_proxy_patch-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 719353778ab08dcc2c93056a329e99dd6d5968491cd77dcb20ba3ea21949230e
MD5 9a17976e0d2c569e04b674c3ddda4750
BLAKE2b-256 7389516b1a90dae2334a7c0c35b9f672267c8cff74b78f7c11a0c8fdf0269993

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page