get-ticker
Retrieve real-time ticker data, including price, volume, and market details, for specified trading pairs across multiple cryptocurrency exchanges using CCXT MCP Server.
Instructions
Get current ticker information for a trading pair
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| exchange | Yes | Exchange ID (e.g., binance, coinbase) | |
| marketType | No | Market type (default: spot) | |
| symbol | Yes | Trading pair symbol (e.g., BTC/USDT) |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"exchange": {
"description": "Exchange ID (e.g., binance, coinbase)",
"type": "string"
},
"marketType": {
"description": "Market type (default: spot)",
"enum": [
"spot",
"future",
"swap",
"option",
"margin"
],
"type": "string"
},
"symbol": {
"description": "Trading pair symbol (e.g., BTC/USDT)",
"type": "string"
}
},
"required": [
"exchange",
"symbol"
],
"type": "object"
}
Implementation Reference
- src/tools/public.ts:35-65 (handler)The main handler function for the 'get-ticker' tool. It rate-limits the API call, selects the exchange instance based on market type, uses caching to fetch ticker data via ex.fetchTicker(symbol), and returns formatted JSON response or error.}, async ({ exchange, symbol, marketType }) => { try { return await rateLimiter.execute(exchange, async () => { const ex = marketType ? getExchangeWithMarketType(exchange, marketType) : getExchange(exchange); const cacheKey = `ticker:${exchange}:${marketType || 'spot'}:${symbol}`; const ticker = await getCachedData(cacheKey, async () => { log(LogLevel.INFO, `Fetching ticker for ${symbol} on ${exchange}`); return await ex.fetchTicker(symbol); }); return { content: [{ type: "text", text: JSON.stringify(ticker, null, 2) }] }; }); } catch (error) { log(LogLevel.ERROR, `Error fetching ticker: ${error instanceof Error ? error.message : String(error)}`); return { content: [{ type: "text", text: `Error: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } });
- src/tools/public.ts:32-34 (schema)Input schema using Zod for validating parameters: exchange (string), symbol (string), marketType (optional enum).exchange: z.string().describe("Exchange ID (e.g., binance, coinbase)"), symbol: z.string().describe("Trading pair symbol (e.g., BTC/USDT)"), marketType: z.enum(["spot", "future", "swap", "option", "margin"]).optional().describe("Market type (default: spot)")
- src/tools/public.ts:31-65 (registration)The server.tool() registration call for 'get-ticker', including description, schema, and inline handler function within registerPublicTools.server.tool("get-ticker", "Get current ticker information for a trading pair", { exchange: z.string().describe("Exchange ID (e.g., binance, coinbase)"), symbol: z.string().describe("Trading pair symbol (e.g., BTC/USDT)"), marketType: z.enum(["spot", "future", "swap", "option", "margin"]).optional().describe("Market type (default: spot)") }, async ({ exchange, symbol, marketType }) => { try { return await rateLimiter.execute(exchange, async () => { const ex = marketType ? getExchangeWithMarketType(exchange, marketType) : getExchange(exchange); const cacheKey = `ticker:${exchange}:${marketType || 'spot'}:${symbol}`; const ticker = await getCachedData(cacheKey, async () => { log(LogLevel.INFO, `Fetching ticker for ${symbol} on ${exchange}`); return await ex.fetchTicker(symbol); }); return { content: [{ type: "text", text: JSON.stringify(ticker, null, 2) }] }; }); } catch (error) { log(LogLevel.ERROR, `Error fetching ticker: ${error instanceof Error ? error.message : String(error)}`); return { content: [{ type: "text", text: `Error: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } });