get_price_percentage
Calculate percentage price changes for cryptocurrency tokens over specified time periods using chain and address identifiers.
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 | ||
| timestamp | No | ||
| look_forward | No | ||
| period | No | 24h |
Implementation Reference
- defillama_server.py:695-719 (handler)The handler function for the 'get_price_percentage' tool. Decorated with @mcp.tool() for registration. Calls DefiLlama API /coins/percentage/{coins} to get percentage change in price over a specified period.@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:695-695 (registration)The @mcp.tool() decorator registers the get_price_percentage function as an MCP tool.@mcp.tool()
- defillama_server.py:30-37 (helper)Shared helper function used by get_price_percentage 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)}"