1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
//! This is a minimal interface for the [Kraken exchange REST API](https://docs.kraken.com/rest/) using the [async-std](https://async.rs/) runtime. //! //! # Prerequisites //! To use the **```private```** endpoints you will need to generate an **```API-Key```** and an **```API-Secret```** to authenticate to the desired Kraken account. //! [How to generate an API key pair?](https://support.kraken.com/hc/en-us/articles/360000919966-How-to-generate-an-API-key-pair-) //! //! # Usage //! Automatically add to your **```Cargo.toml```** with //! ```shell //! cargo add async_kraken //! ``` //! or manually adding as dependecy in **```Cargo.toml```**: //! ```toml //! [dependencies] //! #.. //! async_kraken = "~0.1.2" //! ``` //! //! # Example //! ```rust //! use async_kraken::client::KrakenClient; //! //! fn get_keys() -> (String, String) { //! let content = std::fs::read_to_string("key").expect("File not found"); //! let lines: Vec<&str> = content.lines().collect(); //! //! let key = String::from(lines[0]); //! let secret = String::from(lines[1]); //! //! (key, secret) //! } //! //! #[async_std::main] //! async fn main() { //! // # Only public endpoints //! // let k = KrakenClient::new(); //! //! // # Public and private enpoints //! let (key, secret) = get_keys(); //! let k = KrakenClient::with_credentials(key, secret); //! //! match k.api_request("Time", serde_json::json!({})).await { //! Ok(json) => println!("{:?}", json), //! Err(e) => println!("{:?}", e), //! }; //! //! match k.api_request("OHLC", serde_json::json!({"pair":"doteur", "interval":30, "since":0})).await //! { //! Ok(json) => println!("{:?}", json), //! Err(e) => println!("{:?}", e), //! }; //! //! match k.api_request("Balance", serde_json::json!({})).await { //! Ok(json) => println!("{:?}", json), //! Err(e) => println!("{:?}", e), //! }; //! } //! ``` //! # Disclaimer //! //! This software comes without any kind of warranties. //! //! You are the sole responsible of your gains or loses. use serde::Deserialize; use serde_json::Value; use std::{error::Error, fmt}; pub mod client; mod config; #[derive(Deserialize)] struct KrakenResult { pub error: Vec<String>, #[serde(default)] pub result: Value, } struct KrakenError { pub er_list: Vec<String>, } impl Error for KrakenError {} impl fmt::Display for KrakenError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{:?}", self.er_list) } } impl fmt::Debug for KrakenError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Kraken Errors: {:?}", self.er_list) } }