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.

SpotClient is the primary client for interacting with the Kraken Spot REST API. It covers market data (tickers, order books, candles, spreads), full account state (balances, open orders, positions, ledgers), order lifecycle (submit, amend, cancel, batch), the Earn/staking subsystem, and all deposit and withdrawal operations. All requests are routed to the base URL https://api.kraken.com.

Constructor

Instantiate SpotClient without credentials for public endpoints, or with an API key and secret for private endpoints.
import { SpotClient } from '@siebly/kraken-api';

// Public endpoints require no authentication
const client = new SpotClient();
Kraken Spot API keys use a base64-encoded private key as the secret — not a plain text secret. Make sure you copy the full base64 string from the Kraken web interface.

Available Endpoints

Public methods do not require API credentials and can be called on an unauthenticated SpotClient instance.
MethodDescription
getServerTime()Returns the current server time as a Unix timestamp and RFC 1123 string.
getSystemStatus()Returns the current system status and trading mode (online, cancel_only, post_only, limit_only, maintenance).
getAssetInfo(params?)Returns information about available assets — decimals, display decimals, status, and collateral value.
getAssetPairs(params?)Returns specifications for tradeable asset pairs — tick size, order minimums, available leverage, and fee tiers.
getTicker(params?)Returns ticker data for one or all pairs. Leaving pair empty returns all tradeable markets.
getCandles(params)Returns up to 720 OHLC candles. The last candle is for the current, not-yet-committed interval.
getOrderBook(params)Returns the L2 order book with aggregated quantities at each price level.
getRecentTrades(params)Returns the last 1 000 trades by default.
getRecentSpreads(params)Returns the last ~200 top-of-book spreads for a given pair.
getPreTradeData(params)Returns the top 10 price levels of the order book per pair for transparency reporting.
getPostTradeData(params?)Returns the last 1 000 spot trades across all pairs (or filtered).

Usage Examples

Public Market Data

import { SpotClient } from '@siebly/kraken-api';

const client = new SpotClient();

// Get ticker for a single pair
const ticker = await client.getTicker({ pair: 'XBTUSD' });
console.log('Ticker:', ticker);

// Get L2 order book (top 10 levels)
const orderBook = await client.getOrderBook({ pair: 'XBTUSD', count: 10 });
console.log('Order Book:', orderBook);

Account Data

import { SpotClient } from '@siebly/kraken-api';

const client = new SpotClient({
  apiKey: process.env.API_SPOT_KEY,
  apiSecret: process.env.API_SPOT_SECRET,
});

// Cash balances net of pending withdrawals
const balances = await client.getAccountBalance();
console.log('Balances:', JSON.stringify(balances, null, 2));

// Margin summary (equity, free margin, unrealized P&L)
const tradeBalance = await client.getTradeBalance();
console.log('Trade Balance:', JSON.stringify(tradeBalance, null, 2));

Order Placement

import { SpotClient } from '@siebly/kraken-api';

const client = new SpotClient({
  apiKey: process.env.API_SPOT_KEY,
  apiSecret: process.env.API_SPOT_SECRET,
});

// Limit buy order
const limitOrder = await client.submitOrder({
  ordertype: 'limit',
  type: 'buy',
  volume: '0.0001',
  pair: 'XBTUSD',
  price: '10000',
  cl_ord_id: client.generateNewOrderID(),
});
console.log('Limit Order:', limitOrder);

Order Management

import { SpotClient } from '@siebly/kraken-api';

const client = new SpotClient({
  apiKey: process.env.API_SPOT_KEY,
  apiSecret: process.env.API_SPOT_SECRET,
});

// Amend an existing order's price (preserves queue priority where possible)
const amended = await client.amendOrder({
  txid: 'OXXXXXX-YYYYYY-ZZZZZZ',
  price: '10500',
});
console.log('Amend ID:', amended.result.amend_id);

// Cancel a single order by transaction ID
const cancelled = await client.cancelOrder({ txid: 'OXXXXXX-YYYYYY-ZZZZZZ' });
console.log('Cancelled count:', cancelled.result.count);

generateNewOrderID()

SpotClient exposes a generateNewOrderID() helper that returns a 32-character hex string suitable for use as a cl_ord_id. Client order IDs let you idempotently track and reference your orders even before Kraken assigns a txid.
const orderId = client.generateNewOrderID();
// e.g. "3f2a1b4c8e9d0f1a2b3c4d5e6f7a8b9c"

await client.submitOrder({
  ordertype: 'limit',
  type: 'buy',
  volume: '0.001',
  pair: 'XBTUSD',
  price: '45000',
  cl_ord_id: orderId,   // reference this ID to cancel/amend later
});
Always generate a fresh cl_ord_id per order. Reusing the same ID across orders will result in a rejection.

Validating Orders Without Execution

Both submitOrder and submitBatchOrders accept a validate: true flag. When set, Kraken validates the order parameters and returns what the response would look like — without placing the order. This is useful for integration tests and pre-flight checks.
When validate: true is set, the order is not submitted to the matching engine. No funds are reserved, and no txid is assigned. Use this in staging environments or when testing new order logic.
const validationResult = await client.submitBatchOrders({
  pair: 'XBTUSD',
  validate: true, // dry-run — validate only
  orders: [
    {
      ordertype: 'limit',
      type: 'buy',
      volume: '0.0001',
      price: '45000.00',
      cl_ord_id: client.generateNewOrderID(),
    },
    {
      ordertype: 'limit',
      type: 'sell',
      volume: '0.0001',
      price: '55000.00',
      cl_ord_id: client.generateNewOrderID(),
    },
  ],
});
console.log('Validation Result:', JSON.stringify(validationResult, null, 2));

Further Reading

Market Data Reference

Full parameter documentation for all public endpoints.

Account Reference

Balance, ledger, position, and trade history endpoint details.

Orders Reference

Order types, flags, time-in-force options, and batch constraints.

Funding Reference

Deposit, withdrawal, and Earn/staking endpoint details.

Build docs developers (and LLMs) love