get_price_percentage
Calculate the percentage change in cryptocurrency prices over a specified period by providing token details and optional timestamp. Designed for tracking price trends without managing individual API keys.
Instructions
GET /coins/percentage/{coins}
Get percentage change in price over time.
Parameters:
coins: comma-separated tokens in format {chain}:{address}
timestamp: timestamp of data point (defaults to now)
look_forward: whether to look forward from timestamp (default: False)
period: duration between data points (default: '24h')
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| coins | Yes | ||
| look_forward | No | ||
| period | No | 24h | |
| timestamp | No |
Implementation Reference
- defillama_server.py:695-719 (handler)The handler function for the 'get_price_percentage' MCP tool. It is registered via the @mcp.tool() decorator and implements the logic to query the DefiLlama API for percentage price changes of specified coins over a given period, handling parameters like timestamp and look_forward direction.@mcp.tool() async def get_price_percentage( coins: str, timestamp: Optional[int] = None, look_forward: bool = False, period: str = "24h" ) -> str: """GET /coins/percentage/{coins} Get percentage change in price over time. Parameters: coins: comma-separated tokens in format {chain}:{address} timestamp: timestamp of data point (defaults to now) look_forward: whether to look forward from timestamp (default: False) period: duration between data points (default: '24h') """ params = { 'lookForward': str(look_forward).lower(), 'period': period } if timestamp is not None: params['timestamp'] = timestamp result = await make_request('GET', f'/coins/percentage/{coins}', params) return str(result)
- defillama_server.py:696-719 (schema)The function signature and docstring define the input schema/parameters for the tool, including types and descriptions matching the DefiLlama API requirements.async def get_price_percentage( coins: str, timestamp: Optional[int] = None, look_forward: bool = False, period: str = "24h" ) -> str: """GET /coins/percentage/{coins} Get percentage change in price over time. Parameters: coins: comma-separated tokens in format {chain}:{address} timestamp: timestamp of data point (defaults to now) look_forward: whether to look forward from timestamp (default: False) period: duration between data points (default: '24h') """ params = { 'lookForward': str(look_forward).lower(), 'period': period } if timestamp is not None: params['timestamp'] = timestamp result = await make_request('GET', f'/coins/percentage/{coins}', params) return str(result)
- defillama_server.py:695-695 (registration)The @mcp.tool() decorator registers this function as an MCP tool named 'get_price_percentage' with the FastMCP server.@mcp.tool()
- defillama_server.py:30-37 (helper)Shared helper function used by the get_price_percentage tool (and all others) to make HTTP requests to the DefiLlama API.async def make_request(method: str, endpoint: str, params: Optional[Dict[str, Any]] = None) -> Any: """Make a request to the DefiLlama API.""" try: response = await client.request(method, endpoint, params=params) response.raise_for_status() return response.json() except Exception as e: return f"Error: {str(e)}"