Skip to content

dovahcrow/kraken-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kraken API Client for Rust Language

This library is still in its very early stage. As for now, I only implemented all the APIs that is used by my trading bot.

Implementation status:

Currently this library only implemented a part of the API for Kraken Futures (rest and websocket). But the plan is to also implement spot market API in this library.

Usage

Restful

All the requests/responses are typed into structs/enums. Pass the request object to KrakenRest::request for calling the API.

Calling a public API:

// futures/examples/tickers.rs

use dotenv::dotenv;
use env_logger::init;
use failure::Error;
use kraken_futures::rest::{KrakenRest, TickersRequest};

#[tokio::main]
async fn main() -> Result<(), Error> {
    dotenv()?;
    init();

    let client = KrakenRest::new(None); // None means using the default server url. You can fill in Kraken's internal URL here if you whitelisted your IP.

    let resp = client.request(TickersRequest).await?;

    println!("{:?}", resp);

    Ok(())
}

Calling a private API:

// futures/examples/account.rs

use dotenv::dotenv;
use env_logger::init;
use failure::Error;
use kraken_futures::rest::{AccountsRequest, KrakenRest};
use structopt::StructOpt;

#[derive(Debug, StructOpt, Clone)]
#[structopt(name = "kraken-rs", about = "kraken-rs.")]
struct Opt {
    #[structopt(env)]
    kraken_api_key: String,
    #[structopt(env)]
    kraken_api_secret: String,
}

#[tokio::main]
async fn main() -> Result<(), Error> {
    dotenv()?;
    init();

    let opt = Opt::from_args();

    // None means using the default server url. You can fill in Kraken's internal URL here if you whitelisted your IP.
    let client = KrakenRest::with_credential(None, &opt.kraken_api_key, &opt.kraken_api_secret); 
    let resp = client.request(AccountsRequest).await?;
    println!("{:?}", resp);
    Ok(())
}

Websocket

Websocket examples are quite long. Please take a look at the files in examples folder for reference.

More examples

More examples are located in the examples folder and the tests folder.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages