async_kraken

Crates.ioasync_kraken
lib.rsasync_kraken
version0.1.3
sourcesrc
created_at2021-05-27 17:50:50.13884
updated_at2021-05-28 14:57:50.845259
descriptionMinimal wrapper for the Kraken exchange REST API using async-std
homepagehttps://gitlab.com/dpuyosa/async-kraken
repositoryhttps://gitlab.com/dpuyosa/async-kraken
max_upload_size
id402811
size61,644
(dpuyosa)

documentation

https://docs.rs/async_kraken

README

This is a minimal interface for the Kraken exchange REST API using the async-std runtime.

Being a minimal interface for the API there is just a single method which takes the endpoint name and the parameters as a Value object from serde_json.

When querying a private endpoint this library will handle and properly sing the petition to Kraken.

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?

Usage

Create the KrakenClient object with new() or with_credentials(key, secret) based on your needs.

Then call api_request(endpoint_name, payload). It will return a JSON for you to handle or an error message. You can read about the payload for each endpoint and the returned JSON in the API documentation.

Available Public Endpoint Names:
Time, SystemStatus, Assets, AssetPairs, Ticker, OHLC, Depth, Trades, Spread.

Available Private Endpoint Names:
User Data
Balance, TradeBalance, OpenOrders, ClosedOrders, QueryOrders, TradesHistory, QueryTrades, OpenPositions, Ledgers, QueryLedgers, TradeVolume, AddExport, ExportStatus, RetrieveExport, RemoveExport.

User Trading
AddOrder CancelOrder CancellAll CancelAllOrdersAfter.

User Funding
DepositMethods, DepositAddresses, DepositStatus, WithdrawInfo, Withdraw, WithdrawStatus, WithdrawCancel, WalletTransfer.

Websocket Auth
GetWebSocketsToken.

Example

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.

Commit count: 13

cargo fmt