2 stable releases
new 1.1.0 | Apr 30, 2025 |
---|---|
1.0.2 | Apr 25, 2025 |
#1553 in Network programming
104 downloads per month
23KB
368 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
- Fetch available networks
- Retrieve whitelists for specific networks
- Get latest price feeds for specified assets on a given network
Usage
To use this library in your Rust project, add it to your Cargo.toml
:
[dependencies]
orao-price-service = { version = "1.0.2" }
Then, in your Rust code:
use orao_price_service::{PriceService, PriceServiceConfig};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize the PriceService
let price_service = PriceService::new(
"https://api.example.com",
Some(PriceServiceConfig {
auth_token: Some("your_auth_token".to_string()),
timeout: Some(5000),
http_retries: Some(3),
})
);
// Get available networks
let networks = price_service.get_networks().await?;
println!("Available networks: {:?}", networks);
// Get whitelist for a specific network
let whitelist = price_service.get_whitelist("price-secp256k1").await?;
println!("price-secp256k1 whitelist: {:?}", whitelist);
// Get latest price feeds
let asset_names = vec!["bitcoin".to_string(), "ethereum".to_string()];
let price_feed = price_service.get_latest_price_feeds("price-secp256k1", &asset_names).await?;
println!("Latest price feed: {:?}", price_feed);
Ok(())
}
API Reference
PriceService::new(endpoint: &str, config: Option<PriceServiceConfig>) -> Self
Creates a new instance of PriceService
.
PriceService::get_networks() -> Result<Vec<String>>
Retrieves a list of available networks.
PriceService::get_whitelist(network: &str) -> Result<Vec<String>>
Retrieves the whitelist for a specified network.
PriceService::get_latest_price_feeds(network: &str, asset_names: &[String]) -> Result<PriceFeed>
Retrieves the latest price feeds for specified assets on a given network.
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
~10–24MB
~322K SLoC