Use Pyth Network
The Use Pyth Network
tool, part of AgentiPy, enables users to interact with the Pyth Network on Solana. Its primary function is to fetch real-time token price data from Pyth's on-chain oracles.
Functionality
This tool is implemented in the PythManager
class. It uses the pythclient
library to connect to Pyth Network endpoints and retrieve price information.
Key Methods:
get_price(mint_address: str)
:(Static async method) Fetches the current aggregate price data for a given token
mint_address
(string representing the Pyth price account, which might be different from the SPL token mint for a given asset).It initializes a
SolanaClient
frompythclient
using PythNet's public HTTP/WS endpoints.Creates a
PythPriceAccount
object and callsupdate()
to get the latest price.Returns a dictionary containing:
price
: The aggregate price.confidence_interval
: The confidence interval for the price.status
: The trading status of the price feed (e.g., "TRADING", "NOT_TRADING").message
: An optional message if the status is not "TRADING".
Closes the
solana_client
connection after fetching the price.
Important Considerations:
Direct On-Chain/Oracle Interaction: This tool interacts directly with the Pyth Network's oracle program accounts on Solana via Pyth's defined client endpoints.
Pyth Price Accounts: You must use the correct Pyth price account address for the asset you are interested in. These are specific to Pyth and are not the same as SPL token mint addresses, though they correspond to an underlying asset. Refer to Pyth Network documentation for a list of available price feeds.
Price Status: Always check the
status
field in the response. A status other than "TRADING" (e.g., "UNKNOWN", "HALTED") means the price may not be current or reliable.
Source Code
You can find the source code for this tool on GitHub: https://github.com/niceberginc/agentipy/blob/main/agentipy/tools/use_pyth.py
Last updated