Use this file to discover all available pages before exploring further.
WebsocketAPIClient lets you place, cancel, and batch-manage orders over a persistent WebSocket connection rather than through individual HTTP requests. Each method call returns a Promise that resolves when the matching server response arrives, giving you a familiar async/await experience at significantly lower round-trip latency than REST. Internally, the client wraps a WebsocketClientV3 instance and handles connection management, authentication, and request/response correlation automatically.
WebsocketAPIClient uses the V3/UTA WebSocket API. Your Bitget account must
be upgraded to Unified Account (UTA) mode before API keys will work with
these endpoints.
With the REST clients every call opens a new HTTP connection, serialises parameters, waits for a TCP round-trip, and parses the response. WebsocketAPIClient keeps a single authenticated WebSocket connection open and multiplexes all trading operations over it. The server matches each response to the originating request using a unique id field, and the SDK resolves the corresponding Promise automatically. The result is lower latency, especially for burst order workflows.
When true (default), the client attaches built-in console-log handlers for
the open, reconnect, reconnected, authenticated, and exception
events. Set to false if you want to register your own handlers via
getWSClient().on(...).
Call connectWSAPI() before your first order request to pre-warm the
connection. This pays the authentication handshake cost upfront and removes
the latency spike on the first trade call.
// Resolves once the connection is authenticated and readyawait wsApiClient.getWSClient().connectWSAPI();console.log('WS API connection ready');
Batch place requests never reject the outer Promise even if individual orders
fail. Always inspect the code and msg fields on each item in res.args
to detect per-order errors.
const res = await wsApiClient.placeBatchOrders('spot', [ { clientOid: 'batch-order-1', symbol: 'BTCUSDT', orderType: 'limit', side: 'buy', qty: '0.001', price: '60000', timeInForce: 'gtc', }, { clientOid: 'batch-order-2', symbol: 'BTCUSDT', orderType: 'limit', side: 'buy', qty: '0.002', price: '59500', timeInForce: 'gtc', },]);// Check each order result individuallyfor (const order of res.args) { if (order.code !== '0') { console.error(`Order ${order.clientOid} failed: ${order.msg}`); } else { console.log(`Order ${order.clientOid} placed: orderId=${order.orderId}`); }}