SDKs overview

Kraken provides both official and community-contributed Software Development Kits (SDKs) and libraries to facilitate interaction with its trading platform. These SDKs are designed to abstract the complexities of direct API calls, offering developers language-native methods for executing trades, managing accounts, retrieving market data, and interacting with other Kraken services. Developers can utilize these tools to build automated trading bots, portfolio management applications, or integrate Kraken functionalities into larger systems. The underlying APIs consist of a REST API for general requests and a WebSocket API for real-time data streaming.

Using an SDK can expedite development by handling authentication, request formatting, and response parsing, which are typically managed manually when interacting directly with a RESTful API. This approach allows developers to focus on application logic rather than low-level network communication details. Each official SDK is maintained to ensure compatibility with the latest Kraken API versions and features, providing a reliable foundation for development.

While official SDKs offer direct support and maintenance from Kraken, the ecosystem also benefits from various community libraries. These often provide alternative implementations, support for additional languages, or specialized functionalities not present in the official offerings. The choice between an official SDK and a community library typically depends on the specific project requirements, the preferred programming language, and the level of community support and maintenance available for the latter.

Before using any Kraken SDK, developers must generate API keys from their Kraken account. These keys, consisting of a public key and a private key (secret), are used for authentication. It is crucial to manage these keys securely, store them in environment variables or a secure key management system, and grant them only the necessary permissions to prevent unauthorized access to funds or account functionalities. Kraken's API documentation provides detailed guidance on creating and securing API keys.

Official SDKs by language

Kraken supports several official SDKs, each designed for specific programming languages. These SDKs aim to provide a consistent and documented interface for interacting with the Kraken API. The following table outlines the officially supported SDKs:

Language Package/Repository Installation Command Maturity
Python krakenex pip install krakenex Stable
Node.js kraken-api npm install kraken-api Stable
Java kraken-api-client Maven/Gradle dependency Stable
Go go-kraken-rest go get github.com/beldur/go-kraken-rest Stable
C# KrakenApiClient NuGet package Stable

Each of these SDKs provides methods that map to the available API endpoints, such as placing orders, retrieving account balances, or fetching historical market data. Developers are encouraged to refer to the specific documentation for each SDK for detailed usage examples and API endpoint coverage.

Installation

Installation procedures vary based on the programming language and its package management system. Below are typical installation commands for each official Kraken SDK.

Python

The Kraken Python SDK, krakenex, is available via pip:

pip install krakenex

Node.js

For Node.js projects, the kraken-api package can be installed using npm:

npm install kraken-api

Java

Java developers using Maven or Gradle incorporate the kraken-api-client as a dependency. For Maven, add the following to your pom.xml:

<dependency>
    <groupId>com.github.krypt-project</groupId>
    <artifactId>kraken-api-client</artifactId>
    <version>[latest_version]</version>
</dependency>

Replace [latest_version] with the current version, typically found on the Kraken API client GitHub repository.

Go

The Go SDK, go-kraken-rest, is installed using the Go module system:

go get github.com/beldur/go-kraken-rest

C#

C# developers can install the KrakenApiClient via NuGet Package Manager:

Install-Package KrakenApiClient

Or using the .NET CLI:

dotnet add package KrakenApiClient

Quickstart example

This Python example demonstrates how to initialize the krakenex SDK, retrieve the current server time, and fetch an account balance. This requires valid API keys (api_key and api_secret) configured with appropriate permissions on your Kraken account.

import krakenex
import os

# Initialize Kraken API client
kraken = krakenex.API()

# Load API keys from environment variables for security
kraken.key = os.environ.get('KRAKEN_API_KEY')
kraken.secret = os.environ.get('KRAKEN_API_SECRET')

# Check if API keys are loaded
if not kraken.key or not kraken.secret:
    print("Error: KRAKEN_API_KEY and KRAKEN_API_SECRET environment variables must be set.")
    exit()

# Example 1: Get server time (public endpoint, no authentication needed)
try:
    response_time = kraken.query_public('Time')
    if 'error' in response_time and response_time['error']:
        print(f"Error fetching server time: {response_time['error']}")
    else:
        print(f"Server Time: {response_time['result']['rfc1123']}")
except Exception as e:
    print(f"An error occurred during server time request: {e}")

# Example 2: Get account balance (private endpoint, requires authentication)
try:
    response_balance = kraken.query_private('Balance')
    if 'error' in response_balance and response_balance['error']:
        print(f"Error fetching balance: {response_balance['error']}")
    else:
        print("Account Balances:")
        for currency, amount in response_balance['result'].items():
            print(f"  {currency}: {amount}")
except Exception as e:
    print(f"An error occurred during balance request: {e}")

Before running this code:

  1. Install the krakenex library: pip install krakenex.
  2. Set your Kraken API key and secret as environment variables:

    • export KRAKEN_API_KEY='YOUR_PUBLIC_KEY'
    • export KRAKEN_API_SECRET='YOUR_PRIVATE_KEY'
  3. Ensure your API key has at least 'Query Ledger Entries' permission for the Balance call.

Community libraries

Beyond the official SDKs, the Kraken developer community has contributed several libraries across various programming languages. These libraries often offer alternative interfaces, additional features, or support for languages not covered by official SDKs. While official SDKs are maintained by Kraken, community libraries rely on open-source contributions and may vary in their level of maintenance, documentation, and feature parity with the latest API changes.

Some examples of community-driven efforts include:

  • PHP clients: Several independent PHP libraries exist for interacting with the Kraken API, often found on platforms like GitHub. These cater to developers building web applications with PHP.
  • Ruby wrappers: A few Ruby gems provide object-oriented wrappers around the Kraken API, simplifying its use in Ruby-based applications.
  • Unofficial Go SDKs: While there is an official Go SDK, other community-maintained Go libraries might offer different architectural approaches or specific optimizations.

When considering a community library, developers should evaluate its active maintenance, the thoroughness of its documentation, the presence of a responsive community, and its compatibility with the current Kraken API version. Examining the project's GitHub repository for recent commits, open issues, and pull requests can provide insight into its health and reliability. For example, the principles of open-source contribution often lead to robust community-maintained projects, but diligence is required to select appropriate tools.

Always prioritize security when using any third-party library, especially those interacting with financial APIs. Review the source code if possible, and ensure that sensitive information like API keys is handled securely and not hardcoded directly into the application.