Skip to content

A much simpler rust wrapper for Pyth Hermes crypto price feeds. Search by symbols, get token prices and price streams.

Notifications You must be signed in to change notification settings

Parallax18/simple-pyth-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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, and futures

📦 Installation

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"

🚀 Quickstart

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

📘️ 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(&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);
}

🧱 Types

PriceFeed

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

TokenPriceInfo

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

🛠️ 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 PortfolioLinkedIn

About

A much simpler rust wrapper for Pyth Hermes crypto price feeds. Search by symbols, get token prices and price streams.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages