2.1.0 • Published 2 years ago

valr-api-node v2.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
2 years ago

valr-api-node

Build Status

valr-api-node is a simple node.js wrapper for VALR REST and WebSocket API.

Clients for both the REST API and streaming WebSocket API are included.

Contents

Changelog

See detailed Changelog

Installation

npm install --save valr-api-node

Quick examples

REST API example:

import Valr from 'valr-api-node'

const valr = new VALR({ key, secret })
valr.getMarketSummary({ currencyPair: 'BTCZAR' })
  .then(console.log)
  .catch(console.error)

WebSocket API examples:

import Valr from 'valr-api-node'

const valr = new Valr({ key, secret })
let accountWebSocket = valr.newAccountWebSocket()

accountWebSocket.onopen = () => {
  console.log('Websocket is open')
}
  
accountWebSocket.onmessage = (message) => {
  let data = JSON.parse(message.data)
  console.log('Websocket data received')
}
import Valr from 'valr-api-node'

const valr = new Valr({ key, secret })
let tradeWebSocket = valr.newTradeWebSocket()

tradeWebSocket.onopen = () => {
  console.log('Websocket is open')
}
  
tradeWebSocket.onmessage = (msg) => {
  if (msg.type === 'message' && JSON.parse(msg.data).type === 'AUTHENTICATED') {
    const subscribeMessage = {
      type: 'SUBSCRIBE',
      subscriptions: [
        {
          event: 'MARKET_SUMMARY_UPDATE',
          pairs: ['BTCZAR']
        }
      ]
    }
    tradeWebSocket.send(JSON.stringify(subscribeMessage))
  }

  if (msg.type === 'message' && JSON.parse(msg.data).type === 'MARKET_SUMMARY_UPDATE') {
    console.log(msg.data)
  }
}

tradeWebSocket.onerror = (...args) => {
}

Constructor

Valr({ key, secret, key2, secret2 })

ParameterDescription
key, secretoptionalAPI key and secret
key2, secret2optionalSecondary API key and secret

key and secret are required for authenticated API requests.

A secondary pair of API key and secret can be provided, in which case the authenticated API calls will be made alternatively, one with the primary key/secret one with the secondary key/secret. This feature can be used to take advantage of double API rate limit.

REST API

All methods return promises.

Properties

apiCallRate

Gives the current rate of API calls. The property is read only. The counter is reset at the start of each minute.

It can be used by applications to limit the API call rate to prevent HTTP error code 429 (too many requests) responses from VALR server.

See VALR API documentation for applicable rate limitations: Rate limiting

Public APIs

getCurrencies()

Get a list of currencies supported by VALR :bookmark_tabs:.

getCurrencyPairs()

Get all the order types supported for all currency pairs :bookmark_tabs:.

getOrderTypes({ currencyPair })

Get all the order types supported for all currency pairs :bookmark_tabs: or for a given currency pair :bookmark_tabs:.

ParameterDescription
currencyPairoptionalSpecify the currency pair for which you want to query the market summary

getMarketSummary({ currencyPair })

Get the market summary for all currency pairs :bookmark_tabs: or for a given currency pair :bookmark_tabs:.

ParameterDescription
currencyPairoptionalSpecify the currency pair for which you want to query the market summary

getServerTime()

Get the server time :bookmark_tabs:.

getStatus()

Get the current status of VALR :bookmark_tabs:.

Account

The following APIs allow you to query your account balances and full transaction history. These APIs are protected and will require authentication.

getApiKeyInfo()

Returns the current API Key's information and permissions :bookmark_tabs:.

getBalances()

Returns the list of all wallets with their respective balances:bookmark_tabs:.

getAccountTransactionHistory({ skip, limit })

Get the transaction history for your account:bookmark_tabs:.

ParameterDescription
skipoptionalSkip number of items from the list
limitoptionalLimit the number of items returned

getAccountTradeHistory({limit, currencyPair })

Get the last 100 recent trades for the given currency pair for your account:bookmark_tabs:.

ParameterDescription
limitoptionalLimit the number of items returned
currencyPairoptionalSpecify the currency pair for which you want to query the market

Wallets

Access your wallets programmatically.

getDepositAddress({ currencyCode })

Returns the default deposit address associated with currency specified with the parameter currencyCode :bookmark_tabs:.

ParameterDescription
currencyCoderequiredCurrently, the allowed values here are BTC and ETH

getWithdrawalInfo({ currencyCode })

Get all the information about withdrawing a given currency from your VALR account:bookmark_tabs:.

ParameterDescription
currencyCoderequiredThis is the currency code of the currency you want withdrawal information about

