728x90
1. 고팍스 회원가입
2. 계정 로그인 후 API 키 받기
* API 생성시 나타나는 secret key 복사해서 안전한 곳에 저장하기!
계정관리 -> API키 -> 새 API키 등록
3. 개발환경 확인
- python 설치
https://www.python.org/downloads/
- pycharm 설치
https://www.jetbrains.com/ko-kr/pycharm/download/
4. 예제 돌려보기
gopax.github.io/API/index.html#ce7156229f
import base64, hashlib, hmac, json, requests, time
API_KEY = '<입력하세요>'
SECRET = '<입력하세요>'
def call(need_auth, method, path, body_json=None, recv_window=None):
method = method.upper()
if need_auth:
timestamp = str(int(time.time() * 1000))
include_querystring = method == 'GET' and path.startswith('/orders?')
p = path if include_querystring else path.split('?')[0]
msg = 't' + timestamp + method + p
msg += (str(recv_window) if recv_window else '') + (json.dumps(body_json) if body_json else '')
raw_secret = base64.b64decode(SECRET)
raw_signature = hmac.new(raw_secret, str(msg).encode('utf-8'), hashlib.sha512).digest()
signature = base64.b64encode(raw_signature)
headers = {'api-key': API_KEY, 'timestamp': timestamp, 'signature': signature}
if recv_window:
headers['receive-window'] = str(recv_window)
else:
headers = {}
req_func = {'GET': requests.get, 'POST': requests.post, 'DELETE': requests.delete}[method]
resp = req_func(url='https://api.gopax.co.kr' + path, headers=headers, json=body_json)
return {
'statusCode': resp.status_code,
'body': resp.json(),
'header': dict(resp.headers),
}
post_orders_req_body = {
'side': 'buy', 'type': 'limit', 'amount': 1,
'price': 10000, 'tradingPairName': 'BTC-KRW'
}
print(call(True, 'POST', '/orders', post_orders_req_body, 200))
print(call(True, 'GET', '/orders'))
print(call(True, 'GET', '/orders?includePast=true'))
print(call(True, 'GET', '/trades?limit=1'))
print(call(False, 'GET', '/trading-pairs/BTC-KRW/book?level=1'))
성공!!
728x90
댓글