These examples demonstrate how to use Agentipy's PythManager to fetch real-time, on-chain-verified price feeds from the Pyth Network. The tool supports all Pyth Network price feeds and provides prices with confidence intervals.
Features
Agentipy-Compatible: Seamlessly integrates as a tool within the Agentipy framework.
Async-First: Fully asynchronous implementation for non-blocking performance.
All Feeds Supported: Works with every Pyth Network price feed.
Robust Error Handling: Graceful fallbacks for network issues and invalid addresses.
Confidence Reporting: Returns price with ±confidence interval for data quality checks.
Auto Connection Management: Opens and closes RPC connections automatically.
Code
main1.py (Basic Price Fetching)
This script fetches multiple Pyth feeds concurrently and prints their prices along with confidence intervals.
import asynciofrom agentipy.tools.use_pyth import PythManagerPYTH_FEEDS={"SOL/USD":"H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG","BTC/USD":"GVXRSBjFk6e6J3NbVPXohDJetcTjaeeuykUpbQF8UoMU","AAVE/USD":"3wDLxH34Yz8tGjwHszQ2MfzHwRoaQgKA32uq2bRpjJBW","AEVO/USD":"26emwftTvy4CcXUcPYCHF9PcPHar4kYKfzwM1onYHBCN"}asyncdeffetch_all():asyncdefone(symbol,addr): data =await PythManager.get_price(addr)if data["status"]=="TRADING":print(f"{symbol}: ${data['price']:.4f} ±${data['confidence_interval']:.4f}")else:print(f"{symbol}: {data['status']} — {data.get('message','')}")await asyncio.gather(*(one(s, a)for s, a inPYTH_FEEDS.items()))if__name__=="__main__": asyncio.run(fetch_all())
main2.py (Langchain Integration for Market Analysis)
This script combines Pyth price feeds with a LangChain/OpenAI agent for automated market analysis. It allows users to input a token (predefined like BTC, SOL, ETH, or a custom Pyth feed address) and get an analysis that combines on-chain price data with market news from DuckDuckGo search.