Documentation Index
Fetch the complete documentation index at: https://mintlify.com/tiagosiebler/bitget-api/llms.txt
Use this file to discover all available pages before exploring further.
WebsocketClientV3 is the WebSocket client for Bitget’s Unified Trading Account (V3) real-time data streams. It manages two persistent connections — one public and one private — and handles authentication, heartbeats, and automatic reconnection transparently. If your Bitget account has been upgraded to Unified Account mode, this is the client you should use for both market data and private account events such as account balance, position, order, and fill updates.
Installation
Instantiation
For private topics (account, position, order, fill, strategy-order), supply your API key, secret, and passphrase:
WS Key Map
Every subscribe call requires awsKey that tells the client which underlying connection to use. Always import and use the WS_KEY_MAP constants — never hard-code the string values:
Event Listeners
Set up event listeners before callingsubscribe() so no messages are missed:
Event Reference
| Event | When it fires |
|---|---|
update | A subscribed topic pushed new data (ticker tick, order book update, fill, etc.) |
open | A WebSocket connection was opened or re-opened |
response | The server sent a non-data frame (subscribe confirmation, login acknowledgement) |
reconnect | The client detected a lost connection and is about to reconnect |
reconnected | The connection was successfully re-established after a drop |
authenticated | The private connection completed the login handshake |
exception | A server-side error event or WS API error response was received |
subscribe() Method
WS_KEY_MAP value. Each topic object has the shape:
Public Topics (WsPublicTopicV3)
Public topics carry market data and require no authentication. Valid values for instType on public topics are 'spot', 'usdt-futures', 'coin-futures', and 'usdc-futures'.
| Topic | Description |
|---|---|
ticker | Best bid/ask and last-trade price snapshot |
kline | OHLCV candlestick data |
books | Full order book depth updates |
publicTrade | Individual trade executions in real time |
Subscribe Example — Ticker & Kline
Private Topics (WsPrivateTopicV3)
Private topics carry account-level events and require authentication credentials to be provided at construction. All private topics use instType: 'UTA'.
| Topic | Description |
|---|---|
account | Balance and asset changes for the unified account |
position | Position updates (open, close, size changes) |
order | Order state changes (new, filled, cancelled, etc.) |
fill | Individual fill (execution) events |
strategy-order | Strategy/algo order lifecycle events |
All private V3 topics use
instType: 'UTA'. This is different from public
topics where instType specifies the product class (e.g. 'spot',
'usdt-futures'). Account-level events across all product types are
aggregated into the single UTA instType.Subscribe Example — Account & Orders
connectAll() Method
By default, the client opens a connection lazily when the first subscribe() call is made. Call connectAll() to pre-warm both the public and private connections immediately:
unsubscribe() Method
Remove topics from the active connection and the internal subscription store:
Auto-Reconnect Behaviour
WebsocketClientV3 automatically monitors connection health via a ping/pong heartbeat. If the pong response does not arrive within the configured pongTimeout window, the connection is closed and a reconnect is scheduled after reconnectTimeout milliseconds. All previously subscribed topics are resubscribed automatically once the new connection is authenticated. The reconnect and reconnected events let you track this lifecycle.
Demo Trading
To connect to Bitget’s demo trading WebSocket environment, setdemoTrading: true: