use std::fmt::Display;
use std::sync::Arc;
use serde::de::DeserializeOwned;
use crate::error::Error;
use crate::http::{enc, HttpClient};
use crate::pagination::Page;
use crate::params::Params;
pub struct Markets {
http: Arc<HttpClient>,
}
impl Markets {
pub(crate) fn new(http: Arc<HttpClient>) -> Self {
Self { http }
}
pub fn coin_markets<T: DeserializeOwned>(&self, slug: &str, params: Params) -> Result<Page<T>, Error> {
Page::fetch(self.http.clone(), &format!("/api/v1/coins/{}/markets", enc(slug)), params)
}
pub fn coin_symbols<T: DeserializeOwned>(&self, slug: &str) -> Result<T, Error> {
self.http.get(&format!("/api/v1/coins/{}/symbols", enc(slug)), &Params::new())
}
pub fn tickers<T: DeserializeOwned>(&self, params: Params) -> Result<Page<T>, Error> {
Page::fetch(self.http.clone(), "/api/v1/tickers", params)
}
pub fn pairs<T: DeserializeOwned>(&self, params: Params) -> Result<Page<T>, Error> {
Page::fetch(self.http.clone(), "/api/v1/pairs", params)
}
pub fn pair<T: DeserializeOwned>(&self, id: impl Display) -> Result<T, Error> {
self.http.get(&format!("/api/v1/pairs/{}", enc(&id.to_string())), &Params::new())
}
}
pub struct Exchanges {
http: Arc<HttpClient>,
}
impl Exchanges {
pub(crate) fn new(http: Arc<HttpClient>) -> Self {
Self { http }
}
pub fn list<T: DeserializeOwned>(&self, params: Params) -> Result<Page<T>, Error> {
Page::fetch(self.http.clone(), "/api/v1/exchanges", params)
}
pub fn get<T: DeserializeOwned>(&self, slug: &str) -> Result<T, Error> {
self.http.get(&format!("/api/v1/exchanges/{}", enc(slug)), &Params::new())
}
pub fn trust_score<T: DeserializeOwned>(&self, slug: &str) -> Result<T, Error> {
self.http.get(&format!("/api/v1/exchanges/{}/trust-score", enc(slug)), &Params::new())
}
pub fn history<T: DeserializeOwned>(&self, slug: &str, params: Params) -> Result<T, Error> {
self.http.get(&format!("/api/v1/exchanges/{}/history", enc(slug)), ¶ms)
}
pub fn sparkline<T: DeserializeOwned>(&self, slug: &str, params: Params) -> Result<T, Error> {
self.http.get(&format!("/api/v1/exchanges/{}/sparkline", enc(slug)), ¶ms)
}
pub fn tickers<T: DeserializeOwned>(&self, slug: &str, params: Params) -> Result<Page<T>, Error> {
Page::fetch(self.http.clone(), &format!("/api/v1/exchanges/{}/tickers", enc(slug)), params)
}
pub fn assets<T: DeserializeOwned>(&self, slug: &str, params: Params) -> Result<Page<T>, Error> {
Page::fetch(self.http.clone(), &format!("/api/v1/exchanges/{}/assets", enc(slug)), params)
}
}
pub struct Wallets {
http: Arc<HttpClient>,
}
impl Wallets {
pub(crate) fn new(http: Arc<HttpClient>) -> Self {
Self { http }
}
pub fn list<T: DeserializeOwned>(&self, params: Params) -> Result<Page<T>, Error> {
Page::fetch(self.http.clone(), "/api/v1/wallets", params)
}
pub fn timeline<T: DeserializeOwned>(&self, params: Params) -> Result<Page<T>, Error> {
Page::fetch(self.http.clone(), "/api/v1/wallets/timeline", params)
}
pub fn compare<T: DeserializeOwned>(&self, params: Params) -> Result<T, Error> {
self.http.get("/api/v1/wallets/compare", ¶ms)
}
pub fn get<T: DeserializeOwned>(&self, slug: &str) -> Result<T, Error> {
self.http.get(&format!("/api/v1/wallets/{}", enc(slug)), &Params::new())
}
pub fn assets<T: DeserializeOwned>(&self, slug: &str, params: Params) -> Result<Page<T>, Error> {
Page::fetch(self.http.clone(), &format!("/api/v1/wallets/{}/assets", enc(slug)), params)
}
}