Skip to main content
Glama
mbarinov

OKX MCP Server

by mbarinov

get_account_summary

Read-onlyIdempotent

Retrieve aggregated portfolio metrics from your OKX trading account to monitor performance and analyze holdings.

Instructions

Get aggregated portfolio metrics

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • 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) }],
        };
      }
    }
  • The input schema for the tool, which is empty (no parameters expected).
    export const schema = {};
  • 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,
      },
    };
  • 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;
      }
    }

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mbarinov/okx-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server