Skip to main content
Glama
esshka

OKX MCP Server

by esshka

get_price

Retrieve current cryptocurrency prices from OKX exchange for any trading instrument to monitor market values and inform trading decisions.

Instructions

Get latest price for an OKX instrument

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
instrumentYesInstrument ID (e.g. BTC-USDT)

Implementation Reference

  • The main execution logic for the 'get_price' tool. It queries the OKX /market/ticker API, handles errors, extracts the ticker data, and returns a formatted JSON response with instrument details, prices, and timestamp.
    if (request.params.name === 'get_price') {
      console.error(`[API] Fetching price for instrument: ${args.instrument}`);
      const response = await this.axiosInstance.get<OKXTickerResponse>(
        '/market/ticker',
        {
          params: { instId: args.instrument },
        }
      );
    
      if (response.data.code !== '0') {
        throw new Error(`OKX API error: ${response.data.msg}`);
      }
    
      if (!response.data.data || response.data.data.length === 0) {
        throw new Error('No data returned from OKX API');
      }
    
      const ticker = response.data.data[0];
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify({
              instrument: ticker.instId,
              lastPrice: ticker.last,
              bid: ticker.bidPx,
              ask: ticker.askPx,
              high24h: ticker.high24h,
              low24h: ticker.low24h,
              volume24h: ticker.vol24h,
              timestamp: new Date(parseInt(ticker.ts)).toISOString(),
            }, null, 2),
          },
        ],
      };
    } else {
  • src/index.ts:84-97 (registration)
    Registers the 'get_price' tool in the MCP listTools handler, specifying its name, description, and input schema requiring an 'instrument' parameter.
    {
      name: 'get_price',
      description: 'Get latest price for an OKX instrument',
      inputSchema: {
        type: 'object',
        properties: {
          instrument: {
            type: 'string',
            description: 'Instrument ID (e.g. BTC-USDT)',
          },
        },
        required: ['instrument'],
      },
    },
  • Type definition for the OKX ticker API response, providing type safety for the data parsed in the get_price handler.
    interface OKXTickerResponse {
      code: string;
      msg: string;
      data: Array<{
        instId: string;
        last: string;
        askPx: string;
        bidPx: string;
        open24h: string;
        high24h: string;
        low24h: string;
        volCcy24h: string;
        vol24h: string;
        ts: string;
      }>;
    }
  • src/index.ts:127-127 (registration)
    Validates that the requested tool name is either 'get_price' or 'get_candlesticks' in the callTool handler, effectively registering the allowed tools.
    if (!['get_price', 'get_candlesticks'].includes(request.params.name)) {
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. While 'Get latest price' implies a read operation, it doesn't specify whether this requires authentication, has rate limits, returns cached or real-time data, or what happens with invalid instrument IDs. The description provides minimal behavioral context beyond the basic operation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that communicates the core purpose without any wasted words. It's appropriately sized for a simple tool with one parameter and gets straight to the point.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple price lookup tool with good schema coverage but no annotations or output schema, the description is minimally adequate. It states what the tool does but lacks important context about authentication requirements, error conditions, rate limits, and what format the price is returned in (which is especially important without an output schema).

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, with the single parameter 'instrument' already documented as 'Instrument ID (e.g. BTC-USDT)'. The description doesn't add any additional parameter semantics beyond what the schema provides, so it meets the baseline score when schema coverage is high.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Get latest price') and resource ('for an OKX instrument'), making the purpose immediately understandable. It doesn't specifically differentiate from its sibling 'get_candlesticks' (which presumably provides historical price data rather than latest price), so it doesn't reach the highest score for sibling differentiation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. There's no mention of the sibling tool 'get_candlesticks' or any other potential alternatives, nor does it specify any prerequisites or contextual constraints for usage.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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/esshka/okx-mcp'

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