Skip to content

Instantly share code, notes, and snippets.

@igotit-anything
Created March 10, 2020 11:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igotit-anything/70b0aa30a727f4e13972fbae2d9a795a to your computer and use it in GitHub Desktop.
Save igotit-anything/70b0aa30a727f4e13972fbae2d9a795a to your computer and use it in GitHub Desktop.
//
// 잔액 조회하기
//
var crypto = require('crypto');
var request = require('request');
// 발급받은 api키와 시크릿키를 입력한다
var apikey = 'akdhfafheur';
var secret = 'ausdufasffdkljieurueadfjklj';
// nonce값 생성
var nonce = Date.now() * 1000;
var method = 'GET';
var requestPath = '/balances';
// 필수 정보를 연결하여 prehash 문자열을 생성함
var what = nonce + method + requestPath;
// base64로 secret을 디코딩함
var key = Buffer(secret, 'base64');
// secret으로 sha512 hmac을 생성함
var hmac = crypto.createHmac('sha512', key);
// hmac으로 필수 메시지에 서명하고
// 그 결과물을 base64로 인코딩함
var sign = hmac.update(what).digest('base64');
var host = 'api.gopax.co.kr';
var options = {
method,
json: true,
url: `https://${host}${requestPath}`,
headers: {
'API-KEY': apikey,
Signature: sign,
Nonce: nonce,
},
strictSSL: false,
};
request(options, (err, response, b) => {
if (err) {
console.log('err:', err);
return;
}
console.log(b);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment