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
      ]>;
    }
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. It states what the tool does but doesn't describe important behavioral aspects: whether this is a read-only operation, rate limits, authentication requirements, error conditions, or what format the candlestick data returns. For a financial data tool with no annotation coverage, this leaves significant gaps in understanding how the tool behaves.

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 states the core purpose without any wasted words. It's appropriately sized for a straightforward data retrieval tool and gets directly to the point. Every word earns its place.

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 complexity of financial data retrieval (with no output schema), the description is incomplete. It doesn't explain what candlestick data includes (open, high, low, close, volume), the return format, pagination behavior, or error handling. With no annotations and no output schema, the agent lacks crucial context about what to expect from this tool.

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 already documents all three parameters thoroughly with descriptions, defaults, and constraints. The description adds no additional parameter semantics beyond what's in the schema. This meets the baseline expectation when the schema does the heavy lifting.

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') and resource ('candlestick data for an OKX instrument'), making the purpose immediately understandable. It doesn't explicitly differentiate from the sibling tool 'get_price', but the resource specificity (candlestick data vs. price) provides implicit distinction. The description is not vague or tautological.

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. There's no mention of use cases, prerequisites, or exclusions. The agent must infer usage from the tool name and description alone without explicit direction.

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