Bitget TypeScript SDK example: rest-private-rsa.ts
Bitget Auth REST private RSA example for the Siebly Bitget SDK, with TypeScript source for exchange REST API and WebSocket integration, setup, and production SDK docs.
What This Example Covers
- Bitget authentication and request-signing example in TypeScript.
- Uses the Siebly Bitget SDK package
bitget-apiinstead 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.
Example Path
Bitget/Auth/rest-private-rsa.ts
Source Link
Repository source: https://github.com/sieblyio/crypto-api-examples/blob/master/examples/Bitget/Auth/rest-private-rsa.ts
Related SDK Docs
Example Source
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 Bitget
const 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 auth
const rsaPrivateKey = `
-----BEGIN PRIVATE KEY-----
MIIJQQIBADANBgkqhkiG9w0BAQEFAASCCSswggknAgEAAoICAQC4kNgO71O0xkuH
FjHnr5pimpEeiGPAtDTAeJoS55+kVrh3ThHsm0ARf36zimU
gwrCWAnKqPlbqzWzs9mH9JvZWrEaOgWy
8wMSJ21vtz1rRJhfaUUsOC1KLoWyvzqWW44zKaxoKSqCUMJqDbxIq7RjGlmc8KGJ
scFWRSdfGEEpvqLlpTLoEtWHZP0pUUamSWrH/IgieFFhKaOPvmED24DJAlqSeEFw
z7TW4dfWPRgjCRu4AAfgCtjb+3/7ONeQfx5XFvKFM7VNi/9sRh+alRqpzKrlI
79bM1p/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);
}
})();