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.
See detailed Changelog
npm install --save valr-api-node
import Valr from 'valr-api-node'
const valr = new VALR({ key, secret })
valr.getMarketSummary({ currencyPair: 'BTCZAR' })
.then(console.log)
.catch(console.error)
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) => {
}
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.
All methods return promises.
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
Get a list of currencies supported by VALR π.
Get all the order types supported for all currency pairs π.
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 |
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 |
Get the server time π.
Get the current status of VALR π.
The following APIs allow you to query your account balances and full transaction history. These APIs are protected and will require authentication.
Returns the current API Key's information and permissions π.
Returns the list of all wallets with their respective balancesπ.
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 |
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 |
Access your wallets programmatically.
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
These API calls can be used to receive the market data.
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 |
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 |
Make use of our powerful Simple Buy/Sell API to instantly buy and sell currencies.
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 |
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 |
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.
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 |
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 |
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 |
Create a batch of multiple orders, or cancel orders, in a single request π. See VALR API documentation for applicable parameters.
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. |
Returns all open orders for your account π.
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 |
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. |
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. |
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. |
The methods return a WebSocket object. The WebSocket class that is used to create the websocket can be specified as parameter.
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 |
Establishes a WebSocket connection to receive streaming updates about Trade data.
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.