fetchBalance
Retrieve account balance from a configured cryptocurrency exchange account using the CCXT MCP Server, ideal for managing assets and monitoring financial positions.
Instructions
Fetch account balance for a configured account
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| accountName | Yes | Account name defined in the configuration file (e.g., 'bybit_main') |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"accountName": {
"description": "Account name defined in the configuration file (e.g., 'bybit_main')",
"type": "string"
}
},
"required": [
"accountName"
],
"type": "object"
}
Implementation Reference
- src/tools/account-tools.ts:78-108 (handler)The handler function for the 'fetchBalance' tool. It retrieves the CCXT exchange instance for the given account name and fetches the account balance, returning it as JSON-formatted text or an error if failed.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)Zod schema defining the input parameter 'accountName' for the 'fetchBalance' tool.{ accountName: z .string() .describe( "Account name defined in the configuration file (e.g., 'bybit_main')" ), },
- src/tools/account-tools.ts:69-109 (registration)The 'server.tool()' call that registers the 'fetchBalance' tool with its description, schema, and handler on the MCP server."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:374-374 (registration)Call within CcxtMcpServer.registerTools() that invokes registerAccountTools, thereby registering the 'fetchBalance' tool among others.registerAccountTools(this.server, this);
- src/server.ts:86-86 (registration)Invocation of registerTools() in the CcxtMcpServer constructor, which leads to the registration of the 'fetchBalance' tool.this.registerTools();