node-kraken-ws v5.1.0
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 thedebug
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
- 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
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 */ }
- payload:
- kraken:connection:error
- paylaod: instance of
Error
- paylaod: instance of
- 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.
- See subscriptionStatus. The response of the kraken websocket is just forwarded The payload additionally has a
- kraken:subscribe:failure
- See subscriptionStatus. The response of the kraken websocket is just forwarded
- kraken:unsubscribe:success
- kraken:subscription:event
- See Kraken Websocket api. The response of the kraken websocket is just forwarded
- 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 | / |