Spot Testnet and demo trading
Available environments
- Spot Testnet: a separate Spot API testing service with virtual balances and independent order books.
- Demo trading: the SDK has demo routing for Spot, USDⓈ-M Futures and COIN-M Futures.
Choose the product and environment together. An option on MainClient does not imply support for all of its endpoint families. Production is the default when testnet and demoTrading are false or omitted.
Spot Testnet
Create API credentials at Spot Testnet. Set testnet: true and demoTrading: false on MainClient and any Spot WebSocket clients. Supply the Testnet key and secret as api_key and api_secret.
Spot Testnet supports /api endpoints, not /sapi. Its data and virtual balances are periodically reset; consult the Spot Testnet documentation before depending on persistent account state.
Demo trading
Create API credentials in Binance Demo Trading. Set demoTrading: true and testnet: false on every client used for that environment:
import { MainClient, WebsocketClient } from 'binance';
function requiredEnv(name: string): string {
const value = process.env[name];
if (!value) throw new Error(`Set ${name} in your server environment.`);
return value;
}
// Configure clients only. No requests, subscriptions or orders are sent.
const options = {
api_key: requiredEnv('BINANCE_DEMO_API_KEY'),
api_secret: requiredEnv('BINANCE_DEMO_API_SECRET'),
testnet: false,
demoTrading: true,
};
export const rest = new MainClient(options);
export const ws = new WebsocketClient(options);This example constructs Spot clients without sending requests. For Futures, choose USDMClient or CoinMClient and the corresponding WebSocket market. Keep demo credentials separate from production and Spot Testnet credentials.
Coverage and limitations
Do not enable both flags. The REST and WebSocket clients handle that combination differently. Avoid manual baseUrl or wsUrl overrides when using the environment flags; overrides can bypass SDK routing.
Binance's Futures documentation calls its demo host a “testnet”. Do not infer two independent Futures services or interchangeable credentials from the SDK's two flag names. Follow the Futures environment documentation for the selected product and verify the destination before authenticated operations.
Demo support does not extend automatically to Margin, Portfolio Margin, Options or every account endpoint. The Spot demo documentation also cautions that simulated market data and strategy outcomes do not represent live execution.
What these environments can prove
Use test environments to check request formats, credentials, order handling and reconnect recovery within the features they support. Testnet liquidity, prices, fills, fees and availability can differ substantially from production. Accounts, balances and order history may also be reset.
Testnet is not a reliable place to evaluate strategy performance. Demo trading may use production market data, but simulated fills do not establish live profitability, slippage, execution quality or capacity. Treat both as integration tests, not evidence that a strategy will succeed with real funds. See the CEX testnet overview for the distinction between testnet and demo trading.
Before switching environments
- Keep credentials and configuration separate for each account, product and environment. Never fall back to live credentials when a test key is missing.
- Configure every REST, subscription and WebSocket API client separately. Changing one client does not reconfigure another.
- Check the selected environment's supported endpoints and instruments before sending a request. Similar method signatures do not imply identical availability.
- Keep authenticated requests on your server. Confirm the destination and account before enabling any write operation.
Production remains the default. Selecting a test environment is an explicit choice for each client; it is not a global SDK setting.