5.1.0 • Published 3 years ago

node-kraken-ws v5.1.0

Weekly downloads
29
License
BSD-3-Clause
Repository
github
Last release
3 years ago

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
argumentstyperequireddefault value
pairStringyes/
reqidIntno/

subscribeToOHLC

Arguments
argumentstyperequireddefault value
pairStringyes/
reqidIntno/
intervalIntno/

subscribeToTrade

Arguments
argumentstyperequireddefault value
pairStringyes/
reqidIntno/

subscribeToSpread

Arguments
argumentstyperequireddefault value
pairStringyes/
reqidIntno/

subscribeToBook

Arguments
argumentstyperequireddefault value
pairStringyes/
reqidIntno/
depthIntno/

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
argumentstyperequireddefault value
reqidIntno/
snapshotBoolno/

subscribeToOpenOrders

Arguments
argumentstyperequireddefault value
reqidIntno/

Private order methods

addOrder

argumentstyperequireddefault value
ordertypeStringyes/
typeStringyes/
pairStringyes/
volumeFloatyes/
reqidIntno/
priceFloatno/
price2Floatno/
reqidIntno/
leverageFloatno/
oflagsStringno/
starttmStringno/
expiretmStringno/
userrefStringno/
validateStringno/
closeObjectno/
close.ordertypeStringno/
close.priceFloatno/
close.price2Floatno/
trading_agreementStringno/
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

argumentstyperequireddefault value
txidString | String[]yes/
reqidIntno/
Returns*:

Promise

Resolves with:

void

Rejects with

void

cancelAll

argumentstyperequireddefault value
reqidIntno/
5.1.0

3 years ago

5.0.0-alpha.0

3 years ago

4.0.4

3 years ago

4.0.3

3 years ago

4.0.1

3 years ago

4.0.2

3 years ago

4.0.0

3 years ago

3.1.2

3 years ago

3.1.1

3 years ago

3.1.0

3 years ago

3.0.0

3 years ago

2.1.4

3 years ago

2.0.4

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.0

3 years ago