use super::types::*;
use crate::client::Client;
use crate::error::Result;
pub struct OnchainApi<'a> {
client: &'a Client,
}
impl<'a> OnchainApi<'a> {
pub fn new(client: &'a Client) -> Self {
Self { client }
}
pub async fn networks(&self) -> Result<NetworksResponse> {
self.client.get("/onchain/networks").await
}
pub async fn dexes(&self, network: &str) -> Result<DexesResponse> {
let path = format!("/onchain/networks/{}/dexes", network);
self.client.get(&path).await
}
pub async fn trending_pools(&self) -> Result<PoolsResponse> {
self.client.get("/onchain/networks/trending_pools").await
}
pub async fn trending_pools_network(&self, network: &str) -> Result<PoolsResponse> {
let path = format!("/onchain/networks/{}/trending_pools", network);
self.client.get(&path).await
}
pub async fn top_pools(&self, network: &str) -> Result<PoolsResponse> {
let path = format!("/onchain/networks/{}/pools", network);
self.client.get(&path).await
}
pub async fn pool(&self, network: &str, address: &str) -> Result<PoolResponse> {
let path = format!("/onchain/networks/{}/pools/{}", network, address);
self.client.get(&path).await
}
pub async fn new_pools(&self, network: &str) -> Result<PoolsResponse> {
let path = format!("/onchain/networks/{}/new_pools", network);
self.client.get(&path).await
}
pub async fn token(&self, network: &str, address: &str) -> Result<TokenResponse> {
let path = format!("/onchain/networks/{}/tokens/{}", network, address);
self.client.get(&path).await
}
pub async fn token_price(
&self,
network: &str,
addresses: &[&str],
) -> Result<TokenPriceResponse> {
let path = format!(
"/onchain/simple/networks/{}/token_price/{}",
network,
addresses.join(",")
);
self.client.get(&path).await
}
pub async fn token_pools(&self, network: &str, token_address: &str) -> Result<PoolsResponse> {
let path = format!(
"/onchain/networks/{}/tokens/{}/pools",
network, token_address
);
self.client.get(&path).await
}
pub async fn pool_ohlcv(
&self,
network: &str,
pool_address: &str,
timeframe: &str,
) -> Result<OhlcvResponse> {
let path = format!(
"/onchain/networks/{}/pools/{}/ohlcv/{}",
network, pool_address, timeframe
);
self.client.get(&path).await
}
pub async fn pool_trades(&self, network: &str, pool_address: &str) -> Result<TradesResponse> {
let path = format!(
"/onchain/networks/{}/pools/{}/trades",
network, pool_address
);
self.client.get(&path).await
}
pub async fn search_pools(&self, query: &str) -> Result<PoolsResponse> {
let path = format!("/onchain/search/pools?query={}", query);
self.client.get(&path).await
}
pub async fn new_pools_all(&self) -> Result<PoolsResponse> {
self.client.get("/onchain/networks/new_pools").await
}
pub async fn top_pools_all(&self) -> Result<PoolsResponse> {
self.client.get("/onchain/networks/pools").await
}
pub async fn pools_multi(&self, network: &str, addresses: &[&str]) -> Result<PoolsResponse> {
let path = format!(
"/onchain/networks/{}/pools/multi/{}",
network,
addresses.join(",")
);
self.client.get(&path).await
}
pub async fn tokens_multi(&self, network: &str, addresses: &[&str]) -> Result<TokensResponse> {
let path = format!(
"/onchain/networks/{}/tokens/multi/{}",
network,
addresses.join(",")
);
self.client.get(&path).await
}
pub async fn token_info(&self, network: &str, address: &str) -> Result<TokenInfoResponse> {
let path = format!("/onchain/networks/{}/tokens/{}/info", network, address);
self.client.get(&path).await
}
pub async fn dex_pools(&self, network: &str, dex: &str) -> Result<PoolsResponse> {
let path = format!("/onchain/networks/{}/dexes/{}/pools", network, dex);
self.client.get(&path).await
}
pub async fn recently_updated_tokens(&self) -> Result<TokensResponse> {
self.client
.get("/onchain/tokens/info_recently_updated")
.await
}
pub async fn pool_info(&self, network: &str, pool_address: &str) -> Result<PoolInfoResponse> {
let path = format!("/onchain/networks/{}/pools/{}/info", network, pool_address);
self.client.get(&path).await
}
pub async fn token_holders(
&self,
network: &str,
token_address: &str,
) -> Result<TokenHoldersResponse> {
let path = format!(
"/onchain/networks/{}/tokens/{}/top_holders",
network, token_address
);
self.client.get(&path).await
}
pub async fn token_traders(
&self,
network: &str,
token_address: &str,
) -> Result<TokenTradersResponse> {
let path = format!(
"/onchain/networks/{}/tokens/{}/top_traders",
network, token_address
);
self.client.get(&path).await
}
pub async fn token_holders_chart(
&self,
network: &str,
token_address: &str,
) -> Result<HoldersChartResponse> {
let path = format!(
"/onchain/networks/{}/tokens/{}/holders_chart",
network, token_address
);
self.client.get(&path).await
}
pub async fn token_ohlcv(
&self,
network: &str,
token_address: &str,
timeframe: &str,
) -> Result<TokenOhlcvResponse> {
let path = format!(
"/onchain/networks/{}/tokens/{}/ohlcv/{}",
network, token_address, timeframe
);
self.client.get(&path).await
}
pub async fn token_trades(
&self,
network: &str,
token_address: &str,
) -> Result<TokenTradesResponse> {
let path = format!(
"/onchain/networks/{}/tokens/{}/trades",
network, token_address
);
self.client.get(&path).await
}
pub async fn megafilter(&self, options: &MegafilterOptions) -> Result<PoolsResponse> {
let path = format!("/onchain/pools/megafilter{}", options.to_query_string());
self.client.get(&path).await
}
pub async fn trending_search_pools(&self) -> Result<PoolsResponse> {
self.client.get("/onchain/pools/trending_search").await
}
pub async fn categories(&self) -> Result<OnchainCategoriesResponse> {
self.client.get("/onchain/categories").await
}
pub async fn category_pools(&self, category_id: &str) -> Result<PoolsResponse> {
let path = format!("/onchain/categories/{}/pools", category_id);
self.client.get(&path).await
}
}