Cmc

Struct Cmc 

Source
pub struct Cmc { /* private fields */ }
Expand description

A Cmc can be used to create a CoinMarketCap client with default configuration.

Implementations§

Source§

impl Cmc

Source

pub fn new<T: Into<String>>(api_key: T) -> Self

Constructs a new CoinMarketCap Client.

Source

pub fn id_map( &self, start: usize, limit: usize, sort: Sort, ) -> CmcResult<CmcIdMap>

Returns a mapping of all cryptocurrencies to unique CoinMarketCap ids.

§Example:

Parameters:

  • start Offset the start.
  • limit Specify the number of results to return.
  • sort What field to sort the list of cryptocurrencies by.
use cmc::{Cmc, Sort};

let cmc = Cmc::new("<API KEY>");

match cmc.id_map(1, 50, Sort::CmcRank) {
    Ok(map) => println!("{}", map),
    Err(err) => println!("{}", err),
}
Source

pub fn fiat_id_map( &self, start: usize, limit: usize, sort: SortFiat, ) -> CmcResult<CmcFiatIdMap>

Returns a mapping of all supported fiat currencies to unique CoinMarketCap ids.

§Example:

Parameters:

  • start Offset the start.
  • limit Specify the number of results to return.
  • sort What field to sort the list of currencies by.

Basic usage:

use cmc::{Cmc, SortFiat};

let cmc = Cmc::new("<API KEY>");

match cmc.fiat_id_map(1, 100, SortFiat::Name) {
    Ok(map) => println!("{}", map),
    Err(err) => println!("{}", err),
}
Source

pub fn price<T: Into<String>>(&self, query: T) -> CmcResult<f64>

Latest price for cryptocurrency in USD.

§Example:
use cmc::Cmc;

let cmc = Cmc::new("<API KEY>");

match cmc.price("BTC") {
    Ok(price) => println!("Price: {}", price),
    Err(err) => println!("Error: {}", err),
}
Source

pub fn quotes_latest_by_id<T: Into<String>>(&self, ids: T) -> CmcResult<QLv2Id>

Returns the latest market quote for 1 or more cryptocurrencies (using id’s).

Source

pub fn quotes_latest_by_slug<T: Into<String>>( &self, slugs: T, ) -> CmcResult<QLv2Slug>

Returns the latest market quote for 1 or more cryptocurrencies (using slug’s).

Source

pub fn quotes_latest_by_symbol<T: Into<String>>( &self, symbols: T, ) -> CmcResult<QLv2Symbol>

Returns the latest market quote for 1 or more cryptocurrencies (using symbol’s).

Source

pub fn key_info(&self) -> CmcResult<KeyInfo>

Returns API key details and usage stats.

Source

pub fn price_conversion( &self, amount: f64, symbol: &str, time: Option<&str>, convert: &str, ) -> CmcResult<f64>

Convert an amount of one cryptocurrency or fiat currency into one or more different currencies utilizing the latest market rate for each currency.

§Example:

Parameters:

  • amount An amount of currency to convert.
  • symbol Alternatively the currency symbol of the base cryptocurrency or fiat to convert from.
  • time Optional timestamp (Unix or ISO 8601) to reference historical pricing during conversion. If not passed, the current time will be used.
  • convert Pass fiat or cryptocurrency symbols to convert the source amount to.

Basic usage:

use cmc::Cmc;

let cmc = Cmc::new("<API KEY>");

// 2.5 BTC in EUR
match cmc.price_conversion(2.5, "BTC", None, "EUR") {
    Ok(price) => println!("Total price: {}", price),
    Err(err) => println!("Error: {}", err),
}
Source

pub fn price_conversion_id( &self, amount: f64, id: &str, time: Option<&str>, convert_id: &str, ) -> CmcResult<f64>

Convert an amount of one cryptocurrency or fiat currency into one or more different currencies utilizing the latest market rate for each currency.

§Example:

Parameters:

  • amount An amount of currency to convert.
  • id The CoinMarketCap currency ID of the base cryptocurrency or fiat to convert from.
  • time Optional timestamp (Unix or ISO 8601) to reference historical pricing during conversion. If not passed, the current time will be used.
  • convert_id Optionally calculate market quotes by CoinMarketCap ID instead of symbol. This option is identical to convert outside of ID format.

Basic usage:

use cmc::Cmc;

let cmc = Cmc::new("<API KEY>");

// 1.6 ETH in Monero (XMR).
match cmc.price_conversion_id(1.6, "1027", None, "328") {
    Ok(price) => println!("Total price: {}", price),
    Err(err) => println!("Error: {}", err),
}
Source

pub fn categories<T: Into<String>>( &self, start: usize, limit: usize, pass: T, ) -> CmcResult<CmcCategories>

Returns information about all coin categories available on CoinMarketCap.

§Example:

Parameters:

  • start Optionally offset the start (1-based index) of the paginated list of items to return.
  • limit Optionally specify the number of results to return. Use this parameter and the “start” parameter to determine your own pagination size.
  • pass Cryptocurrency pass (id, slug, symbol)

Basic usage:

use cmc::{CmcBuilder, Pass};

let cmc = CmcBuilder::new("<API KEY>")
    .pass(Pass::Id)
    .build();

match cmc.categories(1, 10, "1027") {
    Ok(categories) => println!("{categories}"),
    Err(err) => println!("{err}"),
}
Source

pub fn category( &self, id: &str, start: usize, limit: usize, ) -> CmcResult<Category>

Returns information about a single coin category available on CoinMarketCap.

§Example:

Parameters:

  • id The Category ID. This can be found using the categories().
  • start Optionally offset the start (1-based index) of the paginated list of coins to return.
  • limit Optionally specify the number of coins to return. Use this parameter and the “start” parameter to determine your own pagination size.

