getPrice
Retrieve real-time spot or futures trading prices for specified cryptocurrency pairs using this tool, enabling accurate market data access for trading decisions.
Instructions
Get current price for a trading pair (spot or futures)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes | Trading pair symbol (e.g., BTCUSDT for spot, BTCUSDT_UMCBL for futures) |
Input Schema (JSON Schema)
{
"properties": {
"symbol": {
"description": "Trading pair symbol (e.g., BTCUSDT for spot, BTCUSDT_UMCBL for futures)",
"type": "string"
}
},
"required": [
"symbol"
],
"type": "object"
}
Implementation Reference
- src/api/rest-client.ts:291-329 (handler)Core handler implementation in BitgetRestClient that fetches current price for spot or futures symbols from Bitget API, with caching support.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; }
- src/server.ts:314-325 (handler)MCP server dispatch handler for getPrice tool, validates input with schema and calls BitgetRestClient.getPrice.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 for validating getPrice tool input (symbol parameter).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)Tool registration in listTools handler, defining name, description, and input schema for getPrice.{ 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'] }, },