getPrice
Retrieve current market prices for cryptocurrency trading pairs on Bitget exchange, supporting both spot and futures contracts.
Instructions
Get current price for a trading pair (spot or futures)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes | Trading pair symbol (e.g., BTCUSDT for spot, BTCUSDT_UMCBL for futures) |
Implementation Reference
- src/server.ts:314-325 (handler)MCP tool handler for getPrice that parses input arguments using the schema and delegates execution to the BitgetRestClient's getPrice method, returning formatted result.case 'getPrice': { const { symbol } = GetPriceSchema.parse(args); const price = await this.bitgetClient.getPrice(symbol); return { content: [ { type: 'text', text: `Current price for ${symbol}: $${price}`, }, ], } as CallToolResult; }
- src/types/mcp.ts:9-11 (schema)Zod schema defining the input parameters for the getPrice tool (symbol string). Used for validation in the handler.export const GetPriceSchema = z.object({ symbol: z.string().describe('Trading pair symbol (e.g., BTCUSDT for spot, BTCUSDT_UMCBL for futures)') });
- src/server.ts:103-113 (registration)Registration of the getPrice tool in the listTools handler, providing name, description, and input schema for MCP discovery.{ name: 'getPrice', description: 'Get current price for a trading pair (spot or futures)', inputSchema: { type: 'object', properties: { symbol: { type: 'string', description: 'Trading pair symbol (e.g., BTCUSDT for spot, BTCUSDT_UMCBL for futures)' } }, required: ['symbol'] }, },
- src/api/rest-client.ts:291-329 (helper)The core getPrice implementation in BitgetRestClient class. Handles caching, spot vs futures logic, API requests to Bitget, and error handling.async getPrice(symbol: string): Promise<string> { const cacheKey = `price:${symbol}`; // Try cache first const cachedPrice = priceCache.get(cacheKey); if (cachedPrice) { return cachedPrice; } let price: string = ''; 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?.last) { price = response.data.last; } else { throw new Error(`Price 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 ticker = response.data.find((t: any) => t.symbol === symbol); if (ticker) { price = ticker.close; } else { throw new Error(`Price not found for symbol: ${symbol}`); } } else { throw new Error(`Price not found for symbol: ${symbol}`); } } // Cache the result priceCache.set(cacheKey, price); return price; }