Basic usage:

use cmc::CmcBuilder;

let cmc = CmcBuilder::new("<API KEY>")
    .convert("EUR")
    .build();

match cmc.category("605e2ce9d41eae1066535f7c", 1, 10) {
    Ok(category) => println!("{category}"),
    Err(err) => println!("{err}"),
}
Source

pub fn metadata<T: Into<String>>(&self, query: T) -> CmcResult<Metadata>

Returns all static metadata available for one cryptocurrency. This information includes details like logo, description, official website URL, social links, and links to a cryptocurrency’s technical documentation.

Parameters:

  • Id: Cryptocurrency coinmarketcap id. Example: “1027”

  • Slug: Alternatively pass one cryptocurrency slug. Example: “ethereum”

  • Symbol: Alternatively pass one cryptocurrency symbol. Example: “BTC”

  • Address: Alternatively pass in a contract address. Example: “0xc40af1e4fecfa05ce6bab79dcd8b373d2e436c4e”

NOTE: CoinMarketCap recommend utilizing CMC ID instead of cryptocurrency symbols to securely identify cryptocurrencies with other endpoints and in your own application logic (Can be obtained using the method id_map()).

use cmc::{CmcBuilder, Pass};

let cmc = CmcBuilder::new("<API KEY>")
    .pass(Pass::Id)
    .build();
// Cryptocurrency metadata.
match cmc.metadata("1027") {
    Ok(metadata) => println!("{}", metadata.description),
    Err(err) => println!("{}", err),
}

let cmc = CmcBuilder::new("<API KEY>")
    .pass(Pass::Address)
    .build();
// Contract address metadata.
match cmc.metadata("0xc40af1e4fecfa05ce6bab79dcd8b373d2e436c4e") {
    Ok(metadata) => println!("{}", metadata.description),
    Err(err) => println!("{}", err),
}
Source

pub fn metadata_map<T: Into<String>>( &self, query: T, ) -> CmcResult<HashMap<String, Metadata>>

Returns HashMap with all static metadata available for one or more cryptocurrencies. This information includes details like logo, description, official website URL, social links, and links to a cryptocurrency’s technical documentation.

§Examples:

Parameters:

  • query: One or more comma-separated CoinMarketCap cryptocurrency exchange ids. Example: “1,328,1027”
use cmc::Cmc;

let cmc = Cmc::new("<API KEY>");

let query = "1,328,1027";
let map = cmc.metadata_map(query)?;

for m in map.values() {
    println!("{}", m.name);
}
Source

pub fn global_metrics(&self) -> CmcResult<GlobalMetrics>

Returns the latest global cryptocurrency market metrics. Use the convert() to return market values in multiple fiat and cryptocurrency conversions in the same call.

use cmc::CmcBuilder;

let cmc = CmcBuilder::new("<API KEY>")
    .convert("EUR")
    .build();

match cmc.global_metrics() {
    Ok(gm) => println!("{}", gm.btc_dominance),
    Err(err) => println!("{}", err),
}
Source

pub fn exchange_metadata<T: Into<String>>( &self, exchange: T, ) -> CmcResult<ExchangeMetadata>

Returns all static metadata for one or more exchanges. This information includes details like launch date, logo, official website URL, social links, and market fee documentation URL.

§Examples:

Parameters:

  • Id: One or more comma-separated CoinMarketCap cryptocurrency exchange ids. Example: “270,271”

  • Slug: Alternatively, one or more comma-separated exchange names in URL friendly shorthand “slug” format (all lowercase, spaces replaced with hyphens). Example: “binance,gdax”.

use cmc::{CmcBuilder, Pass};

// using Id
let cmc = CmcBuilder::new("<API KEY>")
    .pass(Pass::Id)
    .build();

match cmc.exchange_metadata("270") {
    Ok(metadata) => println!("{}", metadata.data.get("270").unwrap().name),
    Err(err) => println!("{}", err),
}

// using Slug
let cmc = CmcBuilder::new("<API KEY>")
    .pass(Pass::Slug)
    .build();

match cmc.exchange_metadata("binance") {
    Ok(metadata) => println!("{}", metadata.data.get("binance").unwrap().name),
    Err(err) => println!("{}", err),
}
Source

pub fn exchange_id_map( &self, listing_status: ListingStatusExchange, start: usize, limit: usize, sort: SortExchange, crypto_id: Option<&str>, ) -> CmcResult<CmcExchangeIdMap>

Returns a paginated list of all active cryptocurrency exchanges by CoinMarketCap ID.

§Examples:

Parameters:

  • listing_status:

Active: Only active exchanges are returned.

Inactive: List of exchanges that are no longer active.

Untracked: List of exchanges that are registered but do not currently meet methodology requirements to have active markets tracked.

  • start: Optionally offset the start (1-based index) of the paginated list of items to return.

  • limit: Optionally specify the number of results to return. Use this parameter and the “start” parameter to determine your own pagination size.

  • sort: What field to sort the list of exchanges by.

  • crypto_id: Optionally include one fiat or cryptocurrency IDs to filter market pairs by.

use cmc::{Cmc, ListingStatusExchange, SortExchange};

let cmc = Cmc::new("<API KEY>");

match cmc.exchange_id_map(ListingStatusExchange::Active, 1, 10, SortExchange::Id, None) {
    Ok(map) => println!("{}", map),
    Err(err) => println!("{}", err),
}

Trait Implementations§

Source§

impl Clone for Cmc

Source§

fn clone(&self) -> Cmc

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Cmc

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Cmc

§

impl !RefUnwindSafe for Cmc

§

impl Send for Cmc

§

impl Sync for Cmc

§

impl Unpin for Cmc

§

impl !UnwindSafe for Cmc

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more