Choose a client โ
Use RestClient for individual requests and WebsocketClient for ongoing market and account updates.
- RestClient: public market data, authenticated account reads and order commands over REST.
- WebsocketClient: public and private subscriptions, connection events and low-level WebSocket API requests.
- WebsocketAPIClient: promise-based Spot and perpetual-futures order requests over WebSockets.
Combine requests and subscriptions โ
One REST client covers multiple products. Method names identify the API family, such as getSpotTicker() for Spot and getFuturesTickers() for perpetual futures. Futures methods also take a settlement currency. Choose the account and product deliberately; Spot amounts and futures contract sizes use different units.
For streams, pass the connection key as the second argument to subscribe(). Use spotV4 for Spot and margin, or perpFuturesUSDTV4 for USDT-settled perpetual futures. The SDK also exports connection keys for BTC-settled perpetuals, delivery futures and options. Select the key and channel together using the WebSocket reference.
Keep long-lived clients for each account and environment. After a disconnect, recover missed state through REST before relying on cached data.
Send WebSocket API requests โ
Use await and try/catch just as you would with a REST API call. The SDK matches responses to requests and manages the WebSocket connection for you. Requests over a persistent WebSocket can offer lower overhead and latency, depending on the exchange, network and workload.
WebsocketAPIClient provides methods such as getSpotOrderStatus(), submitNewSpotOrder() and submitNewFuturesOrder(). It opens and authenticates the connection when needed. Use private subscriptions separately to follow fills and account changes.