> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kraken.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Rust

[kraken-sdk](https://github.com/krakenfx/kraken-api-sdk) is the official Rust SDKs for building integrations against the Spot API. It is async-native, built on tokio, and presents REST and WebSocket v2 behind a single client.

<Note>
  Currently Spot-only. Derivatives support is planned.
</Note>

## Requirements

Requires Rust 1.88 or later and the tokio async runtime.

## Install

```toml theme={null} theme={null}
[dependencies]
kraken-sdk = { git = "https://github.com/krakenfx/kraken-api-sdk", tag = "v0.1.0" }
tokio = { version = "1", features = ["full"] }
rust_decimal = "1"
```

## What it covers

* Spot REST — complete public market data, plus authenticated account and trading endpoints
* Spot WebSocket v2 — public data streams and the authenticated `executions` and `balances` channels
* Order operations: add, amend, cancel, batch add, batch cancel, cancel-all, and a dead man's switch
* Order routing over REST or authenticated WebSocket, selectable per call
* Real-time order book construction with CRC32 checksum validation and automatic reseeding on mismatch
* Automatic reconnect with subscription replay
* Typed errors carrying a stable code, category, retryable flag and request id
* An event bus for connection state, rate-limit warnings, order book gaps and order lifecycle

## Example

```rust theme={null} theme={null}
use kraken_sdk::{ApiKey, Client, Symbol};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let client = Client::builder()
        .with_api_key(
            ApiKey::new(std::env::var("KRAKEN_API_KEY")?),
            std::env::var("KRAKEN_API_SECRET")?,
        )?
        .build()?;

    let resp = client.trade()
        .limit_buy(Symbol::new("BTC/USD")?, "0.01".parse()?, "60000".parse()?)
        .await?;

    println!("placed {:?}", resp.txid);
    Ok(())
}
```

Public market data needs no credentials:

```rust theme={null} theme={null}
use kraken_sdk::{Client, Symbol};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let client = Client::builder().build()?;
    let pair = Symbol::new("BTC/USD")?;

    let tickers = client.market().ticker(Some(&[pair.clone()])).await?;
    if let Some(t) = tickers.get(&pair) {
        println!("last={} bid={} ask={}", t.last_price, t.bid_price, t.ask_price);
    }
    Ok(())
}
```

## Notes for developers coming from other Kraken SDKs

* **Symbols use the modern format only.** `BTC/USD`, not `XBTUSD` or `XXBTZUSD`. Legacy codes return a typed error rather than being silently translated. Asset codes in responses are normalised the same way, so balances are keyed `BTC` and `USD`.
* **Prices and quantities are decimals, not floats.** Parse them from strings (`"0.01".parse()?`). The API does not accept `f64`.
* **A WebSocket subscription is two steps:** register a handler, then subscribe. The `on_*_for` helpers do both in one call and unsubscribe when dropped.
* **Rate limits are reported, not enforced.** The SDK emits a warning event as you approach your tier limit and never sleeps on your behalf, so pacing stays under your control.
