Skip to main content
Glama
kukapay

aster-info-mcp

get_order_book

Fetch real-time order book data for trading pairs and display it as a structured Markdown table with bid/ask prices and quantities.

Instructions

Fetch order book 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 order book entries to return (5, 10, 20, 50, 100, 500, 1000, 5000).
                          If None, defaults to 100.

Returns:
    str: Markdown table containing side (bid or ask), price, and quantity.

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

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
symbolYes
limitNo

Implementation Reference

  • main.py:554-623 (handler)
    The handler function 'get_order_book' fetches order book data from the Aster Finance API (/fapi/v1/depth), processes bids and asks into a pandas DataFrame, formats it, and returns a Markdown table. The @mcp.tool() decorator registers the tool and infers the input schema from the function signature (symbol: str, optional limit: int).
    @mcp.tool()
    async def get_order_book(
        symbol: str,
        limit: Optional[int] = None
    ) -> str:
        """
        Fetch order book 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 order book entries to return (5, 10, 20, 50, 100, 500, 1000, 5000).
                                  If None, defaults to 100.
        
        Returns:
            str: Markdown table containing side (bid or ask), price, and quantity.
        
        Raises:
            Exception: If the API request fails or data processing encounters an error.
        """
        endpoint = "/fapi/v1/depth"
        
        # 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
                order_book_data = response.json()
                
                # Extract bids and asks
                bids = order_book_data.get("bids", [])
                asks = order_book_data.get("asks", [])
                
                # Create DataFrames for bids and asks
                bids_df = pd.DataFrame(bids, columns=["price", "quantity"])
                bids_df["side"] = "bid"
                asks_df = pd.DataFrame(asks, columns=["price", "quantity"])
                asks_df["side"] = "ask"
                
                # Combine bids and asks, sorting by price (descending for bids, ascending for asks)
                df = pd.concat([bids_df, asks_df], ignore_index=True)
                df["price"] = df["price"].astype(float)
                df = df.sort_values(by=["side", "price"], ascending=[True, False])
                
                # Format numbers
                df["price"] = df["price"].round(8)
                df["quantity"] = df["quantity"].astype(float).round(8)
                
                # Reorder columns
                df = df[["side", "price", "quantity"]]
                
                # 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 order book data: {str(e)}")            
  • main.py:554-554 (registration)
    The @mcp.tool() decorator on get_order_book registers it as an MCP tool.
    @mcp.tool()
  • Input schema inferred from type hints: required 'symbol' (str), optional 'limit' (int). Output: str (Markdown table).
    async def get_order_book(
        symbol: str,
        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