fetchBalance
Retrieve current cryptocurrency account balances from configured exchange accounts to monitor holdings and track portfolio value.
Instructions
Fetch account balance for a configured account
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| accountName | Yes | Account name defined in the configuration file (e.g., 'bybit_main') |
Implementation Reference
- src/tools/account-tools.ts:78-108 (handler)The handler function that executes the tool logic: retrieves the CCXT exchange instance for the given account and calls fetchBalance() on it, returning the balance as JSON or an error message.async ({ accountName }) => { try { // 설정 파일에서 로드된 인스턴스 가져오기 const exchange = ccxtServer.getExchangeInstance(accountName); // getExchangeInstance가 성공하면 인증은 보장됨 const balance = await exchange.fetchBalance(); return { content: [ { type: "text", text: JSON.stringify(balance, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error fetching balance for account '${accountName}': ${ (error as Error).message }`, }, ], isError: true, }; } }
- src/tools/account-tools.ts:71-77 (schema)Input schema using Zod: requires 'accountName' string parameter describing the configured account name.{ accountName: z .string() .describe( "Account name defined in the configuration file (e.g., 'bybit_main')" ), },
- src/tools/account-tools.ts:68-109 (registration)Direct registration of the 'fetchBalance' tool on the MCP server using server.tool(), specifying name, description, input schema, and handler function.server.tool( "fetchBalance", "Fetch account balance for a configured account", { accountName: z .string() .describe( "Account name defined in the configuration file (e.g., 'bybit_main')" ), }, async ({ accountName }) => { try { // 설정 파일에서 로드된 인스턴스 가져오기 const exchange = ccxtServer.getExchangeInstance(accountName); // getExchangeInstance가 성공하면 인증은 보장됨 const balance = await exchange.fetchBalance(); return { content: [ { type: "text", text: JSON.stringify(balance, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error fetching balance for account '${accountName}': ${ (error as Error).message }`, }, ], isError: true, }; } } );
- src/server.ts:371-376 (registration)Top-level registration method in CcxtMcpServer that calls registerAccountTools (among others), which registers the fetchBalance tool.private registerTools() { registerMarketTools(this.server, this); registerOrderTools(this.server, this); registerAccountTools(this.server, this); registerAnalysisTools(this.server, this); }