Skip to main content
Glama
gagarinyury

MCP Bitget Trading Server

by gagarinyury

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
NameRequiredDescriptionDefault
symbolYesTrading pair symbol (e.g., BTCUSDT for spot, BTCUSDT_UMCBL for futures)

Implementation Reference

  • 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; }
  • 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'] }, },
  • 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; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/gagarinyury/MCP-bitget-trading'

If you have feedback or need assistance with the MCP directory API, please join our Discord server