newWithdrawal({ currencyCode, amount, address, paymentReference })

Withdraw cryptocurrency funds to an address:bookmark_tabs:.

ParameterDescription
currencyCoderequiredThis is the currency code for the currency you are withdrawing
amountrequiredThe amount to be withdrawn
addressrequiredThe address the funds are withdrawn to
paymentReferenceoptionalWithdrawal request for XRP, XMR, XEM, XLM will accept this optional parameter. Max length is 256

getWithdrawalStatus({ currencyCode, withdrawId })

Check the status of a withdrawal :bookmark_tabs:.

ParameterDescription
currencyCoderequiredThis is the currency code for the currency you have withdrawn
withdrawIdrequiredThe unique id that represents your withdrawal request. This is provided as a response to the API call to withdraw

getDepositHistory({ currencyCode, skip, limit })

Get the Deposit History records for a given currency :bookmark_tabs:.

ParameterDescription
currencyCoderequiredCurrently, the allowed values here are BTC and ETH
skipoptionalSkip number of items from the list
limitoptionalLimit the number of items returned

getWithdrawalHistory({ currencyCode, skip, limit })

Get Withdrawal History records for a given currency :bookmark_tabs:.

ParameterDescription
currencyCoderequiredThis is the currency code for the currency you want the historical withdrawal records
skipoptionalSkip number of items from the list
limitoptionalLimit the number of items returned

getBankAccounts({ currencyCode })

Get a list of bank accounts that are bookmark_tabsed to your VALR account :bookmark_tabs:.

ParameterDescription
currencyCoderequiredThe currency code for the fiat currency. Supported: ZAR

newFiatWithdrawal({ currencyCode, amount, linkedBankAccountId })

Withdraw cryptocurrency funds to an address:bookmark_tabs:.

ParameterDescription
currencyCoderequiredThe currency code for the fiat currency. Supported: ZAR
amountrequiredThe amount to be withdrawn
linkedBankAccountIdrequiredThe bank account Id the funds are withdrawn to

Market Data

These API calls can be used to receive the market data.

getOrderBook({ currencyPair, full })

Withdraw cryptocurrency funds to an address:bookmark_tabs:.

ParameterDescription
currencyPairrequiredCurrency pair for which you want to query the order book. Supported currency pairs: Can be BTCZAR, ETHZAR or XRPZAR
fulloptionaltrue or false (default = false). If it should return a list of all the bids and asks in the order book

getTradeHistory({ currencyPair, limit })

Withdraw cryptocurrency funds to an address:bookmark_tabs:.

ParameterDescription
currencyPairrequiredCurrency pair for which you want to query the trade history. Supported currency pairs: Can be BTCZAR, ETHZAR or XRPZAR
limitoptionalLimit the number of items returned

Simple Buy/Sell

Make use of our powerful Simple Buy/Sell API to instantly buy and sell currencies.

getSimpleQuote({ currencyPair, payInCurrency, payAmount, side })

Get a quote to buy or sell instantly using Simple Buy:bookmark_tabs:.

ParameterDescription
currencyPairrequiredCurrency pair to get a simple quote for. Any currency pair that supports the "simple" order type, can be specified
payInCurrencyrequired
payAmountrequired
siderequiredSELL or BUY

simpleOrder({ currencyPair, payInCurrency, payAmount, side })

Submit an order to buy or sell instantly using Simple Buy/Sell:bookmark_tabs:.

ParameterDescription
currencyPairrequiredCurrency pair to get a simple quote for. Any currency pair that supports the "simple" order type, can be specified
payInCurrencyrequired
payAmountrequired
siderequiredBUY or SELL

getSimpleOrderStatus({ currencyPair, orderId })

Submit an order to buy or sell instantly using Simple Buy/Sell:bookmark_tabs:.

ParameterDescription
currencyPairrequiredCurrency pair of the order for which you are querying the status
orderIdrequiredOrder Id of the order for which you are querying the status

##Exchange Buy/Sell Make use of our powerful Exchange Buy/Sell APIs to place your orders on the Exchange programmatically.

limitOrder({ side, quantity, price, pair, postOnly, customerOrderId })

Create a new limit order :bookmark_tabs:.

ParameterDescription
siderequiredBUY or SELL
quantityrequiredBase amount in BTC
pricerequiredPrice per coin in ZAR
pairrequiredCan be BTCZAR, ETHZAR or XRPZAR
postOnlyoptionaltrue or false
customerOrderIdoptionalAn unique Id across all open orders for a given account. Alphanumeric value with no special chars, limit of 50 characters

marketOrder({ side, amount, pair, customerOrderId })

