Universal (browser & Node.js) client for the Kraken API
Last updated 2 years ago by fredrikolovsson .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install kraken-api-universal-client 
SYNC missed versions from official npm registry.

Kraken API Universal Client

This is an API client for the Kraken cryptocurrency exchange API, with unit tests (let us know if there's some test you want to add) and no polyfill.

The API client supports all methods on Node.js v6.11.1 or later, and the separately exported public-only client supports calling public methods from the browser as well.


import KrakenClient from 'kraken-api-universal-client'

const kraken = new KrakenClient({
  key: 'YOUR_API_KEY',
  secret: 'YOUR_API_SECRET',

// Handles both public and private requests, as long as the provided API
// credentials have the necessary permissions
kraken.request('Assets') // public
  .then(response => { /**/ })
  .catch(error => { /**/ })
kraken.request('TradeBalance', { body: { asset: 'ZEUR' } }) // private
  .then(response => { /**/ })
  .catch(error => { /**/ })

import { createPublicKrakenClient } from 'kraken-api-universal-client'

const publicKraken = createPublicKrakenClient()

// Handles only public requests; will throw error if attempting private requests
  .then(response => { /* handle response */ })
  .catch(error => { /* handle error */ })


yarn add kraken-api-universal-client


npm install --save kraken-api-universal-client


1. Import client

The default export is the client class and the constants are available as a named export, which you can deconstruct to get e.g. the default endpoints. There is also a named export of createPublicKrakenClient, the factory for the client-side client that only handles public methods.

import KrakenClient, {
} from './index'

const {
} = constants

2. Initialize client

To initialize the client you need an API key and API secret, which you obtain through your Kraken account. For security reasons you should only assign the permissions you truly need to the given API key. If you are going to use the public-only client, you do not need any API credentials.

// default, server-side client
const kraken = new KrakenClient({
  key: 'YOUR_API_KEY',
  secret: 'YOUR_API_SECRET',

// public-only client
const publicKraken = createPublicKrakenClient()

3. Make requests

request(endpointKey: string, options?: {
  body?: object // key-value pairs according to Kraken docs
  fetch?: function // custom-implementation of fetch, used in tests
  nonce?: number // custom nonce, defaults to Number(`${}000`)

To make a request to the Kraken API, call the method request() on your initialized client with the endpointKey, and optionally with a body (containing key-value pairs according to the Kraken docs), a custom-implementation of fetch and/or a custom nonce (it defaults to multiplied by 1000, which was found to satisfy Kraken's requirement of "always increasing unsigned 64 bit integer"). The endpointKey is the last part of the Kraken API URL, e.g. like this:

Note that you do not need to specify whether the endpoint is public or private, the client will know that. If an endpointKey is missing, please submit an issue (and a PR, if you can).

// public method
  .then(response => { /**/ })
  .catch(error => { /**/ })

// private method without body
.then(response => { /**/ })
.catch(error => { /**/ })

// private method with body
kraken.request('TradeBalance', { body: { asset: 'ZEUR' } })
  .then(response => { /**/ })
  .catch(error => { /**/ })


The request method returns a Promise, so use .then() and .catch() to handle a response or error respectively (as seen in the example. Please refer to the Kraken documentation and the client code for the details on how responses and errors are structured.

No polyfill needed

As this library prefers to not polyfill fetch and Promise, it depends on fetch-ponyfill, which is recommended by isomorphic-fetch and uses the browser window.Promise and Node global.Promise. Therefore, make sure to use a Node version that implements Promise (if you follow the "engines" requirement in package.json, you should be fine).


Thanks to:



Current Tags

  • 1.0.0                                ...           latest (2 years ago)

1 Versions

  • 1.0.0                                ...           2 years ago
Maintainers (1)
Today 0
This Week 1
This Month 1
Last Day 1
Last Week 0
Last Month 1
Dependencies (6)
Dev Dependencies (11)
Dependents (0)

Copyright 2014 - 2017 © |