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)) {

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