getTicker
Retrieve real-time trading pair data including price, volume, and market information for cryptocurrency trading decisions on Bitget exchange.
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 server handler for 'getTicker' tool: parses arguments with GetTickerSchema, calls BitgetRestClient.getTicker(), and returns JSON stringified 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 definition for getTicker tool input validation (symbol parameter).export const GetTickerSchema = z.object({ symbol: z.string().describe('Trading pair symbol (BTCUSDT for spot, BTCUSDT_UMCBL for futures)') });
- src/server.ts:114-124 (registration)Tool registration in MCP server's listTools response, defining 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 spot/futures detection, API calls to Bitget endpoints, caching with tickerCache, and formats Ticker response.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; }