Skip to main content
Glama
kukapay

aster-info-mcp

get_recent_trades

Fetch recent trades data for cryptocurrency pairs and display results in a Markdown table format.

Instructions

Fetch recent trades data from Aster Finance API and return as Markdown table text.

Parameters:
    symbol (str): Trading pair symbol (e.g., 'BTCUSDT', 'ETHUSDT'). Case-insensitive.
    limit (Optional[int]): Number of trades to return (1 to 1000). If None, defaults to 500.

Returns:
    str: Markdown table containing tradeId, price, qty, quoteQty, time, and isBuyerMaker.

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

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
symbolYes
limitNo

Implementation Reference

  • main.py:627-685 (handler)
    The handler function for the 'get_recent_trades' tool. It fetches recent trade data from the Aster Finance API (/fapi/v1/trades endpoint), processes it using pandas into a formatted Markdown table showing trade ID, price, quantity, quote quantity, time, and whether the buyer was the maker.
    async def get_recent_trades(
        symbol: str,
        limit: Optional[int] = None
    ) -> str:
        """
        Fetch recent trades data from Aster Finance API and return as Markdown table text.
        
        Parameters:
            symbol (str): Trading pair symbol (e.g., 'BTCUSDT', 'ETHUSDT'). Case-insensitive.
            limit (Optional[int]): Number of trades to return (1 to 1000). If None, defaults to 500.
        
        Returns:
            str: Markdown table containing tradeId, price, qty, quoteQty, time, and isBuyerMaker.
        
        Raises:
            Exception: If the API request fails or data processing encounters an error.
        """
        endpoint = "/fapi/v1/trades"
        
        # Construct query parameters
        params = {
            "symbol": symbol.upper(),  # Ensure symbol is uppercase (e.g., BTCUSDT)
        }
        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
                trades_data = response.json()
                
                # Create pandas DataFrame
                df = pd.DataFrame(trades_data)
                
                # Convert time to readable format
                df["time"] = pd.to_datetime(df["time"], unit="ms")
                
                # Select relevant columns and format numbers
                df = df[["id", "price", "qty", "quoteQty", "time", "isBuyerMaker"]]
                df = df.rename(columns={"id": "tradeId"})  # Rename id to tradeId for clarity
                df["price"] = df["price"].astype(float).round(8)
                df["qty"] = df["qty"].astype(float).round(8)
                df["quoteQty"] = df["quoteQty"].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 recent trades data: {str(e)}")

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