get_funding_rate_history
Retrieve historical funding rate data for cryptocurrency trading pairs to analyze market trends and funding costs over time.
Instructions
Fetch Funding Rate History data from Aster Finance API and return as Markdown table text.
Parameters:
symbol (str): Trading pair symbol (e.g., 'BTCUSDT', 'ETHUSDT'). Case-insensitive.
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 funding rate records to return (1 to 1000). If None, defaults to 100.
Returns:
str: Markdown table containing symbol, fundingTime, and fundingRate.
Raises:
Exception: If the API request fails or data processing encounters an error.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes | ||
| startTime | No | ||
| endTime | No | ||
| limit | No |
Implementation Reference
- main.py:311-374 (handler)The complete handler function for the 'get_funding_rate_history' tool, decorated with @mcp.tool() for registration. It fetches funding rate history from the Aster Finance API (/fapi/v1/fundingRate), processes the data using pandas into a formatted Markdown table, with input parameters defining the schema via type hints and docstring.async def get_funding_rate_history( symbol: str, startTime: Optional[int] = None, endTime: Optional[int] = None, limit: Optional[int] = None ) -> str: """ Fetch Funding Rate History data from Aster Finance API and return as Markdown table text. Parameters: symbol (str): Trading pair symbol (e.g., 'BTCUSDT', 'ETHUSDT'). Case-insensitive. 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 funding rate records to return (1 to 1000). If None, defaults to 100. Returns: str: Markdown table containing symbol, fundingTime, and fundingRate. Raises: Exception: If the API request fails or data processing encounters an error. """ endpoint = "/fapi/v1/fundingRate" # Construct query parameters params = { "symbol": symbol.upper(), # Ensure symbol is uppercase (e.g., BTCUSDT) } 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 funding_data: List[dict] = response.json() # Create pandas DataFrame df = pd.DataFrame(funding_data) # Convert fundingTime to readable format df["fundingTime"] = pd.to_datetime(df["fundingTime"], unit="ms") # Select relevant columns and format numbers df = df[["symbol", "fundingTime", "fundingRate"]] df["fundingRate"] = df["fundingRate"].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 Funding Rate data: {str(e)}")