valr-api-node

VALR exchange API client for REST and WebSocket

dutu/valr-api-node https://www.npmjs.com/package/valr-api-node
starsStars 2
forksForks 0
watchersWatchers 2
current-versionCurrent version
total-releasesTotal releases 0
open_issues_countOpen issues 0
dateFirst release -
dateLatest release -
updateLast update 2020-12-06

valr-api-node

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

Clients for both the 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) => {
}

REST API

All methods return promises.

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 📑.

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 📑.

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.

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: BTCZAR
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: BTCZAR
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 BTCZAR
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 BTCZAR
customerOrderId optional An unique Id across all open orders for a given account. Alphanumeric value with no special chars, limit of 50 characters

getOrderStatus({ orderId, customerOrderId })

Returns the status of an order that was placed on the Exchange queried using the orderId 📑.

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 📑.

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 📑.

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.

newAccountWebSocket()

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

newTradeWebSocket()

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

Message Feeds

See VALR Websocket API documentation

License

MIT