Skip to main content
Glama
esshka

OKX MCP Server

by esshka

get_candlesticks

Retrieve historical candlestick data for cryptocurrency trading instruments from OKX exchange to analyze price movements and market trends over specified time intervals.

Instructions

Get candlestick data for an OKX instrument

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
instrumentYesInstrument ID (e.g. BTC-USDT)
barNoTime interval (e.g. 1m, 5m, 1H, 1D)1m
limitNoNumber of candlesticks (max 100)

Implementation Reference

  • Handler implementation for the 'get_candlesticks' tool. Fetches candlestick data from OKX API using axios, processes the response, and returns formatted JSON with timestamps.
    } else {
      // get_candlesticks
      console.error(`[API] Fetching candlesticks for instrument: ${args.instrument}, bar: ${args.bar || '1m'}, limit: ${args.limit || 100}`);
      const response = await this.axiosInstance.get<OKXCandlesticksResponse>(
        '/market/candles',
        {
          params: {
            instId: args.instrument,
            bar: args.bar || '1m',
            limit: args.limit || 100
          },
        }
      );
    
      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');
      }
    
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(
              response.data.data.map(([time, open, high, low, close, vol, volCcy]) => ({
                timestamp: new Date(parseInt(time)).toISOString(),
                open,
                high,
                low,
                close,
                volume: vol,
                volumeCurrency: volCcy
              })),
              null,
              2
            ),
          },
        ],
      };
    }
  • Input schema definition for the 'get_candlesticks' tool, specifying parameters for instrument, bar interval, and limit.
    {
      name: 'get_candlesticks',
      description: 'Get candlestick data for an OKX instrument',
      inputSchema: {
        type: 'object',
        properties: {
          instrument: {
            type: 'string',
            description: 'Instrument ID (e.g. BTC-USDT)',
          },
          bar: {
            type: 'string',
            description: 'Time interval (e.g. 1m, 5m, 1H, 1D)',
            default: '1m'
          },
          limit: {
            type: 'number',
            description: 'Number of candlesticks (max 100)',
            default: 100
          }
        },
        required: ['instrument'],
      },
    },
  • src/index.ts:82-123 (registration)
    Registration of available tools in ListToolsRequestSchema handler, including 'get_candlesticks'.
    this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: [
        {
          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'],
          },
        },
        {
          name: 'get_candlesticks',
          description: 'Get candlestick data for an OKX instrument',
          inputSchema: {
            type: 'object',
            properties: {
              instrument: {
                type: 'string',
                description: 'Instrument ID (e.g. BTC-USDT)',
              },
              bar: {
                type: 'string',
                description: 'Time interval (e.g. 1m, 5m, 1H, 1D)',
                default: '1m'
              },
              limit: {
                type: 'number',
                description: 'Number of candlesticks (max 100)',
                default: 100
              }
            },
            required: ['instrument'],
          },
        },
      ],
    }));
  • TypeScript interface defining the structure of OKX candlesticks API response, used in the handler.
    interface OKXCandlesticksResponse {
      code: string;
      msg: string;
      data: Array<[
        time: string,    // Open time
        open: string,    // Open price
        high: string,    // Highest price
        low: string,     // Lowest price
        close: string,   // Close price
        vol: string,     // Trading volume
        volCcy: string   // Trading volume in currency
      ]>;
    }

Schema Changelog

Changes observed during successful MCP inspections.

  1. Addedv1.0.0

TDQS

C2.9/5.0
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure but only states what the tool does without mentioning rate limits, authentication needs, response format, or pagination behavior. It doesn't explain what 'candlestick data' includes (e.g., OHLC values) or any constraints beyond the implied data retrieval.

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 directly states the tool's purpose without any unnecessary words. It's front-loaded and appropriately sized for a simple data retrieval tool, with every word contributing to clarity.

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

Completeness2/5

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

Given the lack of annotations and output schema, the description is incomplete for a tool with three parameters. It doesn't cover behavioral aspects like response format, error handling, or usage context, leaving significant gaps for an AI agent to understand how to effectively invoke and interpret results.

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?

Schema description coverage is 100%, so the schema fully documents all three parameters. The description adds no additional meaning beyond the schema, such as explaining the significance of candlestick intervals or instrument IDs in context. This meets the baseline for high schema coverage.

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 verb ('Get') and resource ('candlestick data for an OKX instrument'), making the purpose immediately understandable. However, it doesn't differentiate from the sibling tool 'get_price', which likely provides different market data, leaving room for improvement in distinguishing between similar data retrieval functions.

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 the sibling 'get_price' or any alternatives. It lacks context about when candlestick data is appropriate (e.g., for charting, technical analysis) versus price data, offering no usage boundaries or prerequisites.

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

Deploy Server

Other Tools