Skip to main content
Glama
gagarinyury

MCP Bitget Trading Server

by gagarinyury

getCandles

Retrieve historical candlestick (OHLCV) data for cryptocurrency trading pairs on Bitget. Specify symbol, interval, and limit to analyze market trends effectively.

Instructions

Get historical candlestick/OHLCV data

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
intervalYesCandle interval
limitNoNumber of candles (default: 100)
symbolYesTrading pair symbol

Implementation Reference

  • Core implementation of getCandles: fetches historical candlestick data from Bitget API for both spot and futures markets, handles interval formatting, maps API response to Candle[] format.
    async getCandles(symbol: string, interval: string, limit: number = 100): Promise<Candle[]> { if (this.isFuturesSymbol(symbol)) { // Futures candles - use v2 API with productType // Remove _UMCBL suffix if present for v2 API const cleanSymbol = symbol.replace('_UMCBL', ''); const response = await this.request<string[][]>('GET', '/api/v2/mix/market/candles', { productType: 'USDT-FUTURES', symbol: cleanSymbol, granularity: this.formatIntervalForFuturesAPI(interval), // Format interval for futures API limit: limit.toString() }); if (!response.data || response.data.length === 0) { return []; } return response.data.map(candle => ({ symbol: symbol, // Keep original symbol format timestamp: parseInt(candle[0]), open: candle[1], high: candle[2], low: candle[3], close: candle[4], volume: candle[5] })); } else { // Spot candles const response = await this.request<string[][]>('GET', '/api/v2/spot/market/candles', { symbol, granularity: this.formatIntervalForSpotAPI(interval), // Format interval for spot API limit: limit.toString() }); if (!response.data || response.data.length === 0) { return []; } return response.data.map(candle => ({ symbol, timestamp: parseInt(candle[0]), open: candle[1], high: candle[2], low: candle[3], close: candle[4], volume: candle[5] })); } }
  • MCP server tool handler for 'getCandles': parses input arguments using GetCandlesSchema, calls BitgetRestClient.getCandles, returns JSON-formatted response.
    case 'getCandles': { const { symbol, interval, limit = 100 } = GetCandlesSchema.parse(args); const candles = await this.bitgetClient.getCandles(symbol, interval, limit); return { content: [ { type: 'text', text: JSON.stringify(candles, null, 2), }, ], } as CallToolResult; }
  • Zod schema for validating getCandles tool input parameters: symbol, interval (with extensive enum), optional limit.
    export const GetCandlesSchema = z.object({ symbol: z.string().describe('Trading pair symbol (BTCUSDT for spot, BTCUSDT_UMCBL for futures)'), interval: z.enum([ // Minutes (lowercase) '1m', '3m', '5m', '15m', '30m', // Hours (can be lowercase, will be converted) '1h', '4h', '6h', '12h', '1H', '4H', '6H', '12H', // Days/Weeks/Months (can be lowercase, will be converted) '1d', '1w', '1D', '1W', '1M', // UTC variants '6Hutc', '12Hutc', '1Dutc', '3Dutc', '1Wutc', '1Mutc' ]).describe('Candle interval - API will auto-format to correct case'), limit: z.number().optional().describe('Number of candles (default: 100)') });
  • src/server.ts:138-148 (registration)
    Tool registration in ListTools response: defines name 'getCandles', description, and simplified inputSchema for MCP client discovery.
    name: 'getCandles', description: 'Get historical candlestick/OHLCV data', inputSchema: { type: 'object', properties: { symbol: { type: 'string', description: 'Trading pair symbol' }, interval: { type: 'string', enum: ['1m', '5m', '15m', '30m', '1h', '4h', '1d'], description: 'Candle interval' }, limit: { type: 'number', description: 'Number of candles (default: 100)' } }, required: ['symbol', 'interval'] },

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