Skip to content

Latest commit

 

History

History
446 lines (301 loc) · 8.79 KB

README.md

File metadata and controls

446 lines (301 loc) · 8.79 KB

luno-api-node

A simple wrapper for the Luno API. The module supports promise and callbacks.

This module is forked from https://github.com/bausmeier/node-bitx. Since the original repository is not maintained anymore, starting with version v2.0.0 this fork has been detached from original repository. It is now stand alone. Contributions are not pull-requested to original repository.

Usage

Add luno as a dependency:

$ npm install --save luno-api-node

Luno([keyId, keySecret][, options])

To access the private Luno API methods you must supply your key id and key secret as the first two arguments. If you are only accessing the public API endpoints you can leave these two arguments out.

The optional options argument can be used to override the default options. The default options are equivalent to:

{
  hostname: 'api.luno.com',
  port: 443,
  ca: undefined,
  pair: 'XBTZAR'
}

Properties

apiCallRate

Gives the current rate per minute of API calls. The property is read only. It can be used by applications to limit the API call rate to prevent HTTP error code 429 (too many requests) responses from Luno server. See Luno API documentation for applicable rate limitations: https://www.luno.com/en/developers/api#tag/Rate-Limiting

API calls which result in error code 429 or ErrTooManyRequests are considered failed/unprocessed server request and are not added to the apiCallRate counter

Example:

console.log(luno.apiCallRate)

Methods

For details about the API endpoints see https://www.luno.com/en/developers/api.

Callbacks

The arguments passed to the callback function for each method are:

  1. An error or null if no error occurred.
  2. An object containing the data returned by the Luno API.

The callback function is optional. If the callback is not provided, the methods return a promise.

createAccount(currency, name[, callback])

POST https://api.luno.com/api/1/accounts

Example:

luno.createAccount('XBT', 'Trading ACC', function (err, response) {})

updateAccountName(currency, name[, callback])

PUT https://api.luno.com/api/1/accounts/{id}/name

Example:

luno.updateAccountName(12345, 'Trading ACC', function (err, response) {})

listAccountPendingTransactions(id[, callback])

GET https://api.luno.com/api/1/accounts/{id}/pending

Example:

luno.listAccountPendingTransactions(12345, function (err, response) {})

listAccountTransactions(id, min_row, max_row[, callback])

GET https://api.luno.com/api/1/accounts/{id}/transactions

Example:

luno.listAccountTransactions(12345, 1, 1000, function (err, response) {})

listAccountBalances([assets][, callback])

GET https://api.luno.com/api/1/balance

Example:

luno.listAccountBalances(['XBT', 'ETH'], function (err, response) {})

getMove(options[, callback])

GET https://api.luno.com/api/exchange/1/move

Example:

luno.getMove({ id: 18563829047 }, function (err, response) {})

move(amount, debit_account_id, credit_account_id [,options] [, callback])

POST https://api.luno.com/api/exchange/1/move

Example:

luno.move('10000', 12345, 12346, { client_move_id: 'mv-53960812' }, function (err, response) {})

listMoves([options][, callback])

GET https://api.luno.com/api/exchange/1/move/list_moves

Example:

luno.listMoves({ before: 1530865703508, limit: 986 }, function (err, response) {})

getTicker([options][, callback])

GET https://api.luno.com/api/1/ticker/XBTZAR

Default options:

{
  pair: luno.pair
}

Example:

luno.getTicker(function (err, ticker) {})

getAllTickers([callback])

GET https://api.luno.com/api/1/tickers

Example:

luno.getAllTickers(function (err, tickers) {})

getOrderBook([options][, callback])

GET https://api.luno.com/api/1/orderbook

Default options:

{
  pair: luno.pair
}

Example:

luno.getOrderBook(function (err, orderBook) {})

getTrades([options][, callback])

GET https://api.luno.com/api/1/trades

Default options:

{
  pair: luno.pair
}

Example:

luno.getTrades(function (err, trades) {})

getTradeList([options][, callback])

GET https://api.luno.com/api/1/listtrades

Default options:

{
  pair: luno.pair
}

Example:

luno.getTradeList({ sort_desc: true, limit: 10 }, function (err, tradeList) {})

getOrderList([options][, callback])

GET https://api.luno.com/api/1/listorders

Default options:

{
  pair: luno.pair,
  state: undefined
}

