Skip to main content
Glama
ethancod1ng

Bybit MCP Server

by ethancod1ng

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
NameRequiredDescriptionDefault
symbolYes
intervalYes
limitNo

Implementation Reference

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

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/ethancod1ng/bybit-mcp-server'

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