pyth
Rust client for the Pyth Network Hermes API.
Pyth Network provides real-time price feeds for crypto, equities, FX, and commodities. This crate interfaces with the Hermes REST API to fetch price data.
Installation
Add to your Cargo.toml:
[]
= { = "0.1", = "../pyth" }
Quick Start
use ;
async
Features
- No API key required - Hermes API is free to use
- Multiple price feeds - Fetch prices for multiple assets in a single request
- Symbol mapping - Use common symbols (ETH, BTC) instead of feed IDs
- Stale detection - Built-in check for outdated price data
- Confidence intervals - Access price confidence data
API Coverage
Implemented Endpoints
| Endpoint | Method | Description |
|---|---|---|
/v2/updates/price/latest |
get_latest_prices() |
Get latest prices for multiple feeds |
/v2/updates/price/latest |
get_latest_price() |
Get latest price for a single feed |
/v2/price_feeds |
get_price_feed_ids() |
List all available price feeds |
/v2/price_feeds?query= |
search_feeds() |
Search feeds by symbol/name |
/v2/price_feeds?asset_type= |
get_feeds_by_asset_type() |
Filter feeds by asset type |
Supported Symbols
The following symbols are mapped to Pyth feed IDs:
| Symbol | Aliases | Feed |
|---|---|---|
| BTC | BITCOIN, WBTC | BTC/USD |
| ETH | ETHEREUM, WETH | ETH/USD |
| SOL | SOLANA | SOL/USD |
| USDC | - | USDC/USD |
| USDT | TETHER | USDT/USD |
| LINK | CHAINLINK | LINK/USD |
| ARB | ARBITRUM | ARB/USD |
| OP | OPTIMISM | OP/USD |
| AAVE | - | AAVE/USD |
| UNI | UNISWAP | UNI/USD |
| CRV | CURVE | CRV/USD |
| CVX | CONVEX | CVX/USD |
| MKR | MAKER | MKR/USD |
| SNX | SYNTHETIX | SNX/USD |
| LDO | LIDO | LDO/USD |
| DAI | - | DAI/USD |
You can also use feed IDs directly:
let price = client.get_latest_price.await?;
Examples
Fetch Multiple Prices
use ;
let client = new?;
let feeds = client.get_latest_prices.await?;
for feed in feeds
Search for Feeds
use Client;
let client = new?;
// Search for BTC-related feeds
let feeds = client.search_feeds.await?;
for feed in feeds
Symbol Lookup
use ;
let client = new?;
// Convert symbol to feed ID
if let Some = symbol_to_feed_id
Check Price Staleness
use ;
let client = new?;
if let Some = client.get_latest_price.await?
Use Testnet
use Client;
let client = testnet?;
let price = client.get_latest_price.await?;
Custom Configuration
use ;
use Duration;
let config = mainnet
.with_timeout
.with_proxy;
let client = with_config?;
Configuration
Base URLs
| Network | URL |
|---|---|
| Mainnet | https://hermes.pyth.network |
| Testnet | https://hermes-beta.pyth.network |
Timeouts
Default timeout is 30 seconds. Configure with:
use Config;
use Duration;
let config = mainnet
.with_timeout;
Error Handling
use ;
let client = new?;
match client.get_latest_price.await
Types
ParsedPriceFeed
PriceData
License
MIT