Created
March 11, 2020 12:20
-
-
Save igotit-anything/28934a5020257f7c57f90518271f9396 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 잔액 조회하기 | |
# | |
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