GET_ACCOUNTS
Retrieve your Upbit account balances to view holdings across all assets. Requires private API access enabled.
Instructions
Get Upbit account balances (requires private API enabled)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/get-accounts.ts:10-20 (handler)The execute function that calls Upbit /accounts API via authenticated HTTP request and returns JSON-formatted account balances.
execute: async () => { ensurePrivateEnabled(); const baseURL = `${config.upbit.baseUrl}${config.upbit.apiBasePath}`; const client = createHttpClient(baseURL); const token = signJwtToken(); const data = await fetchJson<unknown>(client, "/accounts", { headers: { Authorization: `Bearer ${token}` }, }); return JSON.stringify(data, null, 2); }, } as const; - src/tools/get-accounts.ts:9-9 (schema)Empty Zod schema — the GET_ACCOUNTS tool takes no parameters.
parameters: z.object({}), - src/index.ts:34-34 (registration)Registration of getAccountsTool on the FastMCP server at startup.
server.addTool(getAccountsTool); - src/lib/upbit-auth.ts:5-16 (helper)Validates that private API access is enabled and API keys are configured before making the request.
export function ensurePrivateEnabled(): void { if (!config.upbit.enablePrivate) { throw new Error( "Private trading tools are disabled. Set UPBIT_ENABLE_TRADING=true to enable.", ); } if (!config.upbit.accessKey || !config.upbit.secretKey) { throw new Error( "Upbit API keys are not configured. Set UPBIT_ACCESS_KEY and UPBIT_SECRET_KEY.", ); } } - src/lib/upbit-auth.ts:18-41 (helper)Generates a JWT token signed with the Upbit secret key for API authentication.
export function signJwtToken( params?: Record<string, string | number | boolean | undefined>, ): string { const payload: Record<string, unknown> = { access_key: config.upbit.accessKey, nonce: crypto.randomUUID(), }; if (params && Object.keys(params).length > 0) { const searchParams = new URLSearchParams(); const sortedKeys = Object.keys(params).sort(); for (const key of sortedKeys) { const value = params[key]; if (value === undefined) continue; searchParams.append(key, String(value)); } const encoded = searchParams.toString(); const queryHash = crypto.createHash("sha512").update(encoded).digest("hex"); payload.query_hash = queryHash; payload.query_hash_alg = "SHA512"; } return jwt.sign(payload, config.upbit.secretKey as string); }