Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/sieblyio/kraken-api/llms.txt

Use this file to discover all available pages before exploring further.

Private streams deliver real-time account state changes: order fills, status transitions, balance updates, and open positions. They require valid API keys. The SDK handles every authentication detail automatically — token fetching, caching, challenge signing, and re-authentication after reconnects — so you only need to call subscribe().

Authentication flow

You do not need to manually fetch WebSocket tokens or inject authentication parameters into your subscription payloads. The SDK does this for you automatically based on the keys you provided at construction time.
The authentication mechanism differs by market:
  • Spot private (spotPrivateV2, spotL3V2, spotBetaPrivateV2): The SDK calls the REST API to fetch a short-lived WebSocket token and injects token into each subscription request. The token is cached and refreshed transparently.
  • Derivatives private (derivativesPrivateV1): On connect, the SDK sends a challenge event with your API key. The server responds with a challenge string, which the SDK hashes with SHA-256 and signs with SHA-512 using your API secret. The signed challenge is then included automatically in every private subscription request.

Spot private topics

Spot private streams connect via WS_KEY_MAP.spotPrivateV2 (wss://ws-auth.kraken.com/v2). The one exception is the Level 3 order book, which uses WS_KEY_MAP.spotL3V2 (wss://ws-l3.kraken.com/v2).

Setup

import { WebsocketClient, WS_KEY_MAP } from '@siebly/kraken-api';

const ws = new WebsocketClient({
  apiKey: process.env.API_SPOT_KEY!,
  apiSecret: process.env.API_SPOT_SECRET!,
});

ws.on('open', (data) => {
  console.log('connected:', data.wsKey);
});

ws.on('authenticated', (data) => {
  // Private connection auth handshake completed
  console.log('authenticated:', data.wsKey);
});

ws.on('message', (data) => {
  console.log('data received:', JSON.stringify(data));
});

ws.on('response', (data) => {
  console.log('server reply:', JSON.stringify(data));
});

ws.on('reconnecting', (data) => {
  console.warn('reconnecting — pause order activity:', data.wsKey);
});

ws.on('reconnected', (data) => {
  // Reconcile account state via REST API here
  console.log('reconnected:', data.wsKey);
});

ws.on('exception', (data) => {
  console.error('exception:', data);
});
The executions topic delivers order fills and status changes in real time. It is the primary feed for tracking order lifecycle events.
import { WSTopicRequest } from '@siebly/kraken-api';
import { WSSpotTopic } from '@siebly/kraken-api';

const executionsRequest: WSTopicRequest<WSSpotTopic> = {
  topic: 'executions',
  payload: {
    snap_trades: true,   // Send a snapshot of recent trades on connect — default: false
    snap_orders: true,   // Send a snapshot of open orders on connect — default: true
    order_status: true,  // Include order status in updates — default: true
    ratecounter: true,   // Include rate counter info — default: false
    // users: 'all',     // Filter by user (sub-account scenarios)
  },
};

ws.subscribe(executionsRequest, WS_KEY_MAP.spotPrivateV2);

Complete Spot private example

import {
  WebsocketClient,
  WS_KEY_MAP,
  WSTopicRequest,
} from '@siebly/kraken-api';
import { WSSpotTopic } from '@siebly/kraken-api';

const ws = new WebsocketClient({
  apiKey: process.env.API_SPOT_KEY!,
  apiSecret: process.env.API_SPOT_SECRET!,
});

ws.on('open', (data) => console.log('connected:', data.wsKey));
ws.on('authenticated', (data) => console.log('authenticated:', data.wsKey));
ws.on('message', (data) => console.log('message:', JSON.stringify(data)));
ws.on('response', (data) => console.log('response:', JSON.stringify(data)));
ws.on('reconnecting', (data) => console.warn('reconnecting:', data.wsKey));
ws.on('reconnected', (data) => console.log('reconnected:', data.wsKey));
ws.on('exception', (data) => console.error('exception:', data));

// Order executions and fills
ws.subscribe(
  {
    topic: 'executions',
    payload: {
      snap_trades: true,
      snap_orders: true,
      order_status: true,
      ratecounter: true,
    },
  } as WSTopicRequest<WSSpotTopic>,
  WS_KEY_MAP.spotPrivateV2,
);

// Account balances
ws.subscribe(
  { topic: 'balances' } as WSTopicRequest<WSSpotTopic>,
  WS_KEY_MAP.spotPrivateV2,
);

// Level 3 order book (dedicated L3 endpoint)
ws.subscribe(
  {
    topic: 'level3',
    payload: { symbol: ['BTC/USD'] },
  } as WSTopicRequest<WSSpotTopic>,
  WS_KEY_MAP.spotL3V2,
);

Futures private topics

Futures private streams use WS_KEY_MAP.derivativesPrivateV1 and connect to wss://futures.kraken.com/ws/v1. Authentication is challenge-based and fully automated by the SDK.
Stream real-time updates whenever an open order changes state (placed, filled, cancelled, amended).
// Simple string topic (no parameters needed)
ws.subscribe('open_orders', WS_KEY_MAP.derivativesPrivateV1);

// Or as a typed object
ws.subscribe(
  { topic: 'open_orders' },
  WS_KEY_MAP.derivativesPrivateV1,
);

// Verbose variant — includes full order detail on every update
ws.subscribe('open_orders_verbose', WS_KEY_MAP.derivativesPrivateV1);

Complete Futures private example

import {
  WebsocketClient,
  WS_KEY_MAP,
  WSTopicRequest,
} from '@siebly/kraken-api';
import { WSDerivativesTopic } from '@siebly/kraken-api';

const ws = new WebsocketClient({
  apiKey: process.env.API_FUTURES_KEY!,
  apiSecret: process.env.API_FUTURES_SECRET!,
});

ws.on('open', (data) => console.log('connected:', data.wsKey));
ws.on('authenticated', (data) => console.log('authenticated:', data.wsKey));
ws.on('message', (data) => console.log('message:', JSON.stringify(data)));
ws.on('response', (data) => console.log('response:', JSON.stringify(data)));
ws.on('reconnecting', (data) => console.warn('reconnecting:', data.wsKey));
ws.on('reconnected', (data) => console.log('reconnected:', data.wsKey));
ws.on('exception', (data) => console.error('exception:', data));

// Open orders — standard and verbose variants
ws.subscribe('open_orders', WS_KEY_MAP.derivativesPrivateV1);
ws.subscribe('open_orders_verbose', WS_KEY_MAP.derivativesPrivateV1);

// Trade fills
ws.subscribe(
  { topic: 'fills' } as WSTopicRequest<WSDerivativesTopic>,
  WS_KEY_MAP.derivativesPrivateV1,
);

// Account balances
ws.subscribe('balances', WS_KEY_MAP.derivativesPrivateV1);

// Open positions
ws.subscribe('open_positions', WS_KEY_MAP.derivativesPrivateV1);

// Account log and notifications
ws.subscribe('account_log', WS_KEY_MAP.derivativesPrivateV1);
ws.subscribe('notifications_auth', WS_KEY_MAP.derivativesPrivateV1);

After reconnection

The reconnected event signals that the SDK has successfully re-established the connection, re-authenticated, and resubscribed to all topics. This is the correct moment to call the REST API to reconcile any account state changes that occurred while the WebSocket was down — for example, re-querying open orders or current balances.
ws.on('reconnected', async (data) => {
  console.log('reconnected on', data.wsKey, '— reconciling state...');

  // Example: re-query open orders after reconnect
  // const openOrders = await spotClient.getOpenOrders();
  // rebuildLocalOrderBook(openOrders);
});

Futures private topics reference

TopicDescription
open_ordersOpen order state changes
open_orders_verboseOpen order state changes with full order detail
fillsTrade fill events
balancesAccount balance updates
open_positionsOpen position updates
account_logFull account activity log
notifications_authAuthenticated system notifications

Build docs developers (and LLMs) love