| Crates.io | simple_pyth_client_rs |
| lib.rs | simple_pyth_client_rs |
| version | 0.1.0 |
| created_at | 2025-07-15 10:13:30.950606+00 |
| updated_at | 2025-07-15 10:13:30.950606+00 |
| description | Rust wrapper for Pyth Hermes crypto price feeds |
| homepage | |
| repository | https://github.com/Parallax18/simple-pyth-client |
| max_upload_size | |
| id | 1752927 |
| size | 70,273 |
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.
reqwest, tokio, and futuresRequires 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(())
}
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(&vec![...], |prices| async move {
for p in prices {
println!("Live: {} = {}", p.token_symbol, p.price_30s);
}
}).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(vec!["btc", "doge"]).await?;
for r in result {
println!("{} → ${}", r.token_symbol, r.price_30s);
}
PriceFeedRepresents 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,
}
TokenPriceInfostruct TokenPriceInfo {
name: String,
token_id: String,
token_symbol: String,
price_30s: f64,
price_1m: f64,
timestamp: i64,
fluctuation_pct: f64,
}
apply_exponent handles 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