get_swap_price
Calculate token swap prices using aggregated DeFi liquidity across multiple blockchains for informed trading decisions.
Instructions
Get indicative price for a token swap using Aggregator Protocol
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| chainId | Yes | Blockchain ID (e.g., 1 for Ethereum) | |
| buyToken | Yes | Contract address of token to buy | |
| sellToken | Yes | Contract address of token to sell | |
| sellAmount | Yes | Amount of sellToken in base units | |
| taker | No | Address executing the trade (optional) |
Implementation Reference
- src/services/agService.js:9-27 (handler)Core implementation of getSwapPrice: makes HTTP GET request to aggregator API endpoint /api/swap/price with query parameters
async getSwapPrice(params) { try { const queryParams = new URLSearchParams(params); const response = await fetch(`${this.baseUrl}/api/swap/price?${queryParams}`); if (!response.ok) { throw new Error(`HTTP ${response.status}: ${response.statusText}`); } const data = await response.json(); if (!data.success) { throw new Error(data.error || 'API request failed'); } return data.data; } catch (error) { throw new Error(`Failed to get swap price: ${error.message}`); }