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.0

🚀 使用方法(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 的其他库,可 手动提取代理 自行实现封控解除。

💬 使用问题交流群

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

YpRjixvpykLmzPtrX0kIkdPlvffOFJvF.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.0.tar.gz (6.3 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.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: akshare_proxy_patch-0.4.0.tar.gz
  • Upload date:
  • Size: 6.3 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.0.tar.gz
Algorithm Hash digest
SHA256 e0c9aca5d85c6679476d86cab3fcab240ff95a304d068ffb16cb538b81322b47
MD5 acec6be663e6daaa63928160f75de0fe
BLAKE2b-256 375d20f5cfdfd9ab050ebb6be8994496e5798fc8acc464672fd0ccc369d252bf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for akshare_proxy_patch-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 917365a14b89bb2a6d35bc2f082f5aa04184fba19741e39084b3d57310051236
MD5 67602f7be568663b956f7cce114c55a2
BLAKE2b-256 30ffea2517b3edc1ca0594584fa7adc06328010e696628e671bd2736305b377f

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