Expand description

An interface to the Kraken cryptocurrency exchange via its RESTful JSON-based API.

It allows general exchange-wide data requests, and fully authenticated trading account-based requests. The Kraken API is fully documented at https://docs.kraken.com/rest.

Use this crate if you want to build custom automatons for algorithmic trading through this exchange, or if you want to provide an alternative interface to the one which the Kraken web site gives you.

To use, call the connect method to obtain a handle object, maybe call Kraken_API::set_opt on the handle if you want to make a call to a Kraken end-point which accepts optional filter arguments, and then call the method on the handle which corresponds to the end-point you wish to invoke. As this is a low-level library, the return will be a JSON string as sent by the exchange itself; you will need to be familiar with the Kraken API itself to interpret the returned data (and the intended use of the various end-points).

Thus, an example program might appear as

use  serde_json  as  JSN;

fn  main  ()  ->  Result<(), String>   {

       let  mut  K  =  KKN::connect ("account key".to_string (),
                                     "secret".to_string ());

       K.set_opt (KKN::API_Option::START_TIME, "2022-01-01");

       let  json_result  =  K.account_balance () ?;

       let  json_result  =  JSN::from_str::<JSN::Value> (&json_result)
                               .map_err (|E| E.to_string ()) ?;

       //  There should be code here to deal with the possibility that
       //  the exchange returned an error message to us.

       println! ("We currently have ${} in our account.",
                 json_result ["result"] ["ZUSD"].as_str ().ok_or ("0"));

       Ok (())

The ‘account key’ and the ‘secret’ should be obtained through the Kraken web service, and care must be taken to keep the secret secret (don’t let it find its way into a public code repository!)

Note that we made use of the serde_json crate to parse the response from the Kraken exchange, but this is absolutely not mandated by this library.

Limitations / To do

  • The user needs to be familiar with the Kraken documentation to be able to use this crate effectively. While the crate does help with the formatting of calls and authentication and authorization information, it gives little help with interpreting the responses received from the exchange; as well as working knowledge of the Kraken protocols, an external JSON crate is almost certainly required to handle this.

  • We have currently implemented all of the Market Data, User Data and User Trading end-points. The User Funding and User Staking end-points are not yet implemented, nor is the Websockets Authentication end-point.

  • Some specific strings which the exchange needs to see are not provided by the crate, and in particular the peculiarities of trading pairs like “ZUSDXBTC” have to be dealt with entirely by the user. The exchange provides little consistency among these and coding for them is difficult and use-case specific.


A handle on the connection to the Kraken exchange.


Enumeration of available optional arguments which may be given to some of Kraken’s API’s end-points. Note that the value given to the arguments will always be strings; the comments below indicate how the strings will be interpreted by the exchange.

When submitting a trade instruction, are we buying or selling?

When submitting a trade instruction, what order type do we want to make?

When exporting bulk data, we must specify the nature of the reporting format.


Obtain a handle on a connection to the Kraken exchange.