Fetch Price
The Fetch Price
tool, part of AgentiPy, allows users to fetch the price of a given token in USDC by querying the Jupiter API (https://api.jup.ag/price/v2
). It's a simple way to get current price data for a specific token mint address on Solana.
Functionality
This tool is implemented in the TokenPriceFetcher
class.
Key Methods:
fetch_price(token_id: str) -> str
:Takes a
token_id
(the token mint address as a string) as input.Constructs a URL to query the Jupiter API.
Uses
aiohttp
to make an asynchronous GET request to the API.Parses the JSON response to extract the price of the token in USDC.
Returns the price as a string.
Raises an exception if the API request fails, the response status is not 200, or if price data for the token is not available in the response.
Note: This tool relies on the public Jupiter API. Availability and rate limits of the API are determined by Jupiter Aggregator. The returned price is typically in USDC.
Source Code
You can find the source code for this tool on GitHub: https://github.com/niceberginc/agentipy/blob/main/agentipy/tools/fetch_price.py
Last updated