🦈 Minimal, elegant, fast, async Kraken exchange WebSockets API client | Written in Rust
Description
squalo library aims to interface your software with the Kraken exchange WebSockets API in no time.
Prerequisites
The Kraken exchange allows WebSockets API interaction with both public and private data.
Only for the private one, you need to issue an API-Key and an API-Secret to the squalo library, in order to generate authentication token for signed subscriptions on WebSockets endpoints.
If you are not familiar with, please have a look at WebSockets API - FAQ for a general overview, or at WebSockets API document.
Implementation
Add this to your Cargo.toml:
[]
= { = 0.1.6}
and then add this to your code:
use squalo;
Methods
print_crate_info;
Description: prints crate information (name, description, version, author and repository).
set_kraken_api_credentials;
Description: sets Kraken API credentials for private data access.
Required:
- api_key:
String - api_secret:
String
get_websockets_token.await;
Description: retrieves a WebSockets API token with a signed request from a Kraken REST API endpoint.
Output: returns a WebSockets API token in the String format.
create_communication_channel;
Description: returns a couple of objects, an UnboundedSender (tx) and an UnboundedReceiver (rx) both used for bidirectional interoperation with the WebSocket client.
attach_websockets_stream;
Description: spawns a thread which initializes a WebSocket client (accordingly with the stream_type). The receiver bridges the gap with the incoming data stream and the callback.
Required:
- callback:
fn(eg: fn callback(data: &str) { println("data: {}", data); }) - stream_type:
String(eg "public" or "private") - receiver:
UnboundedReceiver<Message>(retrieved from thesqualo::create_communication_channel()method)
Output: any incoming message forwared from the WebSockets stream to the issued callback comes in stringified JSON format (parse accordingly with the outcome shape).
send_message;
Description: fowards a message to the spawned thread handling the WebSocket client that will write the payload to the stream.
Example
The example below shows how easy is to implement squalo from zero knowledge.
use squalo;
async
Disclaimer
This software comes without any kind of warranties.
I will not be liable for any damages related to the use or the misuse of this software.
You are the sole responsible.
