ccxt / ccxt

A JavaScript / TypeScript / Python / C# / PHP cryptocurrency trading API with support for more than 100 bitcoin/altcoin exchanges
https://docs.ccxt.com
MIT License
31.94k stars 7.38k forks source link

Assistance Needed for Testing Trading Bot on Binance Futures Testnet #22978

Open Papci opened 3 days ago

Papci commented 3 days ago

Operating System

Windows 11

Programming Languages

Python

CCXT Version

No response

Description

Hello ccxt Team,

I have developed a trading bot using ccxt for Binance Futures. Before deploying it in a live environment, I intend to test the bot on Binance's testnet. I have created an account on the Binance Futures testnet (URL: https://testnet.binancefuture.com/en/futures/BTCUSDT) and am using the API Key and API Secret from this testnet account.

However, every time I run my trading_bot.py script, I encounter the following error:

ccxt.base.errors.AuthenticationError: binance {"code":-2008,"msg":"Invalid Api-Key ID."}

The bot is designed to handle both real and test API keys. I have added debug prints to verify which 'MODE' is being used, and it confirms that the test API keys are being utilized. Yet, somehow the requests are still being sent to the live API endpoint (https://api.binance.com).

The relevant part of my code can be found in the code box.

I have tested the code with various URLs such as 'https://testnet.binance.vision/api', 'https://testnet.binance.vision', and 'https://testnet.binancefuture.com/', but the result is always the same.

Could you please confirm if this code snippet is correct? Additionally, what is the appropriate URL to use for the Binance Futures testnet (https://testnet.binancefuture.com/en/futures/BTCUSDT)?

Code

from config import SYMBOLS, TIMEFRAME, WINDOW, STD_DEV, LEVERAGE, API_KEY, API_SECRET, TEST_API_KEY, TEST_API_SECRET, MODE import ccxt

print(f"Config MODE: {MODE}") print(f"Current MODE: {MODE}")

def get_exchange(): if MODE == 'live': print("Using live API keys") return ccxt.binance({ 'apiKey': API_KEY, 'secret': API_SECRET, 'enableRateLimit': True, 'options': { 'defaultType': 'future', } }) else: print("Using test API keys") return ccxt.binance({ 'apiKey': TEST_API_KEY, 'secret': TEST_API_SECRET, 'enableRateLimit': True, 'options': { 'defaultType': 'future', }, 'urls': { 'api': { 'public': 'https://testnet.binance.vision/api', 'private': 'https://testnet.binance.vision/api' }, 'www': 'https://testnet.binance.vision', 'doc': 'https://testnet.binance.vision/doc', 'fees': 'https://testnet.binance.vision/fees' } })

exchange = get_exchange()

  

sc0Vu commented 3 days ago

Hi @Papci You need to call set_sandbox_mode (True) to switch to sandbox APIs. You can also set verbose to True to see which requests are sent to live API.