ccxt connection with api fails
08:46 11 Jun 2026

I am trying to build a trading bot in Python using CCXT as a learning project. However, I have encountered a problem when attempting to connect to Bybit's Testnet API.

The following code:

import ccxt
import json

apiKey = "abc"
secret = "abc123"

exchange = ccxt.bybit({
    'apiKey': apiKey,
    'secret': secret,
    'testnet': True,
    'options': {
        'defaultType': 'swap'  # perpetual futures
    }
})

try:
    # Private endpoint test
    balance = exchange.fetch_balance()
    usdt = balance['USDT']['total']
    print(f"USDT balance: {usdt}")

except ccxt.AuthenticationError as e:
    print(f"Auth error: {e}")

returns the following error:

Auth error: bybit {"retCode":10003,"retMsg":"API key is invalid.","result":{},"retExtInfo":{},"time":1781185798622}

I am certain that I am using my Testnet API key and secret, which were generated from the Bybit Testnet environment.

Has anyone encountered this issue before? Am I missing a required CCXT setting, or is there a specific way to configure Bybit Testnet credentials for futures trading?

python ccxt bybit