Private account updates
Choose the stream for your UTA or Classic account. Private subscriptions require server-side credentials. These examples read updates only; they do not place, amend or cancel orders.
Unified Trading Account V3
Save as private-stream.ts beside the credential helper. Use that guide's compile instructions with private-stream.ts as the entry file, then run:
node --env-file=.env dist/private-stream.jsimport { WebsocketClientV3, WS_KEY_MAP } from 'bitget-api';
import { credentials } from './authenticated-client.js';
const ws = new WebsocketClientV3(credentials);
ws.on('authenticated', () => {
console.log('UTA private connection authenticated.');
});
ws.on('response', (message) => {
console.log('Subscription response:', message);
});
ws.on('update', (message) => {
// Handle account data on the server; keep it out of public logs.
console.log('UTA account update received:', message.arg);
});
ws.on('exception', () => {
console.error('Private stream exception; check the error code and message without logging credentials.');
});
ws.on('reconnect', () => {
console.log('Reconnecting; account state may be stale. Pause trading decisions until recovery completes.');
});
ws.on('reconnected', () => {
console.log('Connection restored; the SDK restores subscriptions automatically. Recover missed account updates through REST.');
});
ws.subscribe([
{
topic: 'account',
payload: {
instType: 'UTA',
},
},
{
topic: 'order',
payload: {
instType: 'UTA',
},
},
{
topic: 'fill',
payload: {
instType: 'UTA',
},
},
{
topic: 'position',
payload: {
instType: 'UTA',
},
},
], WS_KEY_MAP.v3Private).catch(() => {
console.error('Private subscription failed.');
ws.closeAll();
process.exitCode = 1;
});
process.once('SIGINT', () => {
ws.closeAll();
});UTA private subscriptions use WS_KEY_MAP.v3Private and instType: 'UTA', including account, order, fill and position topics. The order topic is singular, order; Classic uses orders. Handle account data on the server. The example logs only the topic information.
Classic V2 Spot
Save as classic-private-stream.ts, compile it with the same helper and run the emitted file:
import { WebsocketClientV2 } from 'bitget-api';
import { credentials } from './authenticated-client.js';
const ws = new WebsocketClientV2(credentials);
ws.on('authenticated', () => {
console.log('Classic private connection authenticated.');
});
ws.on('response', (message) => {
console.log('Subscription response:', message);
});
ws.on('update', (message) => {
console.log('Classic account update received:', message.arg);
});
ws.on('exception', () => {
console.error('Private stream exception; check the error code and message without logging credentials.');
});
ws.on('reconnect', () => {
console.log('Reconnecting; Classic account state may be stale.');
});
ws.on('reconnected', () => {
console.log('Connection restored; the SDK restores subscriptions automatically. Recover missed account updates through REST.');
});
Promise.all([
ws.subscribeTopic('SPOT', 'orders', 'default'),
ws.subscribeTopic('SPOT', 'account', 'default'),
]).catch(() => {
console.error('Private subscription failed.');
ws.closeAll();
process.exitCode = 1;
});
process.once('SIGINT', () => {
ws.closeAll();
});node --env-file=.env dist/classic-private-stream.jssubscribeTopic() determines the private connection from the topic. For orders, default subscribes to all Spot symbols; for account, it subscribes to all coins. Futures and margin use different instrument types and channels.
Follow order updates
Wait for authentication and all required subscription acknowledgements before placing orders. Match updates to orders using orderId and your saved clientOid. An order-command acknowledgement confirms acceptance, not execution. Follow order and fill events to track execution. A quiet stream can be healthy when no account changes occur.
Keep order state, fills, balances and positions separate. Deduplicate executions by their exchange identifiers and preserve decimal precision. Do not poll REST after every successful event or command.
Recover after a gap
The SDK reconnects, authenticates and restores subscriptions automatically. Mark affected state stale during a connection gap. Buffer incoming events and reconcile balances, open orders and executions using the matching REST client. Page through all relevant history, merge buffered events by identifiers and timestamps, and resume trading decisions only when account state is current.
For UTA use getBalances(), getUnfilledOrders(), getHistoryOrders() and getTradeFills(). getFills() is public market trade data and cannot recover your account executions. Classic Spot uses getSpotAccountAssets(), getSpotOpenOrders(), getSpotHistoricOrders() and getSpotFills(). Respect each endpoint's history window and pagination.
UTA's account topic sends initial data, but order and fill do not. Load open orders and any required execution history through REST. Reconnection does not necessarily replay missed events. Save recovery checkpoints so later history queries cover the gap without reloading all history.