Pyth Price Feed API Wrapper (Rust)
A high-performance, async Rust SDK that lets you query and stream live crypto prices using the Pyth Hermes API. Built with a focus on simplicity, performance, and extensibility — ideal for financial tooling, bots, dashboards, and DEXs.
✨ Features
- 🔍 Fetch live and historical token prices (price + EMA)
- 📈 Stream real-time price updates with low latency
- 🔄 Built-in USD filtering for all tracked tokens
- ⚖️ Flexible architecture ready for extension
- ⚡ Powered by
reqwest
,tokio
, andfutures
📦 Installation
Requires Rust 1.70+ and Tokio async runtime
Add the following to your Cargo.toml
:
[]
= { = "0.11", = ["json", "stream"] }
= { = "1", = ["full"] }
= "0.3"
= { = "1", = ["derive"] }
= "1"
= "1"
= "1.19"
🚀 Quickstart
async
📘️ API Methods
get_price_feeds() -> Result<Vec<PriceFeed>>
Fetches the complete list of Pyth price feeds for crypto
pairs.
get_token_price_info(ids: &Vec<String>) -> Result<Vec<TokenPriceInfo>>
Returns detailed price info (price, EMA, timestamp, fluctuation) for specified feeds. If ids
is None
, defaults to all tracked tokens.
get_live_price_stream(ids: &Vec<String>, callback: F)
Streams live price updates for the given token IDs, calling the callback
with Vec<TokenPriceInfo>
as each update arrives.
get_live_price_stream.await?;
get_price_stream_for_duration(ids, duration_secs, tx)
Streams prices for a limited duration and sends each TokenPriceInfo
to the provided tokio::mpsc::Sender
.
search_by_token_symbols(symbols: Vec<&str>) -> Result<Vec<TokenPriceInfo>>
Search for live prices using human-readable symbols (e.g., "BTC"
, "ETH"
).
let result = search_by_token_symbols.await?;
for r in result
🧱 Types
PriceFeed
Represents metadata about each token's price feed, including ID, symbol, and display format.
TokenPriceInfo
🛠️ Notes
- Price data includes a 30s price and 1m EMA, which you can use for basic volatility analysis.
apply_exponent
handles converting scientific notation with a decimal exponent.
📜 License
MIT — feel free to fork, use, and modify.
✍️ Author
Joshthebuilda 5+ years building fullstack crypto and developer infrastructure Portfolio • LinkedIn