Crates.io | ccdata-api |
lib.rs | ccdata-api |
version | 0.1.2 |
source | src |
created_at | 2024-10-15 15:46:24.218719 |
updated_at | 2024-11-13 11:54:01.487814 |
description | Wrapper for CCData REST API endpoints. |
homepage | https://github.com/rsadykhov/ccdata-api |
repository | https://github.com/rsadykhov/ccdata-api |
max_upload_size | |
id | 1409648 |
size | 324,820 |
ccdata-api
is a wrapper for CCData REST API endpoints. This crate supports non-exhausitve list of CCData endpoints,
you can check what endpoints are supported by checking the variants of the enum CCAPIEndpoint
- it contains all
supported endpoint URLs.
For documentation on CCData REST API endpoints visit CCData online documentation:
Disclaimer: This crate is an unofficial CCData REST API wrapper, the maintainers of the crate are independent developers. The developers of the crate do not accept any responsibility or liability for the accuracy, security, or completeness of the code, or the information provided within the crate.
The REST API functions in the crate will error if the data received does not fit into the pre-defined schemas provided in the crate. In the case of missing fields, unexpected null values or unexpected data types, the error message will state:
data did not match any variant of untagged enum EmptyObject
If you encounter this error, please open the issue on GitHub with the parameters that you have used (e.g., asset symbol, timestamp, limit, etc.). Do not provide your API key or any personal data!
To start making the REST API requests, define a data collection backend. This can be done by either directly passing an
API key to the data collection backend, or by defining a .env
file with an API key as an environment variable (Preferred
method).
use ccdata_api::CCData;
let mut backend: CCData = CCData::new();
let api_key: String = String::from("xxxxxxx");
backend.update_api_key(api_key);
assert_eq!(backend.api_key().unwrap(), &String::from("xxxxxxx"));
use ccdata_api::CCData;
let mut backend: CCData = CCData::new();
// Provide API key as the environment variable called API_KEY
backend.build(&"API_KEY").unwrap();
println!("{}", backend.api_key().unwrap());
After the backend has been build, you can make API requests using the methods provided in the backend. For example, to
get a daily spot OHLCV data for Bitcoin you can do the following (note that the calls use Rust's async
functionality):
use ccdata_api::{CCData, CCUnit, DataUnwrap};
use ccdata_api::CCSpotMarket;
#[tokio::main]
async fn main() -> () {
let mut backend: CCData = CCData::new();
// Provide API key as the environment variable called API_KEY
backend.build(&"API_KEY").unwrap();
// Define the API parameters
let market: CCSpotMarket = CCSpotMarket::KRAKEN;
let limit: usize = 2000;
let to_timestamp: Option<i64> - Some(1728860400);
// Make the API call
let ohlcv = backend.get_spot_ohlcv(&String::from("BTC-USD"), to_timestamp, Some(limit), market, CCUnit::Day).await.unwrap();
assert_eq!(ohlcv.data_unwrap().unwrap().len(), limit);
}
If you would like to add a commit or an issue, please do so using the GitHub link to the project: