Skip to main content
Glama

get_live_ticker

Retrieve real-time cryptocurrency ticker data from WebSocket subscriptions for trading pairs like BTC-USDT, providing live price updates for market analysis.

Instructions

Get the latest ticker data from WebSocket subscription

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
instrumentYesInstrument ID (e.g. BTC-USDT)
formatNoOutput format (json or markdown)markdown

Implementation Reference

  • The handler logic for executing the get_live_ticker tool. Checks if subscribed to ticker channel for the instrument, auto-subscribes if not, fetches latest data from WebSocket cache, handles no-data case, and returns formatted JSON or rich Markdown visualization with price bar, changes, and stats.
    if (request.params.name === "get_live_ticker") { const isSubscribed = this.wsClient.isSubscribed( "tickers", args.instrument ); if (!isSubscribed) { console.error( `[WebSocket] Auto-subscribing to ticker for ${args.instrument}` ); this.wsClient.subscribe("tickers", args.instrument); // Give it a moment to connect and receive data await new Promise((resolve) => setTimeout(resolve, 1000)); } const tickerData = this.wsClient.getLatestData( "tickers", args.instrument ); if (!tickerData || tickerData.length === 0) { return { content: [ { type: "text", text: `No live data available yet for ${args.instrument}. If you just subscribed, please wait a moment and try again.`, }, ], }; } const ticker = tickerData[0]; if (args.format === "json") { return { content: [ { type: "text", text: JSON.stringify(ticker, null, 2), }, ], }; } else { // Calculate change for markdown formatting const last = parseFloat(ticker.last); const open24h = parseFloat(ticker.open24h); const priceChange = last - open24h; const priceChangePercent = (priceChange / open24h) * 100; const changeSymbol = priceChange >= 0 ? "▲" : "▼"; // Create price range visual const low24h = parseFloat(ticker.low24h); const high24h = parseFloat(ticker.high24h); const range = high24h - low24h; const position = Math.min(Math.max((last - low24h) / range, 0), 1) * 100; const priceBar = `Low ${low24h.toFixed(2)} [${"▮".repeat( Math.floor(position / 5) )}|${"▯".repeat(20 - Math.floor(position / 5))}] ${high24h.toFixed( 2 )} High`; return { content: [ { type: "text", text: `# ${args.instrument} Live Price Data\n\n` + `## Current Price: $${last.toLocaleString()}\n\n` + `**24h Change:** ${changeSymbol} $${Math.abs( priceChange ).toLocaleString()} (${ priceChangePercent >= 0 ? "+" : "" }${priceChangePercent.toFixed(2)}%)\n\n` + `**Bid:** $${parseFloat( ticker.bidPx ).toLocaleString()} | **Ask:** $${parseFloat( ticker.askPx ).toLocaleString()}\n\n` + `### 24-Hour Price Range\n\n` + `\`\`\`\n${priceBar}\n\`\`\`\n\n` + `**24h High:** $${parseFloat( ticker.high24h ).toLocaleString()}\n` + `**24h Low:** $${parseFloat( ticker.low24h ).toLocaleString()}\n\n` + `**24h Volume:** ${parseFloat( ticker.vol24h ).toLocaleString()} units\n\n` + `**Last Updated:** ${new Date( parseInt(ticker.ts) ).toLocaleString()}\n\n` + `*Data source: Live WebSocket feed*`, }, ], }; } }
  • src/index.ts:351-369 (registration)
    Registration of the get_live_ticker tool in the MCP server's listTools response, including name, description, and input schema.
    { name: "get_live_ticker", description: "Get the latest ticker data from WebSocket subscription", inputSchema: { type: "object", properties: { instrument: { type: "string", description: "Instrument ID (e.g. BTC-USDT)", }, format: { type: "string", description: "Output format (json or markdown)", default: "markdown", }, }, required: ["instrument"], }, },
  • Input schema definition for the get_live_ticker tool, specifying required 'instrument' parameter and optional 'format'.
    inputSchema: { type: "object", properties: { instrument: { type: "string", description: "Instrument ID (e.g. BTC-USDT)", }, format: { type: "string", description: "Output format (json or markdown)", default: "markdown", }, }, required: ["instrument"], },
  • Helper method in OKXWebSocketClient class that retrieves the most recent ticker data from the internal cache using channel and instrument ID as key.
    getLatestData(channel: string, instId: string): any | null { const key = `${channel}:${instId}`; return this.dataCache.get(key) || null; }

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

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