Skip to main content

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

Project description

AkShare Proxy Patch

针对 akshareefinance 的插件补丁,自动为接口注入请求头,解决 stock_zh_a_spot_emstock_zh_a_histget_realtime_quotes 等东财接口报错问题。

安装

  1. 安装好官方 akshareefinance

  2. 安装 akshare-proxy-patch 插件

pip install akshare-proxy-patch==0.2.13

使用方法

akshareefinance 使用方式一致,在文件顶部添加2行代码即可,无需其他额外操作。

# python 文件顶部添加如下代码
import akshare_proxy_patch

akshare_proxy_patch.install_patch(
    "101.201.173.125",
    auth_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()

install_patch 参数说明

  • 参数1:网关
    • 默认为 101.201.173.125 不可修改
  • 参数2:TOKEN
    • 默认为空,每天可免费使用一定次数。如有更多需求,可点击此处注册申请正式的 TOKEN
  • 参数3:重试次数
    • 默认为30,建议保持不变
  • 参数4:需要hook的域名列表
    • 接口URL包含列表内任意一条域名都会走代理,可以根据封控情况调整或细化以降低积分消耗
    • 如只封控 stock_zh_a_spot_em 这个接口,hook_domains=["https://82.push2.eastmoney.com/api/qt/clist/get"] 即可(点击函数查看接口源码找到对应域名)

如何在 aktools 内集成插件?

需要新建一个 akt.py 替换官方的启动方式:

# 添加插件
import akshare_proxy_patch

akshare_proxy_patch.install_patch(
    "101.201.173.125",
    auth_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 即可启动并正常使用 aktools

我是手动爬取的接口,能集成插件吗?

能。如果您没有使用 akshareefinance,而是手动调用的接口,只要代码是使用的 requests,插件都能 hook 住请求,正常工作。

使用问题交流群

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

hx8knYwcWWnRjaPzHuWPXajFougAeGc6.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.2.13.tar.gz (4.8 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.2.13-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: akshare_proxy_patch-0.2.13.tar.gz
  • Upload date:
  • Size: 4.8 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.2.13.tar.gz
Algorithm Hash digest
SHA256 9d95cefad10680e08ecad28bff0d0e3e406f281a7cf44b71d77b8c6026fc3e19
MD5 73219862d73a8deb46beaa76fd5ce667
BLAKE2b-256 4b786b22f9c595863aab05c57f6545858d2163310971135675c2bf7d1b8c5e8d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for akshare_proxy_patch-0.2.13-py3-none-any.whl
Algorithm Hash digest
SHA256 d9cdcd42ffbfc0497433646e9de33f4fa7b286130e677c0c134c00600b37c281
MD5 d30d85de4121d0e2997639916da29a9c
BLAKE2b-256 a549df0b27c28f97cd6d6e56dc6fd79b18709ed3709a26e372216af88c148700

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