getBalance
Retrieve account balance details on the Bitget cryptocurrency exchange. Query specific assets or view all balances in real-time for informed trading decisions.
Instructions
Get account balance information
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| asset | No | Specific asset to query |
Implementation Reference
- src/server.ts:367-378 (handler)MCP tool handler for 'getBalance' that validates input using GetBalanceSchema and delegates to BitgetRestClient.getBalancecase 'getBalance': { const { asset } = GetBalanceSchema.parse(args); const balance = await this.bitgetClient.getBalance(asset); return { content: [ { type: 'text', text: JSON.stringify(balance, null, 2), }, ], } as CallToolResult; }
- src/types/mcp.ts:62-64 (schema)Zod input schema for the getBalance tool, defining optional 'asset' parameterexport const GetBalanceSchema = z.object({ asset: z.string().optional().describe('Specific asset to query') });
- src/server.ts:150-160 (registration)Tool registration in listTools handler, defining name, description, and JSON schema matching GetBalanceSchema{ name: 'getBalance', description: 'Get account balance information', inputSchema: { type: 'object', properties: { asset: { type: 'string', description: 'Specific asset to query' } }, required: [] }, },
- src/api/rest-client.ts:519-534 (helper)Implementation of getBalance in BitgetRestClient that fetches spot account assets via API and maps to Balance type, optionally filtering by assetasync getBalance(asset?: string): Promise<Balance[]> { const response = await this.request<any>('GET', '/api/v2/spot/account/assets', {}, true); const balances = response.data.map((item: any) => ({ asset: item.coin, free: item.available, locked: item.frozen, total: (parseFloat(item.available) + parseFloat(item.frozen)).toString() })); if (asset) { return balances.filter((balance: Balance) => balance.asset === asset); } return balances; }