pub struct Cmc { /* private fields */ }Expand description
A Cmc can be used to create a CoinMarketCap client with default configuration.
Implementations§
Source§impl Cmc
impl Cmc
Sourcepub fn id_map(
&self,
start: usize,
limit: usize,
sort: Sort,
) -> CmcResult<CmcIdMap>
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:
startOffset the start.limitSpecify the number of results to return.sortWhat 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),
}Sourcepub fn fiat_id_map(
&self,
start: usize,
limit: usize,
sort: SortFiat,
) -> CmcResult<CmcFiatIdMap>
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:
startOffset the start.limitSpecify the number of results to return.sortWhat 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),
}Sourcepub fn price<T: Into<String>>(&self, query: T) -> CmcResult<f64>
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),
}Sourcepub fn quotes_latest_by_id<T: Into<String>>(&self, ids: T) -> CmcResult<QLv2Id>
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).
Sourcepub fn quotes_latest_by_slug<T: Into<String>>(
&self,
slugs: T,
) -> CmcResult<QLv2Slug>
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).
Sourcepub fn quotes_latest_by_symbol<T: Into<String>>(
&self,
symbols: T,
) -> CmcResult<QLv2Symbol>
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).
Sourcepub fn price_conversion(
&self,
amount: f64,
symbol: &str,
time: Option<&str>,
convert: &str,
) -> CmcResult<f64>
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:
amountAn amount of currency to convert.symbolAlternatively the currency symbol of the base cryptocurrency or fiat to convert from.timeOptional timestamp (Unix or ISO 8601) to reference historical pricing during conversion. If not passed, the current time will be used.convertPass 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),
}Sourcepub fn price_conversion_id(
&self,
amount: f64,
id: &str,
time: Option<&str>,
convert_id: &str,
) -> CmcResult<f64>
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:
amountAn amount of currency to convert.idThe CoinMarketCap currency ID of the base cryptocurrency or fiat to convert from.timeOptional timestamp (Unix or ISO 8601) to reference historical pricing during conversion. If not passed, the current time will be used.convert_idOptionally 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),
}Sourcepub fn categories<T: Into<String>>(
&self,
start: usize,
limit: usize,
pass: T,
) -> CmcResult<CmcCategories>
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:
startOptionally offset the start (1-based index) of the paginated list of items to return.limitOptionally specify the number of results to return. Use this parameter and the “start” parameter to determine your own pagination size.passCryptocurrency 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}"),
}Sourcepub fn category(
&self,
id: &str,
start: usize,
limit: usize,
) -> CmcResult<Category>
pub fn category( &self, id: &str, start: usize, limit: usize, ) -> CmcResult<Category>
Returns information about a single coin category available on CoinMarketCap.
§Example:
Parameters:
idThe Category ID. This can be found using the categories().startOptionally offset the start (1-based index) of the paginated list of coins to return.limitOptionally 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}"),
}Sourcepub fn metadata<T: Into<String>>(&self, query: T) -> CmcResult<Metadata>
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),
}Sourcepub fn metadata_map<T: Into<String>>(
&self,
query: T,
) -> CmcResult<HashMap<String, Metadata>>
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);
}Sourcepub fn global_metrics(&self) -> CmcResult<GlobalMetrics>
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),
}Sourcepub fn exchange_metadata<T: Into<String>>(
&self,
exchange: T,
) -> CmcResult<ExchangeMetadata>
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),
}Sourcepub fn exchange_id_map(
&self,
listing_status: ListingStatusExchange,
start: usize,
limit: usize,
sort: SortExchange,
crypto_id: Option<&str>,
) -> CmcResult<CmcExchangeIdMap>
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),
}