binance.account.balances
Retrieve cryptocurrency account balances from Binance using API credentials to monitor portfolio holdings.
Instructions
Get account balances (requires API key & secret).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/account.ts:9-22 (handler)The main tool handler: exports tool_account_balances with name, description, schema reference, and async run() that validates input, calls binance.account via the Binance Spot client, and handles errors.export const tool_account_balances: BinanceTool = { name: "binance.account.balances", description: "Get account balances (requires API key & secret).", parameters: balancesSchema, async run(input) { balancesSchema.parse(input); try { const res = await binance.account(withCommonParams({})); return res.data?.balances ?? res.data; } catch (err) { throw toToolError(err); } } };
- src/tools/account.ts:6-6 (schema)Zod schema defining empty input parameters for the tool.const balancesSchema = z.object({});
- src/index.ts:14-39 (registration)The tool is included in the tools array (line 18) and registered via server.addTool() in the forEach loop, copying name, description, parameters, and wrapping execute around the tool's run().const tools = [ tool_market_price, tool_market_klines, tool_exchange_info, tool_account_balances, tool_open_orders, tool_place_order, tool_cancel_order, ]; tools.forEach((tool) => { server.addTool({ name: tool.name, description: tool.description, parameters: tool.parameters, execute: async (args) => { try { const result = await tool.run(args); return JSON.stringify(result, null, 2); } catch (error) { const handled = error instanceof ToolError ? error : new ToolError((error as Error).message); throw handled; } }, }); });
- src/binance/client.ts:16-18 (helper)Helper function used in the handler to add recvWindow to API params.export function withCommonParams<T extends Record<string, unknown>>(params: T) { return { ...params, recvWindow }; }
- src/binance/client.ts:14-14 (helper)Binance Spot client instance used by the handler's binance.account call.export const binance = new Spot(apiKey, apiSecret, { baseURL });