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

Binance期货测试网API报错-2015:密钥/IP/权限问题求助

解决Binance测试网APIError(code=-2015)问题

你的代码:

from binance import Client

api_key = api_key
api_secret = api_secret

def main():
    client = Client(api_key, api_secret, testnet=True)

    info = client.get_account()
    print(info)

if __name__ == "__main__":
    main()

报错信息:

binance.exceptions.BinanceAPIException: APIError(code=-2015): Invalid API-key, IP, or permissions for action.

排查及解决方案:

  • 接口不匹配是核心问题:你使用的是期货测试网,但get_account()是现货账户查询接口,期货测试网无法用这个接口获取数据。要查询期货测试网账户,需改用期货相关接口:
    from binance import Client
    
    # 替换成你真实的期货测试网API密钥
    api_key = "YOUR_FUTURES_TESTNET_API_KEY"
    api_secret = "YOUR_FUTURES_TESTNET_API_SECRET"
    
    def main():
        client = Client(api_key, api_secret, testnet=True)
        # 使用期货账户查询接口
        futures_account_info = client.futures_account()
        print(futures_account_info)
    
    if __name__ == "__main__":
        main()
    
    或者直接使用期货专用客户端:
    from binance.futures import FuturesClient
    
    api_key = "YOUR_FUTURES_TESTNET_API_KEY"
    api_secret = "YOUR_FUTURES_TESTNET_API_SECRET"
    
    def main():
        futures_client = FuturesClient(api_key, api_secret, testnet=True)
        account_info = futures_client.get_account()
        print(account_info)
    
    if __name__ == "__main__":
        main()
    
  • 验证API权限:登录Binance测试网后台,检查你创建的API是否开启了期货相关权限(如“期货账户查询”“期货交易”),现货权限无法访问期货接口。
  • 检查IP白名单:如果API设置了IP白名单,确保当前运行代码的IP在白名单列表中,测试网同样会校验IP白名单。
  • 确认密钥归属:Binance现货测试网和期货测试网的API密钥是独立的,务必确认你使用的是期货测试网生成的密钥,别和现货测试网密钥搞混。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 19:31:22