Clients
Binance has separate REST clients for Spot, futures and Portfolio Margin. WebSocket clients handle streaming updates and request-response operations.
| Client | Purpose |
|---|---|
MainClient | Spot and related account endpoints over HTTP. |
USDMClient | USD-M futures endpoints. |
CoinMClient | COIN-M futures endpoints. |
PortfolioClient | Portfolio Margin endpoints. |
WebsocketClient | Market and account streams, with raw message events and optional formatted events. |
WebsocketAPIClient | Supported awaitable operations over Binance WebSocket APIs. |
REST requests
ts
import { MainClient } from 'binance';
async function main() {
const client = new MainClient();
const result = await client.getSymbolPriceTicker({ symbol: 'BTCUSDT' });
if (Array.isArray(result)) throw new Error('Expected a single-symbol ticker.');
console.log('BTCUSDT last price:', result.price);
}
main().catch((error) => {
console.error(error instanceof Error ? error.message : 'Request failed. See the troubleshooting guide.');
process.exitCode = 1;
});getSymbolPriceTicker() returns response data directly. Its return type allows one ticker or an array; the example handles both before reading price.
WebSocket subscriptions
Register listeners before subscribing with WebsocketClient. The subscription example shows message handling and shutdown.
WebSocket API requests
WebsocketAPIClient returns promises for supported Binance WebSocket API operations. Its method list differs from the REST clients.