Skip to main content
Glama
kukapay

aster-info-mcp

get_kline

Fetch candlestick chart data for cryptocurrency trading pairs from Aster Finance API and format it as a Markdown table for analysis.

Instructions

Fetch Kline/Candlestick data from Aster Finance API and return as Markdown table text.

Parameters:
    symbol (str): Trading pair symbol (e.g., 'BTCUSDT', 'ETHUSDT'). Case-insensitive.
    interval (str): Kline interval (e.g., '1m' for 1 minute, '1h' for 1 hour, '1d' for 1 day).
    startTime (Optional[int]): Start time in milliseconds since Unix epoch. If None, defaults to API behavior.
    endTime (Optional[int]): End time in milliseconds since Unix epoch. If None, defaults to API behavior.
    limit (Optional[int]): Number of Klines to return (1 to 1500). If None, defaults to 500.

Returns:
    str: Markdown table containing open_time, open, high, low, and close.

Raises:
    Exception: If the API request fails or data processing encounters an error.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
symbolYes
intervalYes
startTimeNo
endTimeNo
limitNo

Implementation Reference

  • main.py:20-94 (handler)
    The handler function for the 'get_kline' tool. It is decorated with @mcp.tool() for automatic registration. Fetches candlestick (Kline) data from the Aster Finance API (/fapi/v1/klines), processes it into a pandas DataFrame, formats the data, and returns it as a Markdown table.
    async def get_kline(
        symbol: str,
        interval: str,
        startTime: Optional[int] = None,
        endTime: Optional[int] = None,
        limit: Optional[int] = None
    ) -> str:
        """
        Fetch Kline/Candlestick data from Aster Finance API and return as Markdown table text.
        
        Parameters:
            symbol (str): Trading pair symbol (e.g., 'BTCUSDT', 'ETHUSDT'). Case-insensitive.
            interval (str): Kline interval (e.g., '1m' for 1 minute, '1h' for 1 hour, '1d' for 1 day).
            startTime (Optional[int]): Start time in milliseconds since Unix epoch. If None, defaults to API behavior.
            endTime (Optional[int]): End time in milliseconds since Unix epoch. If None, defaults to API behavior.
            limit (Optional[int]): Number of Klines to return (1 to 1500). If None, defaults to 500.
        
        Returns:
            str: Markdown table containing open_time, open, high, low, and close.
        
        Raises:
            Exception: If the API request fails or data processing encounters an error.
        """
        endpoint = "/fapi/v1/klines"
        
        # Construct query parameters
        params = {
            "symbol": symbol.upper(),  # Ensure symbol is uppercase (e.g., BTCUSDT)
            "interval": interval,      # e.g., 1m, 1h, 1d
        }
        if startTime is not None:
            params["startTime"] = startTime
        if endTime is not None:
            params["endTime"] = endTime
        if limit is not None:
            params["limit"] = limit
    
        async with httpx.AsyncClient() as client:
            try:
                # Make GET request to the API
                response = await client.get(f"{BASE_URL}{endpoint}", params=params)
                response.raise_for_status()  # Raise exception for 4xx/5xx errors
                
                # Parse JSON response
                kline_data: List[List[Any]] = response.json()
                
                # Create pandas DataFrame
                df = pd.DataFrame(kline_data, columns=[
                    "open_time", "open", "high", "low", "close", "volume",
                    "close_time", "quote_asset_volume", "number_of_trades",
                    "taker_buy_base_asset_volume", "taker_buy_quote_asset_volume", "ignore"
                ])
                
                # Convert timestamps to readable format
                df["open_time"] = pd.to_datetime(df["open_time"], unit="ms")
                
                # Select relevant columns and format numbers
                df = df[["open_time", "open", "high", "low", "close"]]
                df["open"] = df["open"].astype(float).round(8)
                df["high"] = df["high"].astype(float).round(8)
                df["low"] = df["low"].astype(float).round(8)
                df["close"] = df["close"].astype(float).round(8)
                
                # Convert DataFrame to Markdown table
                markdown_table = df.to_markdown(index=False)
                
                return markdown_table
            
            except httpx.HTTPStatusError as e:
                # Handle HTTP errors (e.g., 400, 429)
                raise Exception(f"API request failed: {e.response.status_code} - {e.response.text}")
            except Exception as e:
                # Handle other errors (e.g., network issues, pandas errors)
                raise Exception(f"Error processing Kline data: {str(e)}")
  • main.py:20-20 (registration)
    The @mcp.tool() decorator registers the get_kline function as an MCP tool.
    async def get_kline(
  • main.py:21-26 (schema)
    The function signature defines the input schema with typed parameters and return type.
        symbol: str,
        interval: str,
        startTime: Optional[int] = None,
        endTime: Optional[int] = None,
        limit: Optional[int] = None
    ) -> str:

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/kukapay/aster-info-mcp'

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