Example:

luno.getOrderList({ state: 'PENDING' }, function (err, orderList) {})

getOrderListV2([options][, callback])

GET https://api.luno.com/api/exchange/2/listorders

Default options:

{
  pair: luno.pair,
  state: undefined
}

Example:

luno.getOrderListV2({ closed: true }, function (err, orderList) {})

getOrderListV3(options[, callback])

GET https://api.luno.com/api/exchange/3/order

Example:

luno.getOrderListV3({ id: 'BXMC2CJ7HNB88U4' }, function (err, orderList) {})

getBalance([asset][, callback])

GET https://api.luno.com/api/1/balance

Example:

luno.getBalance('ZAR', function (err, balance) {})

getFundingAddress(asset[, options][, callback])

GET https://api.luno.com/api/1/funding_address

Default options:

{
  address: undefined
}

Example:

luno.getFundingAddress('XBT', { address: 'B1tC0InExAMPL3fundIN6AdDreS5t0Use' }, function (err, fundingAddress) {})

createFundingAddress(asset[, callback])

POST https://api.luno.com/api/1/funding_address

Example:

luno.createFundingAddress('XBT', function (err, fundingAddress) {})

getFeeInfo([options][, callback])

GET https://api.luno.com/api/1/fee_info

Default options:

{
  pair: luno.pair
}

Example:

luno.getFeeInfo({ pair: 'XBTZAR' }, function (err, feeInfo) {})

postBuyOrder(volume, price[, options][, callback])

POST https://api.luno.com/api/1/postorder

Example:

luno.postBuyOrder(9999.99, 0.01, function (err, order) {})

postSellOrder(volume, price[, options][, callback])

POST https://api.luno.com/api/1/postorder

Example:

luno.postSellOrder(0.01, 9999.99, function (err, order) {})

postMarketBuyOrder(volume[, options][, callback])

POST https://api.luno.com/api/1/marketorder

Example:

luno.postMarketBuyOrder(0.01, function (err, order) {})

postMarketSellOrder(volume[, options][, callback])

POST https://api.luno.com/api/1/marketorder

Example:

luno.postMarketSellOrder(0.01, function (err, order) {})

stopOrder(orderId[, callback])

POST https://api.luno.com/api/1/stoporder

Example:

luno.stopOrder('BXMC2CJ7HNB88U4', function (err, result) {})

getOrder(orderId[, callback])

GET https://api.luno.com/api/1/orders/{orderId}

Example:

luno.getOrder('BXHW6PFRRXKFSB4', function (err, result) {})

getOrderV2(orderId[, callback])

GET https://api.luno.com/api/exchange/2/orders/{orderId}

Example:

luno.getOrderV2('BXHW6PFRRXKFSB4', function (err, result) {})

getOrderV3(options[, callback])

GET https://api.luno.com/api/exchange/3/orders/{orderId}

Example:

luno.getOrderV3({ id: 'BXMC2CJ7HNB88U4' }, function (err, result) {})
luno.getOrderV3({ client_order_id: 'lmt-53960812' }, function (err, result) {})

getTransactions(asset[, options][, callback])

GET https://api.luno.com/api/1/transactions

Default options:

{
  offset: 0,
  limit: 10
}

Example:

luno.getTransactions('XBT', { offset: 5, limit: 20 }, function (err, transactions) {})

getWithdrawals([callback])

GET https://api.luno.com/api/1/withdrawals

Example:

luno.getWithdrawals(function (err, withdrawals) {})

getWithdrawal(withdrawalId[, callback])

GET https://api.luno.com/api/1/withdrawals/{withdrawalId}

Example:

luno.getWithdrawal('1212', function (err, withdrawal) {})

requestWithdrawal(type, amount[, callback])

POST https://api.luno.com/api/1/withdrawals

Example:

luno.requestWithdrawal('ZAR_EFT', 1000, function (err, withdrawal) {})

cancelWithdrawal(withdrawalId[, callback])

DELETE https://api.luno.com/api/1/withdrawals/{withdrawalId}

Example:

luno.cancelWithdrawal('1212', function (err, withdrawal) {})

listTransfers(id[, options][, callback])

GET https://api.luno.com/api/exchange/1/transfers

Example:

luno.listTransfers(1212, { limit: 986 }, function (err, data) {})

Contributing

Open a pull request or create an issue and help me improve it.