get_account_summary
Retrieve aggregated portfolio metrics from your OKX trading account to monitor performance and analyze holdings.
Instructions
Get aggregated portfolio metrics
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/get_account_summary.ts:21-33 (handler)The main handler function for the 'get_account_summary' tool. It invokes the OKX API client to fetch the account summary and returns it as formatted JSON text content, with error handling.export default async function get_account_summary({}: InferSchema<typeof schema>) { try { const accountSummary = await okxApiClient.getAccountSummary(); return { content: [{ type: 'text', text: JSON.stringify(accountSummary, null, 2) }], }; } catch (error) { const message = error instanceof Error ? error.message : 'An unknown error occurred'; return { content: [{ type: 'text', text: JSON.stringify({ error: message }, null, 2) }], }; } }
- src/tools/get_account_summary.ts:8-9 (schema)The input schema for the tool, which is empty (no parameters expected).export const schema = {};
- src/tools/get_account_summary.ts:10-19 (registration)Metadata object defining the tool's name, description, and annotations, used for registration in the MCP server.export const metadata = { name: 'get_account_summary', description: 'Get aggregated portfolio metrics', annotations: { title: 'Get Account Summary', readOnlyHint: true, destructiveHint: false, idempotentHint: true, }, };
- src/services/okxApiClient.ts:113-138 (helper)Helper method in OkxApiClient that aggregates portfolio value, allocation, open orders, and positions to compute the account summary.async getAccountSummary() { try { const portfolio = await this.getPortfolio(); const openOrders = await this.getOpenOrders(); const positions = await this.getPositions(); const totalValueUsdt = portfolio.reduce( (acc, item) => acc + item.usdtValue, 0 ); const allocation = portfolio.map((item) => ({ currency: item.currency, allocation: item.usdtValue / totalValueUsdt, })); return { totalPortfolioValueUSDT: totalValueUsdt, allocationByAsset: allocation, numberOfOpenOrders: openOrders.length, numberOfOpenPositions: positions.length, }; } catch (error) { console.error("Error fetching account summary:", error); throw error; } }