Exchange management provides core functionality for creating and configuring exchange instances. CCXT supports over 100 cryptocurrency exchanges with a unified API interface.
Create instances of specific exchange classes with configuration options for API credentials, sandbox mode, and connection settings.
/**
* Create a new exchange instance
* @param config - Exchange configuration options
*/
constructor(config?: ExchangeOptions);
interface ExchangeOptions {
/** API key for authenticated requests */
apiKey?: string;
/** API secret for request signing */
secret?: string;
/** Additional password/passphrase (required by some exchanges) */
password?: string;
/** User ID (required by some exchanges) */
uid?: string;
/** Login username (legacy, rarely used) */
login?: string;
/** Private key for wallet-based authentication */
privateKey?: string;
/** Wallet address for wallet-based authentication */
walletAddress?: string;
/** Bearer token (for OAuth-based exchanges) */
token?: string;
/** Enable sandbox/testnet mode */
sandbox?: boolean;
/** Request timeout in milliseconds (default: 10000) */
timeout?: number;
/** Minimum delay between requests in milliseconds */
rateLimit?: number;
/** Enable automatic rate limiting (default: true) */
enableRateLimit?: boolean;
/** Custom User-Agent string */
userAgent?: string;
/** Custom HTTP headers */
headers?: { [key: string]: string };
/** HTTP proxy URL */
proxy?: string;
/** HTTPS proxy URL */
httpsProxy?: string;
/** SOCKS proxy URL */
socksProxy?: string;
/** Verbose logging mode */
verbose?: boolean;
/** Custom request options */
options?: { [key: string]: any };
}Usage Examples:
import ccxt from '@iam4x/ccxt';
// Create exchange instance with API credentials
const exchange = new ccxt.binance({
apiKey: 'your-api-key',
secret: 'your-secret',
sandbox: true, // Use testnet
enableRateLimit: true,
});
// Configure with additional options
const krakenExchange = new ccxt.kraken({
apiKey: 'your-api-key',
secret: 'your-secret',
timeout: 30000, // 30 second timeout
rateLimit: 1000, // 1 second between requests
headers: {
'Custom-Header': 'custom-value'
},
proxy: 'http://proxy-server:8080'
});
// Public-only access (no credentials needed)
const publicExchange = new ccxt.coinbase({
sandbox: false
});Access exchange metadata, capabilities, and configuration details.
/** Exchange identifier string */
readonly id: string;
/** Exchange display name */
readonly name: string;
/** List of countries where exchange is based */
readonly countries: string[];
/** Exchange version string */
readonly version: string;
/** URLs for various exchange endpoints */
readonly urls: {
logo: string;
api: string | { [key: string]: string };
www: string;
doc: string | string[];
fees?: string;
};
/** Exchange capabilities and supported features */
readonly has: ExchangeCapabilities;
/** Trading fees structure */
readonly fees: {
trading: {
maker: number;
taker: number;
percentage: boolean;
tierBased: boolean;
};
funding?: {
withdraw: { [currency: string]: number };
deposit: { [currency: string]: number };
};
};
/** Rate limiting configuration */
readonly rateLimit: number;
/** API endpoints configuration */
readonly api: { [key: string]: any };
/** Timeframes supported for OHLCV data */
readonly timeframes: { [key: string]: string };
/** Exchange status information */
fetchStatus(params?: Dict): Promise<{
status: 'ok' | 'shutdown' | 'error' | 'maintenance';
updated: number;
eta?: number;
url?: string;
}>;
interface ExchangeCapabilities {
CORS?: boolean;
spot?: boolean;
margin?: boolean;
swap?: boolean;
future?: boolean;
option?: boolean;
addMargin?: boolean;
cancelAllOrders?: boolean;
cancelOrder?: boolean;
cancelOrders?: boolean;
createDepositAddress?: boolean;
createLimitOrder?: boolean;
createMarketOrder?: boolean;
createOrder?: boolean;
deposit?: boolean;
editOrder?: boolean;
fetchBalance?: boolean;
fetchClosedOrders?: boolean;
fetchCurrencies?: boolean;
fetchDepositAddress?: boolean;
fetchDeposits?: boolean;
fetchMarkets?: boolean;
fetchMyTrades?: boolean;
fetchOHLCV?: boolean;
fetchOpenOrders?: boolean;
fetchOrder?: boolean;
fetchOrderBook?: boolean;
fetchOrders?: boolean;
fetchStatus?: boolean;
fetchTicker?: boolean;
fetchTickers?: boolean;
fetchTime?: boolean;
fetchTrades?: boolean;
fetchTradingFee?: boolean;
fetchTradingFees?: boolean;
fetchWithdrawals?: boolean;
reduceMargin?: boolean;
setLeverage?: boolean;
setMargin?: boolean;
setMarginMode?: boolean;
setPositionMode?: boolean;
signIn?: boolean;
withdraw?: boolean;
}Usage Examples:
// Check exchange capabilities
const exchange = new ccxt.binance();
console.log('Exchange ID:', exchange.id);
console.log('Exchange Name:', exchange.name);
console.log('Countries:', exchange.countries);
console.log('Supports spot trading:', exchange.has.spot);
console.log('Supports futures:', exchange.has.future);
console.log('Supports WebSocket:', exchange.has.ws);
// Check if specific features are supported
if (exchange.has.fetchOHLCV) {
const candles = await exchange.fetchOHLCV('BTC/USDT', '1h');
}
if (exchange.has.createOrder) {
// Exchange supports order creation
}
// Get exchange status
const status = await exchange.fetchStatus();
console.log('Exchange status:', status.status);CCXT provides access to 100+ cryptocurrency exchanges through individual classes.
// Major exchanges (most commonly used)
class binance extends Exchange { }
class binanceus extends Exchange { }
class binancecoinm extends Exchange { } // Coin-M futures
class binanceusdm extends Exchange { } // USD-M futures
class coinbase extends Exchange { }
class coinbaseadvanced extends Exchange { }
class kraken extends Exchange { }
class krakenfutures extends Exchange { }
class okx extends Exchange { }
class bybit extends Exchange { }
class bitmex extends Exchange { }
class huobi extends Exchange { } // Now HTX
class gateio extends Exchange { }
class kucoin extends Exchange { }
class kucoinfutures extends Exchange { }
class mexc extends Exchange { }
// Additional exchanges (85+ more available)
class alpaca extends Exchange { }
class apex extends Exchange { }
class ascendex extends Exchange { }
class bequant extends Exchange { }
class bigone extends Exchange { }
class bingx extends Exchange { }
class bit2c extends Exchange { }
class bitbank extends Exchange { }
class bitbns extends Exchange { }
class bitfinex extends Exchange { }
class bitflyer extends Exchange { }
class bitget extends Exchange { }
class bithumb extends Exchange { }
class bitmart extends Exchange { }
class bitopro extends Exchange { }
class bitrue extends Exchange { }
class bitso extends Exchange { }
class bitstamp extends Exchange { }
class bitteam extends Exchange { }
class bittrade extends Exchange { }
class bitvavo extends Exchange { }
class blockchaincom extends Exchange { }
class blofin extends Exchange { }
class btcalpha extends Exchange { }
class btcbox extends Exchange { }
class btcmarkets extends Exchange { }
class btcturk extends Exchange { }
class cex extends Exchange { }
class coincatch extends Exchange { }
class coincheck extends Exchange { }
class coinex extends Exchange { }
class coinmate extends Exchange { }
class coinmetro extends Exchange { }
class coinone extends Exchange { }
class coinsph extends Exchange { }
class coinspot extends Exchange { }
class cryptocom extends Exchange { }
class cryptomus extends Exchange { }
class defx extends Exchange { }
class delta extends Exchange { }
class deribit extends Exchange { }
class derive extends Exchange { }
class digifinex extends Exchange { }
class exmo extends Exchange { }
class fmfwio extends Exchange { }
class foxbit extends Exchange { }
class gate extends Exchange { }
class gemini extends Exchange { }
class hashkey extends Exchange { }
class hibachi extends Exchange { }
class hitbtc extends Exchange { }
class hollaex extends Exchange { }
class htx extends Exchange { }
class hyperliquid extends Exchange { }
class independentreserve extends Exchange { }
class indodax extends Exchange { }
class latoken extends Exchange { }
class lbank extends Exchange { }
class luno extends Exchange { }
class mercado extends Exchange { }
class modetrade extends Exchange { }
class myokx extends Exchange { }
class ndax extends Exchange { }
class novadax extends Exchange { }
class oceanex extends Exchange { }
class okcoin extends Exchange { }
class okxus extends Exchange { }
class onetrading extends Exchange { }
class oxfun extends Exchange { }
class p2b extends Exchange { }
class paradex extends Exchange { }
class paymium extends Exchange { }
class phemex extends Exchange { }
class poloniex extends Exchange { }
class probit extends Exchange { }
class timex extends Exchange { }
class tokocrypto extends Exchange { }
class tradeogre extends Exchange { }
class upbit extends Exchange { }
class wavesexchange extends Exchange { }
class whitebit extends Exchange { }
class woo extends Exchange { }
class woofipro extends Exchange { }
class xt extends Exchange { }
class yobit extends Exchange { }
class zaif extends Exchange { }
class zonda extends Exchange { }
// Access all available exchanges
const exchanges: { [key: string]: typeof Exchange };
// Get list of exchange names
const exchangeNames: string[];Usage Examples:
// Create instances of different exchanges
const binanceSpot = new ccxt.binance({ sandbox: true });
const binanceFutures = new ccxt.binanceusdm({ sandbox: true });
const coinbaseExchange = new ccxt.coinbase();
const krakenExchange = new ccxt.kraken();
// List all available exchanges
console.log('Available exchanges:', Object.keys(ccxt));
// Filter exchanges by capability
const spotExchanges = Object.keys(ccxt).filter(name => {
const exchange = new ccxt[name]();
return exchange.has.spot;
});
const futuresExchanges = Object.keys(ccxt).filter(name => {
const exchange = new ccxt[name]();
return exchange.has.future;
});
// Create exchange instance dynamically
const exchangeName = 'binance';
const ExchangeClass = ccxt[exchangeName];
const dynamicExchange = new ExchangeClass({
apiKey: 'your-api-key',
secret: 'your-secret'
});Configure exchange instances for different environments and use cases.
/**
* Load markets from exchange (required before trading)
* @param reload - Force reload markets from exchange
* @returns Markets dictionary indexed by symbol
*/
loadMarkets(reload?: boolean): Promise<{ [symbol: string]: Market }>;
/**
* Set exchange sandbox mode
* @param enabled - Enable or disable sandbox mode
*/
setSandboxMode(enabled: boolean): void;
/**
* Set request timeout
* @param timeout - Timeout in milliseconds
*/
setTimeout(timeout: number): void;
/**
* Set rate limit delay
* @param rateLimit - Delay in milliseconds between requests
*/
setRateLimit(rateLimit: number): void;
/**
* Enable or disable rate limiting
* @param enabled - Enable automatic rate limiting
*/
enableRateLimit(enabled: boolean): void;
/**
* Get current server time from exchange
* @returns Server timestamp in milliseconds
*/
fetchTime(params?: Dict): Promise<number>;Usage Examples:
const exchange = new ccxt.binance();
// Load markets (required before trading operations)
await exchange.loadMarkets();
// Configure sandbox mode
exchange.setSandboxMode(true);
// Set custom timeout
exchange.setTimeout(20000); // 20 seconds
// Configure rate limiting
exchange.setRateLimit(2000); // 2 seconds between requests
exchange.enableRateLimit(true);
// Get server time
const serverTime = await exchange.fetchTime();
console.log('Server time:', new Date(serverTime));
// Access loaded markets
console.log('Available markets:', Object.keys(exchange.markets));
console.log('Market info for BTC/USDT:', exchange.markets['BTC/USDT']);