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 🙏

© 2024 – Pkg Stats / Ryan Hefner

buycoins-kraken-exchange

v1.9.4

Published

Simple library to access the Kraken Exchange API

Downloads

3

Readme

kraken-exchange

Access all elements of the Kraken API

This module fully implements the Kraken API. The full documentation for the API is available on the API help page.

It is written in Coffescript V2 using native Promises and its only dependency is bent. You do not need Coffeescript to use the library; it is pre-compiled to Javascript ES6.

Kraken uses currency symbols preceded by an X or a Z to bring all symbols to four characters. For example XXBT, ZUSD, XETH but DASH with no preceding X. This library uses the three-letter forms thoughout, other than where the base symbol is four letters, e.g. DASH. Thus Euros are always referred to as EUR and Bitcoin as XBT.

There are a few extra methods that are not provided by the Kraken API. These are utility methods which generally give a simplified view of another method. Examples are kraken.profitLoss() and kraken.bidAsk().

Install

npm install kraken-exchange

Get your API key and private key from here.

Example

Kraken = require('kraken-exchange');

const API_KEY = 'MlWItZtB4hqE2c2I9lg3DfnlYFvLQ9CR19Nmd373UEsJtpdAHQlk4NC3';
const PRIV_KEY = 'NZxR7Qyy7vf59fiomB0j1VFVL4J4BAVpKrHmf4hUUQefVFzhlw6as9CScA24cNNsmjb14nl65ZRyy13zlkWxzA';

const kraken = new Kraken(API_KEY, PRIV_KEY);

kraken.time()
.then(response => console.log(response));
.catch(err => console.error(err));

Constructor

const kraken = new Kraken(API_KEY, PRIV_KEY);

Methods

For each method (other than the derived methods), please see the API documentation. Below I have simply documented the call; the response will generally be as documented by Kraken. Currency codes will have been converted and floating responses may be returned as floats rather than strings.

All methods return Promises and pass a single result object to the .then(). Optional parameters are shown within square brackets: [ and ]. It may be necessary to pass a null for some parameters in order to pass later ones.

No errors are caught or reported within the library. All calls should have a .catch(err) to pick up the error.

N.B. The order of parameters in methods is as below which may differ from the Kraken documentation in order to put less-used parameters twards the end of the list.

Derived methods

Average price between bid and ask

kraken.bidAsk(...pairs)

The parameters can be a list of pairs or a single array can be passed.

So kraken.bidAsk('XBTEUR', 'ETHEUR'); or kraken.bidAsk(['XBTEUR', 'ETHEUR']);, whichever is easier for the application.

Profit and loss on open positions

kraken.profitLoss(byPair = false)

This will return an object with the current net profit or loss for each currency in open positions.

If byPair is passed as true, it will return the current net profit or loss for each currency pair rather than each currency.

Public market data

Get server time

kraken.time()

Get asset info

kraken.assets(...assets)

The parameters can be a list of assets or a single array can be passed.

So kraken.assets('XBT', 'ETH'); or kraken.assets(['XBT', 'ETH']);, whichever is easier for the application.

Get tradable asset pairs

kraken.assetPairs(...pairs)

The parameters can be a list of pairs or a single array can be passed.

So kraken.assetPairs('XBTEUR', 'ETHEUR'); or kraken.assetPairs(['XBTEUR', 'ETHEUR']);, whichever is easier for the application.

Get ticker information

kraken.ticker(...pairs)

The parameters can be a list of pairs or a single array can be passed.

Get OHLC data

kraken.ohlc(pair[, interval[, last]])

Get order book

kraken.depth(pair[, count])

Get recent trades

kraken.trades(pair[, since])

Get recent spread data

kraken.spread(pair[, since])

Private user data

Get account balance

kraken.balance()

Get trade balance

kraken.tradeBalance([currency])

Get open orders

kraken.openOrders([trades[, userref]])

Get closed orders

kraken.closedOrders([trades[, userref[, start[, end[, ofs[, closetime]]]]]])

Query orders info

kraken.queryOrders(txids[, trades[, userref]])

Note that txids can be a single transaction id, an array of transaction ids or a comma-separated list of transaction ids.

Get trades history

kraken.tradesHistory([type[, trades[, start[, end[, ofs]]]]])

Query trades info

kraken.queryTrades(txids[, trades])

Note that txids can be a single transaction id, an array of transaction ids or a comma-separated list of transaction ids.

Get open positions

kraken.openPositions([docalcs[, txids]]);

Note that txids can be a single transaction id, an array of transaction ids or a comma-separated list of transaction ids.

Get ledgers info

kraken.ledgers([assets[, type[, start[, end[, ofs]]]]])

Note that assets can be a single asset, an array of assets, a comma-separated list of assets or undefined.

Query ledgers

kraken.queryLedgers(...ids)

The parameters can be a list of ledger ids or a single array can be passed.

Get trade volume

kraken.tradeVolume(..pairs)

The parameters can be a list of currency pairs or a single array can be passed.

Private user trading

Add standard order

kraken.addOrder(pair, type, ordertype, volume[, price[, price2[, leverage[, closetype[, closeprice[, closeprice2]]]]]])

or

kraken.addOrder(params)

where params is an object with the required keys and values from the list above.

Cancel open order

kraken.cancelOrder(txid)

Private user funding

Get deposit methods

kraken.depositMethods(asset)

Get deposit addresses

kraken.depositAddresses(asset, method[, newAddress])

Get status of recent deposits

kraken.depositStatus(asset, method)

Get withdrawal information

kraken.withdrawInfo(asset, key, amount)

Withdraw funds

kraken.withdraw(asset, key, amount)

Wallet Transfer

kraken.walletTransfer(asset, amount)

Get status of recent withdrawals

kraken.withdrawStatus(asset[, method])

Request withdrawal cancelation

kraken.withdrawCancel(asset, refid)

Versions

Version 1.8.0 onwards replaces request (which has been deprecated) with bent by the same author. This has considerably reduced the size of this package and of its dependencies.

Issues

Please report any bugs or make any suggestions at the Github Issue page.