valr-api-client

1.1.3 • Public • Published

valr-api-client

VALR Api REST and web-socket client

See VALR API documentation

valr-api-client is a node.js client for calling the VALR(https://www.valr.com) REST and WebSocket API.

Examples

e.g. To call a rest end-point

const { ValrV1RestClient, ValrV1WsClient } = require('valr-api-client')

// N.B. keep these safe.  don't commit to source control etc...
var apiKey = '<your-api-key>';
var apiSecret = '<your-api-secret>';

const  valrClient = new ValrV1RestClient({ apiKey, apiSecret })
valrClient
    .account
    .getBalances()
        .then((balance) => console.log(balance))

e.g. To subscribe to the trade web socket events

var valrWsTradeClient = new ValrV1WsClient(ValrV1WsClient.WSPATHS.TRADE, { apiKey, apiSecret })
valrWsTradeClient.connect();

valrWsTradeClient.on('connected', () => console.log('TRADE:', 'connected'));

valrWsTradeClient.on('message', (data) => {
    if (data.type == 'AUTHENTICATED') {
        valrWsTradeClient.subscribe(ValrV1WsClient.TRADE_SUBSCRIPTIONS.AGGREGATED_ORDERBOOK_UPDATE, 'BTCZAR');
    } else if (data.type == ValrV1WsClient.TRADE_SUBSCRIPTIONS.AGGREGATED_ORDERBOOK_UPDATE) {
        console.log('TRADE OrderBook Updated:', util.inspect(data, { depth: 99, colors: true }));
    } else {
        console.log(data);
    }
});

valrWsTradeClient.on('error', (err) => console.log('TRADE:', err));
valrWsTradeClient.on('close', (code, reason) => console.log('TRADE:', code, reason));
valrWsTradeClient.on('disconnected', () => console.log('TRADE:', 'disconnected'));

Dependents (0)

Package Sidebar

Install

npm i valr-api-client

Weekly Downloads

11

Version

1.1.3

License

MIT

Unpacked Size

26.6 kB

Total Files

11

Last publish

Collaborators

  • chris.tsim