Advertisement
Guest User

Untitled

a guest
Sep 17th, 2017
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var request = require('request')
  2. var crypto = require('crypto')
  3. var md5 = require('md5')
  4. var n = require('nonce')()
  5. var config = require('./config')
  6. var base64 = require('base-64')
  7. var utf8 = require('utf8')
  8.  
  9. var nonce = n()
  10. console.log('nonce', nonce)
  11.  
  12. var postParams = {
  13.   "Currency": "NAV"
  14. }
  15.  
  16. console.log('json stringify', JSON.stringify(postParams))
  17.  
  18. var text = md5(JSON.stringify(postParams))
  19. var bytes = utf8.encode(text)
  20. var base64MD5 = base64.encode(bytes)
  21.  
  22. var reqSig = config.cryptopia.apiKey
  23.   + 'POST'
  24.   + config.cryptopia.apiUrl + 'getbalance'
  25.   + nonce
  26.   + base64MD5
  27.  
  28. console.log('reqSig', reqSig)
  29.  
  30. const hmacSig = crypto.createHmac('sha256', base64.decode(config.cryptopia.apiSecret))
  31.                    .update(reqSig)
  32.                    .digest('hex');
  33.  
  34. var auth = config.cryptopia.apiKey + ':' + base64.encode(hmacSig) + ':' + nonce
  35.  
  36. console.log('amx', auth)
  37.  
  38. request.post({
  39.   headers: {
  40.     'Content-Type' : 'application/json; charset=utf-8',
  41.     'Authorization': 'amx ' + auth,
  42.   },
  43.   url: config.cryptopia.apiUrl + 'GetBalance',
  44.   body: JSON.stringify(postParams)
  45. }, function(error, response, body){
  46.   console.log(body)
  47. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement