Skip to content

Instantly share code, notes, and snippets.

@igotit-anything
Created March 11, 2020 12:20
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/28934a5020257f7c57f90518271f9396 to your computer and use it in GitHub Desktop.
Save igotit-anything/28934a5020257f7c57f90518271f9396 to your computer and use it in GitHub Desktop.
#
# 잔액 조회하기
#
import time, base64, hmac, hashlib, requests, json
# 발급받은 api키와 시크릿키를 입력한다
apikey = 'ashdflashdfkh.....'
secret = 'as;dlflaskdjfjaskldfjlasjflj.....'
# nonce값 생성
nonce = str(time.time())
method = 'GET'
request_path = '/balances'
#필수 정보를 연결하여 prehash 문자열을 생성함
what = nonce + method + request_path
#base64로 secret을 디코딩함
key = base64.b64decode(secret)
#hmac으로 필수 메시지에 서명하고
signature = hmac.new(key, str(what).encode('utf-8'), hashlib.sha512)
#그 결과물을 base64로 인코딩함
signature_b64 = base64.b64encode(signature.digest())
# HTML 소스 가져오기
def HTMLsouceGet(p):
print (p.text)
custom_headers = {
'API-Key': apikey,
'Signature': signature_b64,
'Nonce': nonce
}
def main():
# method = get
req = requests.get(url = 'https://api.gopax.co.kr' + request_path, headers = custom_headers)
if req.ok:
HTMLsouceGet(req)
else:
print ('요청 에러')
HTMLsouceGet(req)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment