Giter VIP home page Giter VIP logo

kraken-rs's Introduction

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.

kraken-rs's People

Contributors

dovahcrow avatar dancju avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.