#websocket #kraken #trading #api-client #client #api

kraken_ws_client

A strongly-typed client for the Kraken WebSocket API

7 releases (breaking)

0.27.0 Nov 28, 2024
0.26.0 Jul 10, 2024
0.25.0 Jan 29, 2024
0.24.0 Jan 4, 2024
0.20.0 Aug 14, 2023

#948 in Magic Beans

Download history 5/week @ 2024-09-16 8/week @ 2024-09-23 6/week @ 2024-09-30 2/week @ 2024-10-07 2/week @ 2024-10-14 1/week @ 2024-10-21 5/week @ 2024-11-04 2/week @ 2024-11-11 11/week @ 2024-11-18 115/week @ 2024-11-25 15/week @ 2024-12-02

144 downloads per month

Apache-2.0

43KB
1K SLoC

Kraken WebSocket API Client

A strongly-typed Rust SDK for the Kraken WebSocket API.

This crate is an unofficial, community-driven effort.

Installation

[dependencies]
kraken_ws_client = "0.24"

Usage

use futures::StreamExt;
use kraken_ws_client::api::SubscribeTickerRequest;

#[tokio::main]
async fn main() {
    let mut client = kraken_ws_client::connect_public()
        .await
        .expect("cannot connect");

    client
        .send(SubscribeTickerRequest::symbol("BTC/USD"))
        .await
        .expect("cannot send request");

    while let Some(event) = client.ticker_events().next().await {
        dbg!(&event);
    }
}
use kraken_rest_client::Client as RestClient;

let api_key = std::env::var("KRAKEN_API_KEY").expect("api key not defined");
let api_secret = std::env::var("KRAKEN_API_SECRET").expect("api secret not defined");

let rest_client = RestClient::new(api_key, api_secret);
let resp = rest_client.get_web_sockets_token().send().await?;
let token = resp.token;

let mut ws_private_client = kraken_ws_client::connect_private(token)
    .await
    .expect("cannot connect");

ws_private_client
    .send(SubscribeExecutionsRequest::new())
    .await
    .expect("cannot send request");

while let Ok(msg) = ws_private_client.messages().recv().await {
    dbg!(msg);
}

or run the example:

cargo run --example ticker

Status

The software is under active development and the API is expected to change.

Contributing

Pull requests, issues and comments are welcome! Make sure to add tests for new features and bug fixes.

License

This work is licensed under the Apache-2.0 License. See LICENSE.txt or https://spdx.org/licenses/Apache-2.0.html for details.

Copyright © 2022 Georgios Moschovitis.

Dependencies

~6–13MB
~147K SLoC