Skip to main content
Glama

fetchTicker

Retrieve real-time market data for cryptocurrency trading pairs, including prices and volume, from supported exchanges to inform trading decisions.

Instructions

Fetch ticker information for a symbol on an exchange

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
exchangeIdYesExchange ID (e.g., 'binance', 'coinbase')
symbolYesTrading symbol (e.g., 'BTC/USDT')

Implementation Reference

  • The core handler function for the 'fetchTicker' tool. It retrieves a public CCXT exchange instance and calls fetchTicker on the specified symbol, returning JSON-formatted data or error.
    async ({ exchangeId, symbol }) => { try { // 공개 인스턴스 사용 const exchange = ccxtServer.getPublicExchangeInstance(exchangeId); const ticker = await exchange.fetchTicker(symbol); return { content: [ { type: "text", text: JSON.stringify(ticker, null, 2) } ] }; } catch (error) { return { content: [ { type: "text", text: `Error fetching ticker: ${(error as Error).message}` } ], isError: true }; } }
  • Zod input schema defining parameters for the fetchTicker tool: exchangeId (string) and symbol (string).
    { exchangeId: z.string().describe("Exchange ID (e.g., 'binance', 'coinbase')"), symbol: z.string().describe("Trading symbol (e.g., 'BTC/USDT')") },
  • MCP tool registration for 'fetchTicker' via server.tool() within registerMarketTools function, specifying name, description, schema, and handler.
    server.tool( "fetchTicker", "Fetch ticker information for a symbol on an exchange", { exchangeId: z.string().describe("Exchange ID (e.g., 'binance', 'coinbase')"), symbol: z.string().describe("Trading symbol (e.g., 'BTC/USDT')") }, async ({ exchangeId, symbol }) => { try { // 공개 인스턴스 사용 const exchange = ccxtServer.getPublicExchangeInstance(exchangeId); const ticker = await exchange.fetchTicker(symbol); return { content: [ { type: "text", text: JSON.stringify(ticker, null, 2) } ] }; } catch (error) { return { content: [ { type: "text", text: `Error fetching ticker: ${(error as Error).message}` } ], isError: true }; } } );
  • src/server.ts:372-372 (registration)
    Top-level call to registerMarketTools in CcxtMcpServer.registerTools(), which registers the fetchTicker tool.
    registerMarketTools(this.server, this);
  • Helper method on CcxtMcpServer that provides unauthenticated public exchange instances, used by fetchTicker handler.
    getPublicExchangeInstance( exchangeId: string, marketType: "spot" | "futures" = "spot", ): Exchange { const instanceKey = `${exchangeId}-${marketType}`; if (!this.publicExchangeInstances[instanceKey]) { if (!ccxt.exchanges.includes(exchangeId)) { console.error( `Exchange ID '${exchangeId}' not found in ccxt.exchanges for public instance.`, ); throw new Error(`Unsupported exchange for public data: ${exchangeId}`); } const exchangeOptions = { options: { defaultType: marketType, }, }; try { // @ts-ignore - CCXT dynamic instantiation without credentials this.publicExchangeInstances[instanceKey] = new ccxt[exchangeId]( exchangeOptions, ); } catch (error) { console.error( `Failed to create public CCXT instance for ${exchangeId} (${marketType}):`, error, ); throw error; // Re-throw the error after logging } } return this.publicExchangeInstances[instanceKey]; }

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/lazy-dinosaur/ccxt-mcp'

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