npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

node-kraken-ws

v5.1.0

Published

A websocket library for the kraken exchange

Readme

node-kraken-ws

This is a kraken websocket implementation written by some rando on the internet.

Tests have not been implemented yet and the docs are still incomplete.

Breaking changes in Version 5

  • The log options has been removed, the library now uses the debug module.
  • The library does not automatically reconnect when the connection closes or when connecting fails
    • Consumers should use the promise responses when connecting and the heartbeat or a custom ping/pong mechanism to determine whether the connection is alive or not and reconnect manually. This can be done with the reconnect method

How to use

A websocket connection can subscribe to either public or private channels. For this reason, there are two implementations, one for public & one for private channels.

Connecting

Creating an instance will not connect to the web socket, instead, contrary to 3.x versions, the connect method has to be used:

import { KrakenWSPublic, KrakenWSPrivate } from 'node-kraken-ws'

async () => {
  const public = new KrakenWSPublic()
  await public.connect()

  const private = new KrakenWSPrivate()
  await private.connect()
}

Subscribing

Subscribing will always return a promise with the properties described in the docs. A unsubscribe prop will be added by this library:

import { KrakenWSPublic, KrakenWSPrivate } from 'node-kraken-ws'

async () => {
  const instance = new KrakenWSPublic()
  await instance.connect()

  const {
    ...originalPayload,
    unsubscribe, // Function
  } = await instance.subscribe(...)
}

Listening to events

import { KrakenWSPublic, KrakenWSPrivate } from 'node-kraken-ws'

async () => {
  const instance = new KrakenWSPublic()
  await instance.connect()
  const { channelID } = await instance.subscribeToSpread(...)

  const removeListener = instance.on('kraken:subscribe:event', payload => {
    if (payload[0] !== channelID) return
    // ...
  })
}

List of shared events

  • kraken:connection:closed
  • kraken:connection:establishing
  • kraken:connection:established
    • payload: { ws: /* instance of the actual websocket */ }
  • kraken:connection:error
    • paylaod: instance of Error
  • kraken:connection:reconnecting:start
  • kraken:connection:reconnecting:failure
  • kraken:subscribe:success
  • kraken:subscribe:error
    • See subscriptionStatus. The response of the kraken websocket is just forwarded The payload additionally has a unsubscribe property, which can be used to unsubscribe to the channel.
  • kraken:subscribe:failure
  • kraken:unsubscribe:success
  • kraken:subscription:event
  • kraken:unhandled

Public channels

import { KrakenWSPublic } from 'node-kraken-ws'

const ws = new KrakenWSPublic({ /* pass options */ })

Public channel methods:

subscribeToTicker

Arguments

| arguments | type | required | default value | |-----------|------|----------|---------------| | pair | String | yes | / | | reqid | Int | no | / |

subscribeToOHLC

Arguments

| arguments | type | required | default value | |-----------|------|----------|---------------| | pair | String | yes | / | | reqid | Int | no | / | | interval | Int | no | / |

subscribeToTrade

Arguments

| arguments | type | required | default value | |-----------|------|----------|---------------| | pair | String | yes | / | | reqid | Int | no | / |

subscribeToSpread

Arguments

| arguments | type | required | default value | |-----------|------|----------|---------------| | pair | String | yes | / | | reqid | Int | no | / |

subscribeToBook

Arguments

| arguments | type | required | default value | |-----------|------|----------|---------------| | pair | String | yes | / | | reqid | Int | no | / | | depth | Int | no | / |

Private channels

import { KrakenWSPrivate } from 'node-kraken-ws'

const ws = new KrakenWSPrivate({ /* pass options */ })

List of private events

kraken:addorder:success

See the response payload of the addOrder message

kraken:addorder:failure

See the response payload of the addOrder message

kraken:cancelorder:success

See the response payload of the addOrder message

kraken:cancelorder:failure

See the response payload of the addOrder message

kraken:cancelall:success

See the response payload of the addOrder message

kraken:cancelall:failure

See the response payload of the addOrder message

Private channel methods:

subscribeToOwnTrades

Arguments

| arguments | type | required | default value | |-----------|------|----------|---------------| | reqid | Int | no | / | | snapshot | Bool | no | / |

subscribeToOpenOrders

Arguments

| arguments | type | required | default value | |-----------|------|----------|---------------| | reqid | Int | no | / |

Private order methods

addOrder

| arguments | type | required | default value | |-----------|------|----------|---------------| | ordertype | String | yes | / | | type | String | yes | / | | pair | String | yes | / | | volume | Float | yes | / | | reqid | Int | no | / | | price | Float | no | / | | price2 | Float | no | / | | reqid | Int | no | / | | leverage | Float | no | / | | oflags | String | no | / | | starttm | String | no | / | | expiretm | String | no | / | | userref | String | no | / | | validate | String | no | / | | close | Object | no | / | | close.ordertype | String | no | / | | close.price | Float | no | / | | close.price2 | Float | no | / | | trading_agreement | String | no | / |

Returns

Promise

Resolves with:
{
  event: String
  reqid: Int
  status: "ok" | "error"
  txid?: String
  descr?: String
}
Rejects with:
{
  event: String
  reqid: Int
  status: "ok" | "error"
  errorMessage?: String
}

cancelOrder

| arguments | type | required | default value | |-----------|------|----------|---------------| | txid | String | String[] | yes | / | | reqid | Int | no | / |

Returns*:

Promise

Resolves with:

void

Rejects with

void

cancelAll

| arguments | type | required | default value | |-----------|------|----------|---------------| | reqid | Int | no | / |