use super::types::*;
use crate::client::Client;
use crate::error::Result;
pub struct SimpleApi<'a> {
client: &'a Client,
}
impl<'a> SimpleApi<'a> {
pub fn new(client: &'a Client) -> Self {
Self { client }
}
pub async fn price(&self, ids: &[&str], vs_currencies: &[&str]) -> Result<PricesResponse> {
let path = format!(
"/simple/price?ids={}&vs_currencies={}",
ids.join(","),
vs_currencies.join(",")
);
self.client.get(&path).await
}
pub async fn price_with_options(
&self,
ids: &[&str],
vs_currencies: &[&str],
options: &PriceOptions,
) -> Result<PricesResponse> {
let path = format!(
"/simple/price?ids={}&vs_currencies={}{}",
ids.join(","),
vs_currencies.join(","),
options.to_query_string()
);
self.client.get(&path).await
}
pub async fn token_price(
&self,
platform: &str,
contract_addresses: &[&str],
vs_currencies: &[&str],
) -> Result<TokenPricesResponse> {
let path = format!(
"/simple/token_price/{}?contract_addresses={}&vs_currencies={}",
platform,
contract_addresses.join(","),
vs_currencies.join(",")
);
self.client.get(&path).await
}
pub async fn supported_vs_currencies(&self) -> Result<SupportedCurrencies> {
self.client.get("/simple/supported_vs_currencies").await
}
}