Create a new market order :bookmark_tabs:.

ParameterDescription
siderequiredBUY or SELL
amountrequiredQuote amount for BUY. Base amount for SELL
pairrequiredCan be BTCZAR, ETHZAR or XRPZAR
customerOrderIdoptionalAn unique Id across all open orders for a given account. Alphanumeric value with no special chars, limit of 50 characters

stopLimitOrder({ side, amount, pair, customerOrderId })

Create a new market order :bookmark_tabs:.

ParameterDescription
siderequiredBUY or SELL
quantityrequiredAmount in Base Currency
pricerequiredThe Limit Price at which the BUY or SELL order will be placed
pairrequiredCan be BTCZAR, ETHZAR or XRPZAR
timeInForcerequiredCan be GTC, FOK or IOC
stopPricerequiredThe target price for the trade to trigger
typerequiredCan be TAKE_PROFIT_LIMIT or STOP_LOSS_LIMIT
customerOrderIdoptionalAn unique Id across all open orders for a given account. Alphanumeric value with no special chars, limit of 50 characters

batchOrders({ requests })

Create a batch of multiple orders, or cancel orders, in a single request :bookmark_tabs:. See VALR API documentation for applicable parameters.

getOrderStatus({ orderId, customerOrderId })

Returns the status of an order that was placed on the Exchange queried using the orderId :bookmark_tabs: or customerOrderId :bookmark_tabs:.

ParameterDescription
currencyPairrequiredCurrency pair
orderId or customerOrderIdrequiredorderId is the order id provided by VALR. customerOrderId is the order Id provided by you when creating the order. Either orderId or customerOrderId can be specified, but not both.

getOpenOrders()

Returns all open orders for your account :bookmark_tabs:.

getOrderHistory({ skip, limit })

Returns historical orders placed by you :bookmark_tabs:.

ParameterDescription
skipoptionalSkip number of items from the list
limitoptionalLimit the number of items returned

getOrderHistorySummary({ orderId, customerOrderId })

Returns a more detailed summary about an order queried using the orderId :bookmark_tabs: or customerOrderId :bookmark_tabs:.

Detailed summary can be requested for an order when the getOrderStatus API call returns one of the following statuses: Filled, Cancelled or Failed.

ParameterDescription
orderId or customerOrderIdrequiredorderId is the order id provided by VALR. customerOrderId is the order Id provided by you when creating the order. Either orderId or customerOrderId can be specified, but not both.

getOrderHistoryDetail({ orderId, customerOrderId })

Returns detailed history of an order's statuses queried using the orderId :bookmark_tabs: or customerOrderId :bookmark_tabs:.

This call returns an array of "Order Status" objects. The latest and most up-to-date status of this order is the zeroth element in the array.

ParameterDescription
orderId or customerOrderIdrequiredorderId is the order id provided by VALR. customerOrderId is the order Id provided by you when creating the order. Either orderId or customerOrderId can be specified, but not both.

cancelOrder({ pair, orderId, customerOrderId })

Cancel an open order :bookmark_tabs:.

ParameterDescription
pairrequiredCurrency pair
orderId or customerOrderIdrequiredorderId is the order id provided by VALR. customerOrderId is the order Id provided by you when creating the order. Either orderId or customerOrderId can be specified, but not both.

WebSocket API

Connection

The methods return a WebSocket object. The WebSocket class that is used to create the websocket can be specified as parameter.

newAccountWebSocket([WebSocketClass, options])

Establishes a WebSocket connection to receive streaming updates about your VALR account.

ParameterDescription
WebSocketClassoptionalWebSocketClass that will be used to create the WebSocket. If omitted It defaults to WebSocket.
optionsoptionalObject that will be passed to the WebSocket constructor

newTradeWebSocket([WebSocketClass, options])

Establishes a WebSocket connection to receive streaming updates about Trade data.

Events subscribing and unsubscribing

Once you open a connection to 'Account', you are automatically subscribed to all messages for all events on the 'Account' WebSocket connection. You will start receiving message feeds pertaining to your VALR account. For example, you will receive messages when your balance is updated or when a new trade is executed on your account.

On the other hand, When you open a connection to 'Trade', in order to receive message feeds about trading data, you must subscribe to events you are interested in on the 'Trade' WebSocket connection.

When you are no longer interested in receiving messages for certain events on the 'Trade' WebSocket connection, you can send a unsubscribe message.

See VALR Websocket API documentation on how to subscribe and unsubscribe to 'Trade' events.

Message Feeds

See VALR Websocket API documentation

License

MIT

2.1.0

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.5.0

2 years ago

1.4.0

3 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.1.2

4 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago