use std::time::Duration;
use one_inch::client::{self, SupportedCurrencies, SupportedNetworks};
use one_inch::tokens::tokens_price::TokensPricesRequestBuilder;
#[tokio::main]
async fn main() {
let network_id = SupportedNetworks::BSC;
let token = env!("ONE_INCH_API_TOKEN");
let client = client::new_with_default_http(token.into(), network_id);
let currencies = client.get_custom_currencies().await.map_err(|e| {
eprintln!("Error while making get currencies request: {}", e)
}).unwrap();
println!("Total currencies supported : {}", ¤cies.codes.len());
println!("All the currencies list : ");
for cr in currencies.codes.iter() {
print!("{}, ", cr);
}
println!();
std::thread::sleep(Duration::from_secs(5));
let my_tokens_list: Vec<String> = vec![
"0xce7de646e7208a4ef112cb6ed5038fa6cc6b12e3".into(), "0x1d2f0da169ceb9fc7b3144628db156f3f6c60dbe".into(), "0xba2ae424d960c26247dd6c32edc70b295c744c43".into(), "0x7083609fce4d1d8dc0c979aab8c869ea2c873402".into(), ];
let get_prices_details = TokensPricesRequestBuilder::new()
.addresses(my_tokens_list.clone())
.currency(SupportedCurrencies::USD).build().unwrap();
let prices_usd = client.get_tokens_price(get_prices_details).await
.map_err(|e| eprintln!("Error while getting prices for tokens to usd : {e}"))
.unwrap();
for token in &my_tokens_list {
match prices_usd.prices.get(token) {
Some(price) => println!("Price for token {}: {}", token, price),
None => eprintln!("Price for token {} not found", token),
}
}
}