2 stable releases
1.1.0 | Apr 30, 2025 |
---|---|
1.0.2 | Apr 25, 2025 |
#214 in Testing
255 downloads per month
25KB
419 lines
ORAO Price Service
This Rust library provides a client for interacting with the ORAO Price Service API. It allows users to fetch price feeds for various assets across different networks.
Features
- Retrieve whitelists
- Get latest price feeds for specified assets
Usage
To use this library in your Rust project, add it to your Cargo.toml
:
[dependencies]
orao-oracles-price-service = { version = "1.1.0" }
Then, in your Rust code:
use orao_oracles_price_service::{Secp256k1PriceService, PriceServiceConfig};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize the PriceService
let price_service = Secp256k1PriceService::new(
"https://api.example.com",
Some(PriceServiceConfig {
auth_token: Some("your_auth_token".to_string()),
timeout: Some(5000),
http_retries: Some(3),
})
);
// Get whitelist
let whitelist = price_service.get_whitelist().await?;
println!("evm whitelist: {:?}", whitelist);
// Get latest price feeds
let asset_names = vec!["bitcoin", "ethereum"];
let price_feed = price_service.get_latest_price_feeds(&asset_names).await?;
println!("Latest price feed: {:?}", price_feed);
// Get price feeds update data for contract call
let price_feeds_update_data = price_service.get_price_feeds_update_data(&price_feed);
println!("{:?}", price_feeds_update_data);
Ok(())
}
Supported Networks
Network | Service name |
---|---|
evm | Secp256k1PriceService |
fuel | Ed25519PriceService |
solana | Ed25519PriceService |
API Reference
EVMPriceService::new(endpoint: &str, config: Option<PriceServiceConfig>) -> Self
Creates a new instance of PriceService
.
EVMPriceService::get_whitelist() -> Result<Vec<String>>
Retrieves the whitelist.
EVMPriceService::get_latest_price_feeds(asset_names: &[&str]) -> Result<PriceFeed>
Retrieves the latest price feeds for specified assets.
Error Handling
All methods return a Result
type, allowing for proper error handling. Errors can occur due to network issues, parsing
problems, or invalid responses from the API.
Logging
This library uses the tracing
crate for logging. You can initialize logging by calling the init_tracing()
function
provided in the library.
Dependencies
~12–25MB
~332K SLoC