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
| Name | Required | Description | Default |
|---|---|---|---|
| exchangeId | Yes | Exchange ID (e.g., 'binance', 'coinbase') | |
| symbol | Yes | Trading symbol (e.g., 'BTC/USDT') |
Implementation Reference
- src/tools/market-tools.ts:56-81 (handler)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 }; } }
- src/tools/market-tools.ts:52-55 (schema)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')") },
- src/tools/market-tools.ts:49-82 (registration)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);
- src/server.ts:321-356 (helper)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]; }