Skip to content

dutu/valr-api-node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

26 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

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 })

Parameter Description
key, secret optional API key and secret
key2, secret2 optional Secondary 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 πŸ“‘.

getCurrencyPairs()

Get all the order types supported for all currency pairs πŸ“‘.

getOrderTypes({ currencyPair })

Get all the order types supported for all currency pairs πŸ“‘ or for a given currency pair πŸ“‘.

Parameter Description
currencyPair optional Specify the currency pair for which you want to query the market summary

getMarketSummary({ currencyPair })

Get the market summary for all currency pairs πŸ“‘ or for a given currency pair πŸ“‘.

Parameter Description
currencyPair optional Specify the currency pair for which you want to query the market summary

getServerTime()

Get the server time πŸ“‘.

getStatus()

Get the current status of VALR πŸ“‘.

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 πŸ“‘.

getBalances()

Returns the list of all wallets with their respective balancesπŸ“‘.

getAccountTransactionHistory({ skip, limit })

Get the transaction history for your accountπŸ“‘.

Parameter Description
skip optional Skip number of items from the list
limit optional Limit the number of items returned

getAccountTradeHistory({limit, currencyPair })

Get the last 100 recent trades for the given currency pair for your accountπŸ“‘.

Parameter Description
limit optional Limit the number of items returned
currencyPair optional Specify 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 πŸ“‘.

Parameter Description
currencyCode required Currently, the allowed values here are BTC and ETH

getWithdrawalInfo({ currencyCode })

Get all the information about withdrawing a given currency from your VALR accountπŸ“‘.

Parameter Description
currencyCode required This is the currency code of the currency you want withdrawal information about

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

Withdraw cryptocurrency funds to an addressπŸ“‘.

Parameter Description
currencyCode required This is the currency code for the currency you are withdrawing
amount required The amount to be withdrawn
address required The address the funds are withdrawn to
paymentReference optional Withdrawal request for XRP, XMR, XEM, XLM will accept this optional parameter. Max length is 256

getWithdrawalStatus({ currencyCode, withdrawId })

Check the status of a withdrawal πŸ“‘.

Parameter Description
currencyCode required This is the currency code for the currency you have withdrawn
withdrawId required The 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 πŸ“‘.

Parameter Description
currencyCode required Currently, the allowed values here are BTC and ETH
skip optional Skip number of items from the list
limit optional Limit the number of items returned

getWithdrawalHistory({ currencyCode, skip, limit })

Get Withdrawal History records for a given currency πŸ“‘.

Parameter Description
currencyCode required This is the currency code for the currency you want the historical withdrawal records
skip optional Skip number of items from the list
limit optional Limit the number of items returned

getBankAccounts({ currencyCode })

Get a list of bank accounts that are bookmark_tabsed to your VALR account πŸ“‘.

Parameter Description
currencyCode required The currency code for the fiat currency. Supported: ZAR

newFiatWithdrawal({ currencyCode, amount, linkedBankAccountId })

Withdraw cryptocurrency funds to an addressπŸ“‘.

Parameter Description
currencyCode required The currency code for the fiat currency. Supported: ZAR
amount required The amount to be withdrawn
linkedBankAccountId required The 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πŸ“‘.

Parameter Description
currencyPair required Currency pair for which you want to query the order book. Supported currency pairs: Can be BTCZAR, ETHZAR or XRPZAR
full optional true 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πŸ“‘.

Parameter Description
currencyPair required Currency pair for which you want to query the trade history. Supported currency pairs: Can be BTCZAR, ETHZAR or XRPZAR
limit optional Limit 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πŸ“‘.

Parameter Description
currencyPair required Currency pair to get a simple quote for. Any currency pair that supports the "simple" order type, can be specified
payInCurrency required
payAmount required
side required SELL or BUY

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

Submit an order to buy or sell instantly using Simple Buy/SellπŸ“‘.

Parameter Description
currencyPair required Currency pair to get a simple quote for. Any currency pair that supports the "simple" order type, can be specified
payInCurrency required
payAmount required
side required BUY or SELL

getSimpleOrderStatus({ currencyPair, orderId })

Submit an order to buy or sell instantly using Simple Buy/SellπŸ“‘.

Parameter Description
currencyPair required Currency pair of the order for which you are querying the status
orderId required Order 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 πŸ“‘.

Parameter Description
side required BUY or SELL
quantity required Base amount in BTC
price required Price per coin in ZAR
pair required Can be BTCZAR, ETHZAR or XRPZAR
postOnly optional true or false
customerOrderId optional An 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 πŸ“‘.

Parameter Description
side required BUY or SELL
amount required Quote amount for BUY. Base amount for SELL
pair required Can be BTCZAR, ETHZAR or XRPZAR
customerOrderId optional An 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 πŸ“‘.

Parameter Description
side required BUY or SELL
quantity required Amount in Base Currency
price required The Limit Price at which the BUY or SELL order will be placed
pair required Can be BTCZAR, ETHZAR or XRPZAR
timeInForce required Can be GTC, FOK or IOC
stopPrice required The target price for the trade to trigger
type required Can be TAKE_PROFIT_LIMIT or STOP_LOSS_LIMIT
customerOrderId optional An 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 πŸ“‘. 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 πŸ“‘ or customerOrderId πŸ“‘.

Parameter Description
currencyPair required Currency pair
orderId or customerOrderId required orderId 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 πŸ“‘.

getOrderHistory({ skip, limit })

Returns historical orders placed by you πŸ“‘.

Parameter Description
skip optional Skip number of items from the list
limit optional Limit the number of items returned

getOrderHistorySummary({ orderId, customerOrderId })

Returns a more detailed summary about an order queried using the orderId πŸ“‘ or customerOrderId πŸ“‘.

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

Parameter Description
orderId or customerOrderId required orderId 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 πŸ“‘ or customerOrderId πŸ“‘.

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.

Parameter Description
orderId or customerOrderId required orderId 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 πŸ“‘.

Parameter Description
pair required Currency pair
orderId or customerOrderId required orderId 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.

Parameter Description
WebSocketClass optional WebSocketClass that will be used to create the WebSocket. If omitted It defaults to WebSocket.
options optional Object 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