Gate TypeScript SDK example: getBalances.ts
Gate REST Spot get balances example for the Siebly Gate SDK, with TypeScript source for exchange REST API and WebSocket integration, setup, and production SDK docs.
What This Example Covers
- Gate REST API example in TypeScript.
- Uses the Siebly Gate SDK package
gateio-apiinstead of hand-written HTTP request plumbing. - Source path:
Gate/Rest/spot/getBalances.ts. - Example category: REST Spot.
- Imports SDK symbols including
RestClient.
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.
- Open the repository source when you need the latest committed version: GitHub source file.
Example Path
Gate/Rest/spot/getBalances.ts
Source Link
Repository source: https://github.com/sieblyio/crypto-api-examples/blob/master/examples/Gate/Rest/spot/getBalances.ts
Related SDK Docs
Example Source
import { RestClient } from 'gateio-api';
// Define the account object with API key and secret
const account = {
key: process.env.API_KEY || 'yourApiHere', // Replace 'yourApiHere' with your actual API key
secret: process.env.API_SECRET || 'yourSecretHere', // Replace 'yourSecretHere' with your actual API secret
};
// Initialize the RestClient with the API credentials
const gateRestClient = new RestClient({
apiKey: account.key,
apiSecret: account.secret,
});
async function getSpotBalances() {
try {
console.log('Using API keys:', account);
// Fetch the spot account balances
const balances = await gateRestClient.getSpotAccounts();
console.log('Response: ', balances); // Log the response to the console
} catch (e) {
console.error('Error in execution: ', e); // Log any errors that occur
}
}
// Execute the function to get spot balances
getSpotBalances();