cmc 0.1.5

Rust Library for the CoinMarketCap API
Documentation

cmc

Crates.io docs.rs MIT licensed Apache-2.0 licensed

Unofficial Rust Library for the CoinMarketCap API

Usage

Get your API key here

Price cryptocurrency

use cmc::Cmc;

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

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

Price with custom settings

use cmc::{CmcBuilder, Pass};

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

match cmc.price("1027") { // 1027 is Ethereum id.
    Ok(price) => println!("{}", price), // In Euro instead default USD
    Err(err) => println!("Error: {}", err),
}

CoinMarketCap ID Map

NOTE: CoinMarketCap recommend utilizing CMC ID instead of cryptocurrency symbols to securely identify cryptocurrencies with other endpoints and in your own application logic.

use cmc::{Cmc, Sort};

let cmc = Cmc::new("<API KEY>");
let map = cmc.id_map(1, 5, Sort::Id).unwrap();

for cc in map {
    println!(
        "CMC Id: {}\nName: {}\nSymbol: {}\nSlug: {}\nRank: {}\n---------------",
        cc.id, cc.name, cc.symbol, cc.slug, cc.rank
    )
}

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.