Crates.io | rustgecko |
lib.rs | rustgecko |
version | 0.3.4 |
source | src |
created_at | 2022-12-21 09:38:43.699064 |
updated_at | 2023-09-16 19:23:06.877048 |
description | A Simple SDK for Coingecko API |
homepage | |
repository | https://github.com/ffindelsberger/rustgecko |
max_upload_size | |
id | 742976 |
size | 50,892 |
Pull Requests and Suggestions for Improvements are highly welcomed and appreciated
Simple API Client for CoinGecko written in Rust
Refer to CoinGecko official API
Endpoint | Status | Testing | Function |
---|---|---|---|
/ping | ✓ | ping | |
/simple/price | ✓ | simple_price_short, simple_price | |
/simple/supported_vs_currencies | ✓ | ✓ | SimpleSupportedVSCurrencies |
/coins/list | ✓ | ✓ | CoinsList |
/coins/market | ✓ | ✓ | CoinsMarket |
/coins/{id} | ✓ | ✓ | CoinsID |
/coins/{id}/history | ✓ | ✓ | CoinsIDHistory |
/coins/{id}/market_chart | ✓ | ✓ | CoinsIDMarketChart |
/events/countries | WIP | WIP | EventsCountries |
/events/types | WIP | WIP | EventsType |
/exchange_rates | ✓ | ✓ | ExchangeRate |
/global | ✓ | ✓ | Global |
More api Endpoints than listed here will be supported in the Future. As soon as I start working on additional Endpoints the Table will be updated.
By Default this Crate uses the rustls backend of reqwest, if you need native-tls/openSSL you need to activate the native-tls feature
rustgecko = { version = "*" , features = ["native-tls"] }
Some Methods with a lot of boolean Flags have a shorter Version i.E "simple_price_short" for if you just want to retrieve Some Data and leave the Rest of the Params as their Default.
use rustgecko::client::GeckoClient;
fn main() {
let client = GeckoClient::default();
}
In a Production Setting or when you have a Coingecko Subscription you might want to supply your own Client with Credentials or with any other additional configuration.
use rustgecko::client::GeckoClient;
fn main() {
use reqwest::header;
let mut headers = header::HeaderMap::new();
// Consider marking security-sensitive headers with `set_sensitive`.
let mut auth_value = header::HeaderValue::from_static("secret");
auth_value.set_sensitive(true);
headers.insert("x-cg-pro-api-key", auth_value);
// get a client builder
let client = reqwest::Client::builder()
.default_headers(headers)
.build()
.unwrap();
let _ = GeckoClient::new_with_custom_client(client, "https://some.url");
}
Every 4XX Response is turned into an error of type reqwest::Error and propagated up the call chain.
For handling reqwest errors reference the Docs -> https://docs.rs/reqwest/0.7.2/reqwest/struct.Error.html
async fn main() {
if let Err(err) = GeckoClient::default().exchangerates().await {
match err.status() {
Some(StatusCode::TOO_MANY_REQUESTS) => info!("we have to slow down"),
Some(_) => info!("Something else happened"),
None => info!("We got an error without a status code"),
}
}
}
MIT
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.