Kraken API: REST and WebSocket Integration for Automated Trading

Build trading bots, portfolio trackers, and institutional infrastructure on the Kraken API. REST endpoints for transactional operations, WebSocket feeds for real-time market data, and HMAC-SHA512 authentication.

Kraken API: The Foundation for Programmatic Trading

API Architecture Overview

  • REST API (api.kraken.com) for order placement, balance queries, trade history, and account management
  • WebSocket API (ws.kraken.com) for real-time order book, trade, ticker, and OHLC data streams
  • HMAC-SHA512 authentication with nonce-based replay protection for all private endpoints
  • Official client libraries for Python, Node.js, Go, Rust, and C# — compliant with NIST cryptographic standards

The Kraken API serves as the programmatic backbone for thousands of trading bots, portfolio management systems, and institutional platforms operating on the exchange. Whether you are a solo developer building your first algorithmic strategy or a quantitative fund deploying high-frequency trading infrastructure across multiple venues, the Kraken API provides the reliability, speed, and security that production systems demand. The API has been battle-tested through every major market event since 2013 — flash crashes, bull runs, regulatory announcements — maintaining consistent availability and deterministic behavior when other exchange APIs fail.

The API architecture follows a clear separation of concerns. The REST API handles discrete, transactional operations: placing and cancelling orders, querying balances and open positions, retrieving trade and ledger history, and managing account settings. Each REST request is a self-contained HTTP call with explicit input and output. The WebSocket API provides persistent, bidirectional connections for streaming real-time market data. Order book snapshots with incremental updates, live trade feeds, OHLC (Open-High-Low-Close) candle data, and spread information flow continuously without the polling overhead of repeated REST calls. Most production trading systems combine both: WebSocket for market data ingestion and signal generation, REST for order execution and account management.

Security is foundational to the Kraken API design. Every private API call requires cryptographic authentication using HMAC-SHA512 signatures computed from your API secret, a monotonically incrementing nonce, the request URI path, and the SHA-256 hash of the POST data. This multi-factor signature scheme ensures that even if network traffic is intercepted, requests cannot be forged or replayed. API keys support granular permission scoping — you can create read-only keys for portfolio dashboards, trade-only keys for bots, and restrict all keys to specific IP addresses via whitelisting. The CISA cybersecurity guidelines recommend exactly this type of least-privilege access model for automated financial systems.

REST API

The REST API at api.kraken.com provides HTTP endpoints for all transactional operations. Public endpoints (no auth required) serve market data: ticker, order book depth, OHLC, trade history, and asset info. Private endpoints (auth required) handle order management, balance queries, ledger exports, staking operations, and withdrawal requests. Response format is JSON with standardized error handling across all endpoints.

WebSocket API

The WebSocket API at ws.kraken.com and ws-auth.kraken.com provides persistent streaming connections. Public feeds deliver real-time order book updates, trades, tickers, OHLC data, and spread information. Authenticated feeds provide personal trade execution reports, order status updates, and balance change notifications. Subscribe to multiple channels on a single connection with minimal latency overhead.

API Authentication and Key Management

Generating API keys is straightforward. After your Kraken login, navigate to Security > API and create a new key pair. Kraken provides a public key (used to identify your requests) and a private secret (used to sign them). The private secret is displayed only once at creation time — store it immediately in a secure location such as an encrypted password manager or a hardware security module (HSM). If the secret is lost, you must generate a new key pair.

Permission granularity is a critical security feature. Each API key can be configured with any combination of: Query Funds (read balances), Query Open Orders & Trades (read order status), Query Closed Orders & Trades (read history), Query Ledger Entries, Create & Modify Orders, Cancel/Close Orders, Deposit Funds, Withdraw Funds, and Manage WebSocket Token. A well-designed security model creates separate keys for each function: a read-only key for your portfolio tracker, a trade-only key for your bot, and never grants withdrawal permission to any automated system.

IP whitelisting adds another security layer. When you specify allowed IP addresses for a key, Kraken rejects any request signed with that key if it originates from a non-whitelisted IP. This means that even if your API secret is compromised (leaked in source code, stolen from a compromised server), the attacker cannot use it from their own infrastructure. For production trading systems, always whitelist the specific IPs of your trading servers and never leave the whitelist empty.

Rate Limits and Throttling

Kraken employs a counter-based rate limiting system rather than a simple requests-per-second model. Each account has a rate limit counter that starts at a maximum value (15 for public, 20 for private on standard accounts) and decreases with each API call. The counter replenishes at a fixed rate over time. Different endpoint categories consume different amounts from the counter: a simple balance query might cost 1 point, while a trade history request costs 2 points. Order placement and cancellation have separate, more generous limits to ensure active trading is never throttled.

When the counter reaches zero, subsequent requests return an EAPI:Rate limit error. Your application must implement proper backoff logic — exponential backoff with jitter is the recommended approach. Hammering the API after receiving a rate limit error will not resolve the issue and may result in temporary IP-level blocking. Professional trading applications maintain a local counter mirror and self-throttle before hitting the server-side limit, ensuring continuous operation without interruptions.

For high-volume traders and institutional clients, Kraken offers elevated rate limits as part of the institutional services program. These enhanced limits accommodate the throughput requirements of market-making operations, multi-strategy funds, and high-frequency algorithms that generate hundreds of orders per minute. Contact the institutional team to discuss custom rate limit configurations tailored to your specific operational profile.

