# Currency-Prices **currency-prices** is a lightweight Rust library designed to fetch cryptocurrency prices from CoinMarketCap. The primary function of this library is to provide a convenient way to obtain real-time currency conversion rates between specified cryptocurrencies. ## Usage ### Installation Add the following line to your `Cargo.toml` file: ```toml [dependencies] currency-prices = "0.1.2" ``` ### Getting Started To use this library, you'll need to configure it with your CoinMarketCap API key and endpoint. We offer two configurations: one for development and testing, and another for production. Development Configuration To obtain the development configuration with default settings (using a sandbox API key for testing), call: ```Rust use currency_prices::CoinMarketCapConfig; let dev_config = CoinMarketCapConfig::get_sandbox_config(); let currency_prices_api = CurrencyPrices::new(config); ``` Production Configuration For production, you need to provide your production API key when obtaining the configuration: ```Rust use currency_prices::CoinMarketCapConfig; let api_key = "your_production_api_key"; let prod_config = CoinMarketCapConfig::get_production_config(api_key); let currency_prices_api = CurrencyPrices::new(config); ``` Fetching Prices The library exposes a Struct wich contains the function for fetching cryptocurrency prices. You need to pass the from_currency, to_currency. ```Rust use currency_prices::{ models::{CoinMarketCapConfig, Currency}, CurrencyPrices, }; let from_currency = Currency { name: String::from("HDN"), }; let to_currency = Currency { name: String::from("USD"), }; let price = currency_prices_api.get_price(from_currency, to_currency).await?; ``` the get_price is an async funcion which returns ```Rust Result // Where pub struct CurrencyPrice { pub from_currency: Currency, pub to_currency: Currency, pub price: Decimal, } pub enum CurrencyPricesError { Request(reqwest::Error), Custom(String), } ```