Skip to main content
Glama

get_kline

Retrieve candlestick (K-line) data for a specific trading pair and time interval. Specify category, symbol, interval, and optional start, end, and limit parameters to analyze market trends and price movements.

Instructions

Get K-line (candlestick) data Args: category (str): Category (spot, linear, inverse, etc.) symbol (str): Symbol (e.g., BTCUSDT) interval (str): Time interval (1, 3, 5, 15, 30, 60, 120, 240, 360, 720, D, W, M) start (Optional[int]): Start time in milliseconds end (Optional[int]): End time in milliseconds limit (int): Number of records to retrieve Returns: Dict: K-line data Example: get_kline("spot", "BTCUSDT", "1h", 1625097600000, 1625184000000, 100) Reference: https://bybit-exchange.github.io/docs/v5/market/kline

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
categoryYesCategory (spot, linear, inverse, etc.)
endNoEnd time in milliseconds
intervalYesTime interval (1, 3, 5, 15, 30, 60, 120, 240, 360, 720, D, W, M)
limitNoNumber of records to retrieve
startNoStart time in milliseconds
symbolYesSymbol (e.g., BTCUSDT)

Implementation Reference

  • The primary MCP tool handler for 'get_kline'. Decorated with @mcp.tool(), uses Pydantic Field for input schema/validation, calls BybitService.get_kline, handles errors and returns the API response.
    @mcp.tool() def get_kline( category: str = Field(description="Category (spot, linear, inverse, etc.)"), symbol: str = Field(description="Symbol (e.g., BTCUSDT)"), interval: str = Field(description="Time interval (1, 3, 5, 15, 30, 60, 120, 240, 360, 720, D, W, M)"), start: Optional[int] = Field(default=None, description="Start time in milliseconds"), end: Optional[int] = Field(default=None, description="End time in milliseconds"), limit: int = Field(default=200, description="Number of records to retrieve") ) -> Dict: """ Get K-line (candlestick) data Args: category (str): Category (spot, linear, inverse, etc.) symbol (str): Symbol (e.g., BTCUSDT) interval (str): Time interval (1, 3, 5, 15, 30, 60, 120, 240, 360, 720, D, W, M) start (Optional[int]): Start time in milliseconds end (Optional[int]): End time in milliseconds limit (int): Number of records to retrieve Returns: Dict: K-line data Example: get_kline("spot", "BTCUSDT", "1h", 1625097600000, 1625184000000, 100) Reference: https://bybit-exchange.github.io/docs/v5/market/kline """ try: result = bybit_service.get_kline(category, symbol, interval, start, end, limit) if result.get("retCode") != 0: logger.error(f"Failed to get K-line data: {result.get('retMsg')}") return {"error": result.get("retMsg")} return result except Exception as e: logger.error(f"Failed to get K-line data: {e}", exc_info=True) return {"error": str(e)}
  • Helper method in BybitService class that prepares parameters and calls the pybit.unified_trading.HTTP client's get_kline method to fetch actual K-line data from Bybit API.
    def get_kline(self, category: str, symbol: str, interval: str, start: Optional[int] = None, end: Optional[int] = None, limit: int = 200) -> Dict: """ Get K-line data Args: category: Category (spot, linear, inverse, etc.) symbol: Symbol (e.g., BTCUSDT) interval: Time interval (1, 3, 5, 15, 30, 60, 120, 240, 360, 720, D, W, M) start: Start time (millisecond timestamp) end: End time (millisecond timestamp) limit: Number of records to retrieve Returns: Dict: K-line data """ try: params = { "category": category, "symbol": symbol, "interval": interval, "limit": limit } if start: params["start"] = start if end: params["end"] = end response = self.client.get_kline(**params) return response except Exception as e: logger.error(f"Failed to get K-line data: {str(e)}") return {"error": str(e)}
  • src/server.py:92-92 (registration)
    The @mcp.tool() decorator registers the get_kline function as an MCP tool.
    @mcp.tool()
  • Pydantic Field definitions provide the input schema and descriptions for the MCP tool parameters.
    category: str = Field(description="Category (spot, linear, inverse, etc.)"), symbol: str = Field(description="Symbol (e.g., BTCUSDT)"), interval: str = Field(description="Time interval (1, 3, 5, 15, 30, 60, 120, 240, 360, 720, D, W, M)"), start: Optional[int] = Field(default=None, description="Start time in milliseconds"), end: Optional[int] = Field(default=None, description="End time in milliseconds"), limit: int = Field(default=200, description="Number of records to retrieve") ) -> Dict:

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

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