You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Python中通过VPN连接获取Binance国际版API数据?

解决方案建议

1. 调用主流VPN的官方CLI工具(Python通过系统命令触发)

很多VPN服务都提供了OSX平台的命令行工具,你可以用Python的subprocess模块直接调用这些工具实现连接,无需专门的Python包:

  • NordVPN CLI
    先通过Homebrew安装:brew install nordvpn,终端登录账号后nordvpn login,再用Python调用:

    import subprocess
    import binance
    
    # 连接爱尔兰节点
    subprocess.run(["nordvpn", "connect", "ireland"], check=True)
    
    # 执行Binance API操作
    client = binance.Client(api_key=API_KEY, api_secret=API_SECRET)
    transactions = client.get_account_trades()
    for trade in transactions:
        print(trade)
    
    # 操作完成后断开VPN
    subprocess.run(["nordvpn", "disconnect"])
    
  • ExpressVPN CLI
    官网下载DMG安装后,终端执行expressvpn activate激活账号,Python调用示例:

    import subprocess
    import binance
    
    # 连接爱尔兰节点
    subprocess.run(["expressvpn", "connect", "ireland"], check=True)
    
    # Binance API操作...
    
    subprocess.run(["expressvpn", "disconnect"])
    

2. 第三方Python封装的VPN工具

部分第三方库封装了VPN CLI的操作逻辑,比如nordvpn_switcher(支持OSX),可以简化代码:

from nordvpn_switcher import initialize_VPN, rotate_VPN, close_VPN
import binance

# 初始化配置(首次运行需完成账号设置)
initialize_VPN(save=1, area_input=['ireland'])
# 连接爱尔兰节点
rotate_VPN()

# Binance API操作...

# 关闭VPN连接
close_VPN()

注:这类库本质还是依赖官方CLI,需先安装对应VPN的命令行工具。

3. 代理替代方案

如果不想使用VPN,可配置爱尔兰地区的HTTP/SOCKS代理,让Binance客户端通过代理请求:

import binance

client = binance.Client(
    api_key=API_KEY,
    api_secret=API_SECRET,
    requests_params={'proxies': {
        'https': 'https://your-irish-proxy-address:port',
        'http': 'http://your-irish-proxy-address:port'
    }}
)

transactions = client.get_account_trades()
for trade in transactions:
    print(trade)

该方式无需VPN,但需要稳定安全的代理服务支持。


内容的提问来源于stack exchange,提问作者jd_h2003

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 00:37:31