getTicker
Retrieve detailed ticker data for cryptocurrency trading pairs to analyze real-time market information, including price, volume, and other key metrics, using Bitget exchange integration.
Instructions
Get full ticker information for a trading pair
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes | Trading pair symbol |
Implementation Reference
- src/server.ts:327-338 (handler)MCP tool handler for 'getTicker' that validates input using GetTickerSchema, fetches ticker data from BitgetRestClient, and returns JSON-formatted result.case 'getTicker': { const { symbol } = GetTickerSchema.parse(args); const ticker = await this.bitgetClient.getTicker(symbol); return { content: [ { type: 'text', text: JSON.stringify(ticker, null, 2), }, ], } as CallToolResult; }
- src/types/mcp.ts:13-15 (schema)Zod schema defining the input parameters for the getTicker tool (requires 'symbol' string).export const GetTickerSchema = z.object({ symbol: z.string().describe('Trading pair symbol (BTCUSDT for spot, BTCUSDT_UMCBL for futures)') });
- src/server.ts:115-124 (registration)Registration of the 'getTicker' tool in the listTools response, including name, description, and input schema.name: 'getTicker', description: 'Get full ticker information for a trading pair', inputSchema: { type: 'object', properties: { symbol: { type: 'string', description: 'Trading pair symbol' } }, required: ['symbol'] }, },
- src/api/rest-client.ts:334-406 (helper)Core implementation of getTicker in BitgetRestClient: handles caching, spot vs futures logic, API requests to Bitget, and ticker data formatting.async getTicker(symbol: string): Promise<Ticker> { const cacheKey = `ticker:${symbol}`; // Try cache first const cachedTicker = tickerCache.get(cacheKey); if (cachedTicker) { return cachedTicker; } let ticker: Ticker = { symbol: '', last: '', bid: '', ask: '', high24h: '', low24h: '', volume24h: '', change24h: '', changePercent24h: '', timestamp: 0 }; if (this.isFuturesSymbol(symbol)) { // Futures ticker const futuresSymbol = symbol.includes('_UMCBL') ? symbol : `${symbol}_UMCBL`; const response = await this.request<any>('GET', '/api/mix/v1/market/ticker', { symbol: futuresSymbol }); if (response.data) { const tickerData = response.data; ticker = { symbol: tickerData.symbol, last: tickerData.last, bid: tickerData.bestBid, ask: tickerData.bestAsk, high24h: tickerData.high24h, low24h: tickerData.low24h, volume24h: tickerData.baseVolume, change24h: ((parseFloat(tickerData.last) - parseFloat(tickerData.openUtc)) / parseFloat(tickerData.openUtc) * 100).toFixed(2), changePercent24h: tickerData.priceChangePercent, timestamp: parseInt(tickerData.timestamp) || Date.now() }; } else { throw new Error(`Ticker not found for symbol: ${symbol}`); } } else { // Spot ticker - use v1 public API const response = await this.request<any>('GET', '/api/spot/v1/market/tickers', {}); if (response.data && Array.isArray(response.data)) { const tickerData = response.data.find((t: any) => t.symbol === symbol); if (tickerData) { ticker = { symbol: tickerData.symbol, last: tickerData.close, bid: tickerData.buyOne, ask: tickerData.sellOne, high24h: tickerData.high24h, low24h: tickerData.low24h, volume24h: tickerData.baseVol, change24h: tickerData.change, changePercent24h: tickerData.changePercent, timestamp: parseInt(tickerData.ts) || Date.now() }; } else { throw new Error(`Ticker not found for symbol: ${symbol}`); } } else { throw new Error(`Ticker not found for symbol: ${symbol}`); } } // Cache the result tickerCache.set(cacheKey, ticker); return ticker; }