Crate simple_pyth_client_rs

Source
Expand description

ยงPyth Price Feed API Wrapper (Rust)

A high-performance, async Rust SDK to query and stream live crypto prices using the Pyth Hermes API.

Built to provide a simpler way to interract with Pyth Hermes crypto price feeds. Search by symbols, get token prices and price streams.

ยงโœจ Features

  • Fetch live and historical token prices (price + EMA)
  • Stream real-time price updates
  • Filter tokens by human-readable symbols
  • Powered by reqwest, tokio, serde, futures

ยง๐Ÿ“š Examples

#[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(())
}

ยง๐Ÿ“‚ Data Types

ยงPriceFeed

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,
}

ยงTokenPriceInfo

pub struct TokenPriceInfo {
    pub name: String,
    pub token_id: String,
    pub token_symbol: String,
    pub price_30s: f64,
    pub price_1m: f64,
    pub timestamp: i64,
    pub fluctuation_pct: f64,
}

ยง๐Ÿ”ง Core Methods

  • get_price_feeds() โ€” Get metadata for all supported crypto/USD price feeds
  • get_token_price_info(ids) โ€” Get current price info for specific or all tokens
  • get_live_price_stream(ids, callback) โ€” Stream price updates and handle them with a callback
  • get_price_stream_for_duration(ids, duration_secs, tx) โ€” Stream prices for a set duration
  • search_by_token_symbols(symbols) โ€” Search and fetch prices using readable token symbols

ยงโœ… Requirements

  • Rust 1.70+
  • Tokio async runtime

ยง๐Ÿ“… License

MIT


Built with โค๏ธ by Joshthebuilda

Re-exportsยง

pub use client::get_live_price_stream;
pub use client::get_price_feeds;
pub use client::get_price_stream_for_duration;
pub use client::get_token_price_info;
pub use client::search_by_token_symbols;

Modulesยง

client
types