Bitget Auth JavaScript SDK example: rest-private-rsa.ts

Bitget Auth REST private RSA JavaScript example for the Siebly Bitget SDK, covering exchange REST API and WebSocket integration, setup, and production SDK docs.

We use environment variables in our examples for API keys. It is your responsibility to manage and secure your keys appropriately.

examples/Bitget/Auth/rest-private-rsa.ts

What this example covers

  • Bitget authentication and request-signing JavaScript example.
  • Uses the Siebly Bitget SDK package bitget-api instead of hand-written signing code.
  • Source path: Bitget/Auth/rest-private-rsa.ts.
  • Example category: Auth.
  • Imports SDK symbols including RestClientV2, RestClientV3.
  • Calls SDK methods such as getBalances().

How to use this example

  • Start here for the specific request or stream pattern, then check the matching SDK guide for install, credentials, and operational notes.
  • For private or order-management examples, keep credentials in environment variables or a secret manager. Use read-only keys where possible, and check the execution mode reference before any exchange write path can run.
  • Open the repository source when you need the latest committed version: GitHub source file.
import { RestClientV2, RestClientV3 } from 'bitget-api'; // Import frmo NPM: // or if you prefer require: // Received after creating a new API key with a self-generated RSA public key on Bitgetconst API_KEY = 'bg_0866563123123123123f567e83e52fd'; // The self-generated RSA private key, this is never directly given to Bitget, but used to generate a signature// Note: this MUST include the "BEGIN PRIVATE KEY" header so that the SDK understands this is RSA authconst rsaPrivateKey = `-----BEGIN PRIVATE KEY-----MIIJQQIBADANBgkqhkiG9w0BAQEFAASCCSswggknAgEAAoICAQC4kNgO71O0xkuHFjHnr5pimpEeiGPAtDTAeJoS55+kVrh3ThHsm0ARf36zimUgwrCWAnKqPlbqzWzs9mH9JvZWrEaOgWy8wMSJ21vtz1rRJhfaUUsOC1KLoWyvzqWW44zKaxoKSqCUMJqDbxIq7RjGlmc8KGJscFWRSdfGEEpvqLlpTLoEtWHZP0pUUamSWrH/IgieFFhKaOPvmED24DJAlqSeEFwz7TW4dfWPRgjCRu4AAfgCtjb+3/7ONeQfx5XFvKFM7VNi/9sRh+alRqpzKrlI79bM1p/egrC4c8KUqrNk2s5c3HIU......THISISANEXAMPLE-----END PRIVATE KEY-----`; // This is set by you when registering your RSA API key in Bitget's website.const API_PASS = 'TestingRSA'; const client = new RestClientV2({  apiKey: API_KEY,  apiSecret: rsaPrivateKey,  apiPass: API_PASS,}); const clientV3 = new RestClientV3({  apiKey: API_KEY,  apiSecret: rsaPrivateKey,  apiPass: API_PASS,}); // const wsClient = new WebsocketClientV2({//   apiKey: API_KEY,//   apiSecret: rsaPrivateKey,//   apiPass: API_PASS,// }); (async () => {  try {    console.log('V2 private api call result: ', await client.getBalances());  } catch (e) {    console.error('V2 request failed: ', e);  }  try {    console.log('V3 private api call result: ', await clientV3.getBalances());  } catch (e) {    console.error('V3 request failed: ', e);  }})(); 

Subscribe on Substack

Complete the Substack form below to join our newsletter. Substack handles all subscriber data directly.