#26487Binance Futures Testnet private API calls routed to Live Spot API (Invalid Api-Key ID)
Issue Details
Operating System
Windows 11 Pro
Programming Languages
Python
CCXT Version
4.4.95
Description
Absolut! Da dein Englisch nicht so gut ist, helfe ich dir gerne dabei, eine präzise und verständliche Problembeschreibung für das CCXT GitHub Issue zu formulieren. Hier ist ein Entwurf, den du kopieren und einfügen kannst. Ich habe alle wichtigen Punkte berücksichtigt, die wir besprochen haben:
Title: Binance Futures Testnet private API calls routed to Live Spot API (Invalid Api-Key ID)
Body:
Hello CCXT team,
I am experiencing an issue when trying to connect to the Binance Futures Testnet using the CCXT library.
Problem Description: My goal is to trade on the Binance Futures Testnet.
Public API calls work correctly: I can successfully fetch the server time (exchange.fetch_time()) from the Futures Testnet API. The verbose output confirms that this request correctly goes to https://fapi.binance.com/fapi/v1/time.
Private API calls fail and are misrouted: When I try to make private API calls, such as exchange.fetch_balance(params={'type': 'future'}) or exchange.fetch_positions(['BTCUSDT']), the request is incorrectly sent to the Binance Live Spot API domain (https://api.binance.com/sapi/v1/capital/config/getall) instead of the Futures Testnet API (https://testnet.binancefuture.com/fapi/v1).
Error received: The request to the incorrect endpoint then returns an HTTP 400 Bad Request with the error message: {"code":-2008,"msg":"Invalid Api-Key ID."}.
What I have confirmed:
API Keys: My API keys (API Key and Secret Key) are correctly generated from and belong to the Binance Futures Testnet (https://testnet.binancefuture.com/). I have double-checked this on the official Futures Testnet website.
CCXT Version: I am using the latest stable version of CCXT, 4.4.95.
Code Configuration: My code explicitly sets defaultType: 'future', setSandboxMode: True, and attempts to override the urls with https://testnet.binancefuture.com/fapi/v1 for fapi, fapiPublic, fapiPrivate, and general api, public, private keys, to ensure proper routing.
Expected Behavior: Private API calls for the Futures Testnet should be routed to https://testnet.binancefuture.com/fapi/v1/... and authenticate successfully with the provided Futures Testnet API keys.
Steps to Reproduce:
Obtain API keys from https://testnet.binancefuture.com/.
Set up a .env file with BINANCE_TESTNET_API_KEY and BINANCE_TESTNET_SECRET_KEY.
Run the provided Python code.
Environment:
Python version: (Bitte hier deine Python-Version angeben, z.B. Python 3.9.7)
Operating System: (Bitte hier dein Betriebssystem angeben, z.B. Windows 10)
CCXT Version: 4.4.95
Code
from dotenv import load_dotenv import ccxt load_dotenv() exchange = ccxt.binance({ 'apiKey': os.getenv('BINANCE_TESTNET_API_KEY'), 'secret': os.getenv('BINANCE_TESTNET_SECRET_KEY'), 'enableRateLimit': True, 'options': { 'defaultType': 'future', 'adjustForTimeDifference': True, 'urls': { 'fapi': 'https://testnet.binancefuture.com/fapi/v1', 'fapiPublic': 'https://testnet.binancefuture.com/fapi/v1', 'fapiPrivate': 'https://testnet.binancefuture.com/fapi/v1', 'api': 'https://testnet.binancefuture.com/fapi/v1', # Overriding for general API too 'public': 'https://testnet.binancefuture.com/fapi/v1', 'private': 'https://testnet.binancefuture.com/fapi/v1', } }, 'setSandboxMode': True, 'verbose': True, # For detailed logging }) def test_connection(): try: print("\n1. Teste öffentliche API (ohne Key)...") print("Serverzeit:", exchange.fetch_time()) # Testing fetch_balance (which failed) # print("\n2. Teste private API (mit Key)...") # balance = exchange.fetch_balance(params={'type': 'future'}) # print("Kontostand:", balance['USDT']['total']) print("\n3. Teste Positionsabfrage (Futures-spezifisch)...") positions = exchange.fetch_positions(['BTCUSDT']) print("Positionen:", len(positions)) except Exception as e: print("FEHLER:", str(e)) if __name__ == "__main__": test_connection()