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.
- 🔍 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
Requires Rust 1.70+ and Tokio async runtime
Add the following to your Cargo.toml:
[dependencies]
reqwest = { version = "0.11", features = ["json", "stream"] }
tokio = { version = "1", features = ["full"] }
futures = "0.3"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
anyhow = "1"
once_cell = "1.19"#[tokio::main]
async fn main() -> anyhow::Result<()> {
use simple_pyth_client_rs::*;
// Search for specific crypto/USD pairs
let symbols = vec!["BTC", "ETH", "USDC", "SOL", "USDT"];
let price_feeds = search_by_token_symbols(symbols).await?;
println!("{:?}", price_feeds);
Ok(())
}Fetches the complete list of Pyth price feeds for crypto pairs.
Returns detailed price info (price, EMA, timestamp, fluctuation) for specified feeds. If ids is None, defaults to all tracked tokens.
Streams live price updates for the given token IDs, calling the callback with Vec<TokenPriceInfo> as each update arrives.
get_live_price_stream(&vec![...], |prices| async move {
for p in prices {
println!("Live: {} = {}", p.token_symbol, p.price_30s);
}
}).await?;Streams prices for a limited duration and sends each TokenPriceInfo to the provided tokio::mpsc::Sender.
Search for live prices using human-readable symbols (e.g., "BTC", "ETH").
let result = search_by_token_symbols(vec!["btc", "doge"]).await?;
for r in result {
println!("{} → ${}", r.token_symbol, r.price_30s);
}Represents metadata about each token's price feed, including ID, symbol, and display format.
pub struct PriceFeed {
pub id: String,
pub attributes: Attr,
}
pub struct Attr {
pub asset_type: String,
pub base: String,
pub description: String,
pub display_symbol: String,
pub generic_symbol: String,
pub quote_currency: String,
pub schedule: String,
pub symbol: String,
}struct TokenPriceInfo {
name: String,
token_id: String,
token_symbol: String,
price_30s: f64,
price_1m: f64,
timestamp: i64,
fluctuation_pct: f64,
}- Price data includes a 30s price and 1m EMA, which you can use for basic volatility analysis.
apply_exponenthandles converting scientific notation with a decimal exponent.
MIT — feel free to fork, use, and modify.
Joshthebuilda 5+ years building fullstack crypto and developer infrastructure Portfolio • LinkedIn