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 ]>; }

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