WebSocket Integration and Real-Time Data

The WebSocket API transforms how trading applications consume market data. Instead of polling the REST API every second (which consumes rate limit budget and introduces latency), a single WebSocket connection can subscribe to multiple data channels simultaneously. The book channel provides order book snapshots followed by incremental updates, allowing your application to maintain a real-time local copy of the full order book depth. The trade channel streams every executed trade in real-time. The ohlc channel provides candle data across multiple timeframes.

For authenticated operations, the ownTrades and openOrders channels on ws-auth.kraken.com push real-time notifications about your own order fills, partial fills, cancellations, and position updates. This eliminates the need to poll for order status — your application receives instant confirmation when a trade executes. Latency from order book event to your application is typically under 50 milliseconds, making the WebSocket suitable for latency-sensitive strategies that react to market microstructure changes.

Kraken API Endpoints Overview

CategoryEndpointMethodAuth RequiredDescriptionRate Cost
Public/0/public/TickerGETNoCurrent ticker data for any pair1
Public/0/public/DepthGETNoOrder book depth snapshot1
Public/0/public/OHLCGETNoOHLC candle data1
Public/0/public/TradesGETNoRecent trades for a pair1
Private/0/private/BalancePOSTYesAccount balances1
Private/0/private/OpenOrdersPOSTYesList open orders1
Private/0/private/AddOrderPOSTYesPlace a new order0 (separate limit)
Private/0/private/CancelOrderPOSTYesCancel an open order0 (separate limit)
Private/0/private/TradesHistoryPOSTYesClosed trade history2
WebSocketws.kraken.comWSNo (public)Real-time market data streamsN/A
WebSocketws-auth.kraken.comWSYes (token)Private order and trade updatesN/A

Client Libraries and Developer Resources

Kraken provides official and community-maintained client libraries that handle the complexities of authentication, request signing, and response parsing. The official Python library (krakenex) is the most popular choice, supporting both REST and WebSocket APIs with clean, Pythonic interfaces. Node.js developers can use the kraken-api npm package for server-side bot development. Go and Rust libraries are available for high-performance, low-latency applications where garbage collection pauses or runtime overhead must be minimized.

Beyond the client libraries, Kraken provides comprehensive documentation with request/response examples for every endpoint. A sandbox environment allows developers to test their integration against simulated order books without risking real funds. The sandbox mirrors the production API's interface exactly, ensuring that code developed and tested against the sandbox will function identically in production. This development workflow — sandbox testing followed by production deployment — is standard practice for professional trading system development.

For complex integration requirements, the Kraken developer community on GitHub and dedicated forums provides peer support. Common integration patterns — market-making bots, arbitrage systems, portfolio rebalancers, and data aggregation pipelines — are well-documented with open-source reference implementations. Whether you are building a simple price alert system or a sophisticated multi-exchange arbitrage engine, the Kraken API ecosystem provides the tools and documentation to get you from concept to production efficiently.

Frequently Asked Questions

How do I generate Kraken API keys?

After your Kraken login, navigate to Security > API. Click "Generate New Key" and configure permissions (Query, Trade, Fund, Staking). Set IP whitelists to restrict usage to your server IPs. Store the private secret immediately — it is displayed only once and cannot be retrieved later. Create separate keys for different functions.

What are the Kraken API rate limits?

Kraken uses counter-based rate limits. Public endpoints: counter starts at 15. Private endpoints: counter starts at 20 (standard) or higher (institutional). Each call decrements the counter by 1-2 points depending on the endpoint. The counter replenishes over time. Exceeding limits returns EAPI:Rate limit. Implement exponential backoff in your error handling.

What is the difference between the REST API and WebSocket API?

REST handles discrete transactions (placing orders, checking balances, querying history) via HTTP request-response. WebSocket provides persistent real-time streams (order book updates, trades, OHLC) without polling overhead. Most production systems use both: WebSocket for data, REST for execution. See the order types guide for available order types via API.

How does Kraken API authentication work?

Private endpoints require HMAC-SHA512 signatures. Each request includes your public API key, a monotonically incrementing nonce, and a signature computed from: private secret + nonce + URI path + SHA-256(nonce + POST data). The nonce prevents replay attacks. Official client libraries handle signing automatically.

Can I use the Kraken API for automated trading bots?

Yes. The API supports all order types programmatically: market, limit, stop loss, trailing stop, iceberg. WebSocket feeds provide sub-second data for signals. Use Trade-only keys (no withdrawal permission) for bots. Implement proper error handling for rate limits and network failures. Test thoroughly in the sandbox before deploying to production.

Related Kraken Services

Kraken Pro Terminal

Use the Pro web interface alongside your API integration for visual order book monitoring and manual overrides.

Order Types

Understand all order types available via the API including advanced flags like Post-Only, Reduce-Only, and IOC.

Fee Schedule

Calculate trading costs programmatically with fee tier information available through the API endpoints.

Security Guide

Best practices for API key security including IP whitelisting, permission scoping, and secret management.

Build on the Kraken API

Generate your API keys and start integrating with Kraken's institutional-grade trading infrastructure today.