get_price_change_statistics_24h
Fetch 24-hour cryptocurrency price change statistics from Aster Finance API and display as a Markdown table with symbol, price change, percentage change, last price, and volume.
Instructions
Fetch 24-hour ticker price change statistics from Aster Finance API and return as Markdown table text.
Parameters:
symbol (Optional[str]): Trading pair symbol (e.g., 'BTCUSDT', 'ETHUSDT'). Case-insensitive.
If None, returns data for all symbols.
Returns:
str: Markdown table containing symbol, priceChange, priceChangePercent, lastPrice, and volume.
Raises:
Exception: If the API request fails or data processing encounters an error.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | No |
Implementation Reference
- main.py:377-434 (handler)The handler function for the 'get_price_change_statistics_24h' tool. It is registered via the @mcp.tool() decorator. Fetches 24hr ticker statistics from Asterdex API, processes with pandas DataFrame, formats numbers, and returns a Markdown table.@mcp.tool() async def get_price_change_statistics_24h( symbol: Optional[str] = None ) -> str: """ Fetch 24-hour ticker price change statistics from Aster Finance API and return as Markdown table text. Parameters: symbol (Optional[str]): Trading pair symbol (e.g., 'BTCUSDT', 'ETHUSDT'). Case-insensitive. If None, returns data for all symbols. Returns: str: Markdown table containing symbol, priceChange, priceChangePercent, lastPrice, and volume. Raises: Exception: If the API request fails or data processing encounters an error. """ endpoint = "/fapi/v1/ticker/24hr" # Construct query parameters params = {} if symbol is not None: params["symbol"] = symbol.upper() # Ensure symbol is uppercase (e.g., BTCUSDT) 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 ticker_data = response.json() # Handle single symbol (dict) or all symbols (list of dicts) if isinstance(ticker_data, dict): ticker_data = [ticker_data] # Create pandas DataFrame df = pd.DataFrame(ticker_data) # Select relevant columns and format numbers df = df[["symbol", "priceChange", "priceChangePercent", "lastPrice", "volume"]] df["priceChange"] = df["priceChange"].astype(float).round(8) df["priceChangePercent"] = df["priceChangePercent"].astype(float).round(2) df["lastPrice"] = df["lastPrice"].astype(float).round(8) df["volume"] = df["volume"].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 24-hour price change statistics: {str(e)}")
- main.py:377-377 (registration)The @mcp.tool() decorator registers the get_price_change_statistics_24h function as an MCP tool.@mcp.tool()
- main.py:378-393 (schema)The function signature and docstring define the input schema (symbol: Optional[str]) and output (str Markdown table).async def get_price_change_statistics_24h( symbol: Optional[str] = None ) -> str: """ Fetch 24-hour ticker price change statistics from Aster Finance API and return as Markdown table text. Parameters: symbol (Optional[str]): Trading pair symbol (e.g., 'BTCUSDT', 'ETHUSDT'). Case-insensitive. If None, returns data for all symbols. Returns: str: Markdown table containing symbol, priceChange, priceChangePercent, lastPrice, and volume. Raises: Exception: If the API request fails or data processing encounters an error. """