5 releases

0.1.6 Jun 10, 2021
0.1.5 Jun 9, 2021

#3 in #coin-gecko

22 downloads per month

MIT/Apache

56KB
1.5K SLoC

gecko

A simple library to access coingecko's api.

Dependecy

[dependecies]
tokio = { version = "1", features = ["full"] }
gecko = { version = "0.1.6" } 

Example

use gecko;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
   let gecko_client = gecko::CoinGeckoAPI::default();
   let coins_list = gecko::coins::List::required();
   let response = gecko_client(&coins_list).await.unwrap();
   println!("{:?}", response):
}

Note

The testing only covers that the api endpoints are reachable (200 code). Responses are translated into a serde json values and the correctness of expected values are not tested.

ps

this is my first rust project so be nice :)


lib.rs:

gecko

The gecko crate provides convenient access coingeckos api. The focus of this crate is on access/retreival of data from coingecko api endpoints and not on convenience or manipulating reponses/data. Although, if raw text reponses are not desired, the crate has funcitonality to provide coingeckos api response in json objects.

Note: Coingeckos api has a limit of 100 requests per minute.

Examples

Default

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
   let gecko_client = gecko::CoinGeckoAPI::default();
   let coins_list = gecko::coins::List::required();
   let response = gecko_client.get_json(&coins_list).await.unwrap();
   println!("{:?}", response);
   Ok(())
}

Custom

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
   let gecko_client = gecko::CoinGeckoAPI::default();
   let mut coins_list = gecko::coins::Info::required("premia".to_string());
   coins_list.tickers = false;
   let response = gecko_client.get_json(&coins_list).await.unwrap();
   println!("{:?}", response["id"]);
   Ok(())
}

Or if you do not want the request object to be a mutable variable...

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
   let gecko_client = gecko::CoinGeckoAPI::default();
   let coins_list = {
      let mut _tmp = gecko::coins::Info::required("premia".to_string());
      _tmp.tickers = false;
      _tmp
   };
   let response = gecko_client.get_json(&coins_list).await.unwrap();
   println!("{:?}", response["id"]);
   Ok(())
}

For more information about CoinGecko API can be found here The Route trait can be implented to give a struct the ability to be used by [CoinGeckoAPI]

Dependencies

~7–19MB
~257K SLoC