bitculator 1.1.0

Official Rust SDK for the Bitculator Data API
Documentation
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;

/// Markets, tickers, and trading pairs.
pub struct Markets {
    http: Arc<HttpClient>,
}

impl Markets {
    pub(crate) fn new(http: Arc<HttpClient>) -> Self {
        Self { http }
    }

    /// Markets (tickers) for a coin (paginated). Params: page, per_page,
    /// exchange, pair, instrument, search, min_volume, max_volume, min_change,
    /// max_change, sort.
    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)
    }

    /// Trading symbols for a coin.
    pub fn coin_symbols<T: DeserializeOwned>(&self, slug: &str) -> Result<T, Error> {
        self.http.get(&format!("/api/v1/coins/{}/symbols", enc(slug)), &Params::new())
    }

    /// List tickers across the market (paginated).
    pub fn tickers<T: DeserializeOwned>(&self, params: Params) -> Result<Page<T>, Error> {
        Page::fetch(self.http.clone(), "/api/v1/tickers", params)
    }

    /// List trading pairs (paginated). Params: page, per_page, search, coin,
    /// min_volume, max_volume, sort.
    pub fn pairs<T: DeserializeOwned>(&self, params: Params) -> Result<Page<T>, Error> {
        Page::fetch(self.http.clone(), "/api/v1/pairs", params)
    }

    /// Get a single trading pair by id.
    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())
    }
}

/// Exchanges: listings, trust score, history, markets, and listed assets.
pub struct Exchanges {
    http: Arc<HttpClient>,
}

impl Exchanges {
    pub(crate) fn new(http: Arc<HttpClient>) -> Self {
        Self { http }
    }

    /// List exchanges (paginated). Params: page, per_page, type, search,
    /// min_pairs, max_pairs, min_assets, max_assets, min_volume, max_volume,
    /// ids, slugs, sort.
    pub fn list<T: DeserializeOwned>(&self, params: Params) -> Result<Page<T>, Error> {
        Page::fetch(self.http.clone(), "/api/v1/exchanges", params)
    }

    /// Get a single exchange by slug.
    pub fn get<T: DeserializeOwned>(&self, slug: &str) -> Result<T, Error> {
        self.http.get(&format!("/api/v1/exchanges/{}", enc(slug)), &Params::new())
    }

    /// Get an exchange's trust score.
    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())
    }

    /// Volume/history for an exchange. Params: interval, start, end, limit.
    pub fn history<T: DeserializeOwned>(&self, slug: &str, params: Params) -> Result<T, Error> {
        self.http.get(&format!("/api/v1/exchanges/{}/history", enc(slug)), &params)
    }

    /// Sparkline for an exchange. Params: period.
    pub fn sparkline<T: DeserializeOwned>(&self, slug: &str, params: Params) -> Result<T, Error> {
        self.http.get(&format!("/api/v1/exchanges/{}/sparkline", enc(slug)), &params)
    }

    /// Markets (tickers) on an exchange (paginated).
    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)
    }

    /// Coins listed on an exchange (paginated).
    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)
    }
}

/// Wallets: listings, release timeline, comparison, and supported coins.
pub struct Wallets {
    http: Arc<HttpClient>,
}

impl Wallets {
    pub(crate) fn new(http: Arc<HttpClient>) -> Self {
        Self { http }
    }

    /// List wallets (paginated). Params: page, per_page, search, min_score,
    /// max_score, tags, ids, slugs, sort.
    pub fn list<T: DeserializeOwned>(&self, params: Params) -> Result<Page<T>, Error> {
        Page::fetch(self.http.clone(), "/api/v1/wallets", params)
    }

    /// Wallet release timeline (paginated).
    pub fn timeline<T: DeserializeOwned>(&self, params: Params) -> Result<Page<T>, Error> {
        Page::fetch(self.http.clone(), "/api/v1/wallets/timeline", params)
    }

    /// Compare a set of wallets side by side. Params: slugs.
    pub fn compare<T: DeserializeOwned>(&self, params: Params) -> Result<T, Error> {
        self.http.get("/api/v1/wallets/compare", &params)
    }

    /// Get a single wallet by slug.
    pub fn get<T: DeserializeOwned>(&self, slug: &str) -> Result<T, Error> {
        self.http.get(&format!("/api/v1/wallets/{}", enc(slug)), &Params::new())
    }

    /// Coins supported by a wallet (paginated).
    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)
    }
}