#exchange #trading #kraken #async #api-bindings #api

bin+lib async_kraken

Minimal wrapper for the Kraken exchange REST API using async-std

3 releases

0.1.3 May 28, 2021
0.1.2 May 27, 2021
0.1.1 May 27, 2021
0.1.0 May 27, 2021

#23 in #kraken


Used in async_kraken_ws

Apache-2.0

20KB
178 lines

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.

Dependencies

~16–28MB
~513K SLoC