Skip to content

UTA WebSocket API requests ​

WebsocketAPIClient returns promises for UTA V3 trading requests. Use a separate private subscription client for account events. Classic V2 trading is not supported by this client. Methods include submitNewOrder(), updateOrder(), cancelOrder() and batch operations. The underlying WebsocketClientV3 is available through getWSClient().

Cancel one existing UTA Spot order ​

This example cancels the remaining quantity of the order identified by BITGET_CLIENT_ORDER_ID. It uses live trading by default. Configure credentials, select the intended account/environment and keep the separate UTA private stream running. Save as ws-api.ts, compile with the credential helper and run only when you intend to cancel that order:

ts
import { WebsocketAPIClient } from 'bitget-api';
import { credentials, requiredEnv } from './authenticated-client.js';

const api = new WebsocketAPIClient(credentials);

async function main() {
  const response = await api.cancelOrder('spot', {
    clientOid: requiredEnv('BITGET_CLIENT_ORDER_ID'),
  });
  if (response.code !== '0') {
    throw new Error(`Cancellation rejected: ${response.code}`);
  }
  console.log('Cancellation acknowledgement:', response.args);
}

main().catch(() => {
  console.error('WS API command failed. Reconcile the order before retrying.');
  process.exitCode = 1;
}).finally(() => {
  api.getWSClient().closeAll();
});
sh
node --env-file=.env dist/ws-api.js

The wrapper connects and authenticates automatically. This one-shot example closes its own command connection after completion; a production service can reuse a long-lived client. Closing it does not cancel other orders or close your separate private subscription client.

Request and response differences ​

  • The wrapper's category argument is lowercase, such as spot or usdt-futures. REST requests use uppercase categories such as SPOT.
  • WebSocket command success uses code: '0', while REST success uses code: '00000'.
  • WebSocket response payloads are in args, not REST's data.
  • Placement uses submitNewOrder(category, params). Amendment uses updateOrder(category, params), not the REST name modifyOrder().

Inspect top-level codes and each item's result where supplied by batch endpoints. A resolved promise is not proof that every batch item succeeded or that an order filled. Handle rejected requests as well. Check each item's outcome before retrying a partially successful batch.

Recovery ​

A command acknowledgement confirms acceptance. Follow private order and fill events to keep account state current. A rejected or timed-out command may require reconciliation before retrying; use the saved order IDs and targeted REST recovery.

The SDK manages the connection and matches responses to requests. Your application must save order IDs, respect rate limits and recover missed account changes. Moving a request from REST to WebSockets does not remove exchange rate limits.

WebsocketAPIClient reference · Bitget WebSocket cancellation API

Built by Siebly. Open source SDKs for exchange APIs.