get_klines
Retrieve historical candlestick data for trading symbols from Bybit to analyze market trends and price movements over specified time intervals.
Instructions
Get historical candlestick data for a trading symbol
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes | ||
| interval | Yes | ||
| limit | No |
Implementation Reference
- src/server.ts:69-75 (handler)Handler switch case for the 'get_klines' tool, which extracts arguments and calls the client's getKlines method.case 'get_klines': result = await this.client.getKlines( args.symbol as string, args.interval as string, args.limit as number ); break;
- src/types.ts:35-39 (schema)Zod schema defining input parameters for the get_klines tool: symbol, interval, and optional limit.export const KlinesSchema = z.object({ symbol: z.string().describe('Trading symbol (e.g., BTCUSDT)'), interval: z.enum(['1', '3', '5', '15', '30', '60', '120', '240', '360', '720', 'D', 'M', 'W']).describe('Kline interval'), limit: z.number().min(1).max(1000).optional().describe('Number of klines to return (default: 200)') });
- src/tools.ts:33-41 (registration)Registration of the 'get_klines' tool in the tools array, including name, description, and reference to input schema.{ name: 'get_klines', description: 'Get historical candlestick data for a trading symbol', inputSchema: { type: 'object', properties: KlinesSchema.shape, required: ['symbol', 'interval'] } },
- src/client.ts:48-60 (helper)Helper method in BybitClient wrapper that implements the core logic by calling the Bybit SDK's getKline method for spot category.async getKlines(symbol: string, interval: string, limit: number = 200) { try { const response = await this.client.getKline({ category: 'spot', symbol: symbol, interval: interval as any, limit: limit }); return response; } catch (error) { throw new Error(`Failed to get klines for ${symbol}: ${error instanceof Error ? error.message : JSON.stringify(error)}`); } }