Skip to content

Instantly share code, notes, and snippets.

@KolevDarko
Created February 13, 2019 09:34
Show Gist options
  • Save KolevDarko/cebf4b6b0782e47011d0909e88185d42 to your computer and use it in GitHub Desktop.
Save KolevDarko/cebf4b6b0782e47011d0909e88185d42 to your computer and use it in GitHub Desktop.
/**
* npm install -g crypto-js
* npm install -g request
*/
var crypto = require('crypto-js');
var public_key = 'enter your public key';
var secret_key = 'enter your secret key';
var timestamp = Math.floor(Date.now() / 1000);
var payload = timestamp + '.' + public_key;
var hash = crypto.HmacSHA256(payload, secret_key);
var hex_hash = crypto.enc.Hex.stringify(hash);
var signature = payload + "." + hex_hash;
var ticker_btcusd_url = 'https://apiv2.bitcoinaverage.com/indices/global/ticker/BTCUSD';
var request = require('request');
var options = {
url: ticker_btcusd_url,
headers: {
'X-Signature': signature
}
};
function callback(error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
}
request(options, callback);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment