Use this file to discover all available pages before exploring further.
RestClientV2 is the REST client for Bitget’s classic (V2) account structure, targeting the /api/v2/ family of endpoints. It provides comprehensive coverage of spot trading, USDT/COIN-margined futures, cross/isolated margin, copy trading, earn products, broker management, and sub-accounts. If your account has not yet been upgraded to Bitget’s Unified Trading Account (UTA), this is the client you should use. Accounts already on UTA should use RestClientV3 instead.
import { RestClientV2 } from 'bitget-api';const client = new RestClientV2({ apiKey: 'YOUR_API_KEY', apiSecret: 'YOUR_API_SECRET', apiPass: 'YOUR_API_PASS',});
Credentials are entirely optional when you only need public market data. Calling private endpoints without credentials will result in an authentication error.
Provide a custom HMAC signing function. Useful for improving performance by substituting Node’s built-in crypto.createHmac instead of the default Web Crypto implementation. See the examples/auth/ folder for a reference implementation.
The SpotOrderRequestV2 type describes all order parameters. The example below reads the minimum trade amount from the symbol’s trading rules before placing a market sell order.
import { RestClientV2, SpotOrderRequestV2 } from 'bitget-api';const client = new RestClientV2({ apiKey: process.env.API_KEY, apiSecret: process.env.API_SECRET, apiPass: process.env.API_PASS,});(async () => { try { const symbol = 'BTCUSDT'; // Get current BTC balance const assets = await client.getSpotAccountAssets(); const btcAsset = assets.data.find( (bal) => bal.coin === 'BTC' || bal.coin === 'btc', ); const btcAmount = btcAsset ? Number(btcAsset.available) : 0; if (!btcAmount) { console.error('No BTC available to sell'); return; } // Fetch trading rules to retrieve the minimum order size const symbolsResult = await client.getSpotSymbolInfo(); const btcRules = symbolsResult.data.find((rule) => rule.symbol === symbol); if (!btcRules) { return console.log('No trading rules found for ' + symbol); } const order: SpotOrderRequestV2 = { symbol, side: 'sell', orderType: 'market', force: 'gtc', size: btcRules.minTradeAmount, }; console.log('Submitting order:', order); const result = await client.spotSubmitOrder(order); console.log('Order result:', result); } catch (e) { console.error('Request failed:', e); }})();
Setting BITGETTRACE=true will print the full details of every outbound HTTP request and inbound response to stdout. This is very useful for diagnosing authentication issues, unexpected parameter serialisation, or API errors — but it will expose your API credentials and request payloads in logs. Never enable this in production.
BITGETTRACE=true ts-node your-script.ts
This environment variable is read by the underlying REST client base class and activates verbose request/response tracing without requiring any code changes.
Call client.fetchLatencySummary() to measure the round-trip latency and clock skew between your server and Bitget’s API. If the measured time difference exceeds 500 ms, you risk authentication failures caused by timestamp mismatch. The method logs a full diagnostic summary to the console automatically.
import { RestClientV2 } from 'bitget-api';const client = new RestClientV2();(async () => { await client.fetchLatencySummary();})();