Skip to main content

AkShare Proxy Patch

针对 akshare、efinance、yfinance、aktools、daily_stock_analysis 的🐒插件补丁,解决 stock_zh_a_spot_em、stock_zh_a_hist、get_realtime_quotes 等东财接口报错问题和 Yahoo YFRateLimitError 问题。并对 akshare 部分接口进行多线程加速处理。

✨ 特性

  • 解决 akshare 或 aktools 的 stock_zh_a_spot_em、stock_zh_a_hist 接口报错问题
  • 解决 efinance 的 get_realtime_quotes 等接口报错问题
  • 解决 yfinance Yahoo接口国内无法使用问题
  • 解决 daily_stock_analysis 的数据获取报错问题
  • 多线程加速 stock_zh_a_spot_em 等 akshare 接口

📦 安装

  1. 安装并升级官方 akshare 或 efinance 包

  2. 安装 akshare-proxy-patch 插件

pip install akshare-proxy-patch==0.5.1

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

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

  2. akshare 或 efinance 用户:在 Python 文件最顶部 添加如下代码,并替换 你的TOKEN。

# python 文件顶部添加如下代码
# 重要:插件引入和调用一定要放到最顶部!不能在 akshare 或 efinance 之后引入!

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",
      "searchapi.eastmoney.com/api/suggest/get",
      "push2delay.eastmoney.com/api/qt/clist/get"
    ],
    fast=True
)

# --------------------------
# 后续你的业务代码保持不变
# --------------------------

# 假如你使用 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 文件顶部添加如下代码
# 重要:插件引入和调用一定要放到最顶部!不能在 akshare 或 efinance 之后引入!

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")
  1. 尽量用 efinance 替代 akshare 的部分函数配合插件获取数据,效率更高,更省积分。

install_patch 参数说明

  • ip
    • 网关,不可修改
  • auth_token
    • TOKEN 授权凭证
  • retry
    • 重试次数,默认为30,建议保持不变
  • hook_domains
    • 封控的域名列表,插件会 hook 住这些域名的请求,解除封控。已默认涵盖常见函数的域名。
    • 可点击 akshare 或 efinance 函数查看接口源码对应的 URL 并添加到该列表。
    • 如只用到 stock_zh_a_spot_em 这个接口,hook_domains 可设置为 ["https://82.push2.eastmoney.com/api/qt/clist/get"]。
  • fast
    • 是否启用 akshare 多线程加速,默认开启,加速函数列表如下
    • 所有用到 fetch_paginated_data 分页函数的接口,如 stock_zh_a_spot_em、stock_sh_a_spot_em、stock_board_industry_cons_em 等

如何在 aktools 内集成插件?

  • aktools 想要集成插件,需下载 akt.py 文件,并填入您的 TOKEN。
  • 然后执行 python akt.py 即可启动一个 http://127.0.0.1:8080/ 服务。只是启动方式不同而已,使用请参考 aktools 官方文档。

如何在 daily_stock_analysis 内集成插件?

  • daily_stock_analysis 本身集成了 akshare、efinance 等数据源,如遇数据源报错,可以通过引入插件来解决。
  • 在 daily_stock_analysis 项目中,找到入口 Python 文件 main.py,在文件顶部引入插件:
# 找到 daily_stock_analysis main.py 的这行(第一行)代码,在其下方引入插件
from __future__ import annotations

# 引入插件
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",
      "searchapi.eastmoney.com/api/suggest/get",
      "push2delay.eastmoney.com/api/qt/clist/get"
    ],
    fast=True
)
# daily_stock_analysis main.py 的其他后续代码
# 插件引入成功后正常启动该项目即可

股票数量很多,如何快速拉取数据?

  • 尽量使用 efinance 替代 akshare 来获取数据, efinance 内置多线程,效率更高,更省积分。
  • 在大规模快速获取数据时,可使用多进程提升效率。 可以参考 多进程获取所有股票的历史K线,修改 auth_token,执行 python main.py 测试。

如何灵活禁用/启用插件?

加入如下代码后插件就会被禁用,点击查看禁用/启用插件示例:

akshare_proxy_patch.uninstall_patch()

我没使用 akshare 或 efinance,能集成插件吗?

  • 如果使用 Python 语言的 requests 库请求接口,插件能自动 hook 住请求,正常工作。
  • 如果您使用其他语言或 python 的其他库,可 手动提取代理 自行实现封控解除。

使用问题交流群

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

eozuhg3eH48ntnAnZXjKpmiegT7Ws0cl.webp

Metadata

Release files for akshare-proxy-patch 0.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for akshare-proxy-patch 0.5.1
File Size Uploaded Provenance Actions
akshare_proxy_patch-0.5.1.tar.gz 11.7 kB Without provenance Details for akshare_proxy_patch-0.5.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for akshare-proxy-patch 0.5.1
File Interpreter ABI Platform Actions
akshare_proxy_patch-0.5.1-py3-none-any.whl Python 3 none any Details for akshare_proxy_patch-0.5.1-py3-none-any.whl

Total release size: 23.4 kB

Release files / akshare_proxy_patch-0.5.1.tar.gz

Download URL akshare_proxy_patch-0.5.1.tar.gz
Size 11.7 kB
Tags Source
SHA-256 checksum
How to use checksums
4d6c61af27eb27b0104ef997f8da690c592f98f183ff0287289be6f1a0fd43cb
BLAKE2b-256 checksum
How to use checksums
2fdf598a23b277bfdba68b107d69abfb4394b4a508841cc6c8fb05269d87fe46
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.12

Release files / akshare_proxy_patch-0.5.1-py3-none-any.whl

Download URL akshare_proxy_patch-0.5.1-py3-none-any.whl
Size 11.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4435cfd62c6a1a17ccf49ff1ccaffb0cc8d74f83c16b5e226b0ca8a81b411639
BLAKE2b-256 checksum
How to use checksums
761c922d0489bbcb99d545d7c8424fade8c3ef1d8f3d7f6140be93df94837d75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.12

Security for akshare-proxy-patch 0.5.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page