get_premium_index
Retrieve Premium Index data for trading pairs from the Aster Finance API, formatted as a Markdown table. Input a specific symbol or fetch all data with ease.
Instructions
Fetch Premium Index data 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, markPrice, indexPrice, lastFundingRate, and nextFundingTime.
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:248-307 (handler)The handler function for the 'get_premium_index' tool. Decorated with @mcp.tool() for registration and schema inference. Fetches premium index data from AsterDex API, processes it into a pandas DataFrame, formats numbers and timestamps, and returns a Markdown table.@mcp.tool() async def get_premium_index( symbol: Optional[str] = None ) -> str: """ Fetch Premium Index data 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, markPrice, indexPrice, lastFundingRate, and nextFundingTime. Raises: Exception: If the API request fails or data processing encounters an error. """ endpoint = "/fapi/v1/premiumIndex" # 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 premium_data = response.json() # Handle single symbol (dict) or all symbols (list of dicts) if isinstance(premium_data, dict): premium_data = [premium_data] # Create pandas DataFrame df = pd.DataFrame(premium_data) # Convert nextFundingTime to readable format df["nextFundingTime"] = pd.to_datetime(df["nextFundingTime"], unit="ms") # Select relevant columns and format numbers df = df[["symbol", "markPrice", "indexPrice", "lastFundingRate", "nextFundingTime"]] df["markPrice"] = df["markPrice"].astype(float).round(8) df["indexPrice"] = df["indexPrice"].astype(float).round(8) df["lastFundingRate"] = df["lastFundingRate"].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 Premium Index data: {str(e)}")