Public 데이터가 아닌 HTTP API나 WebSocket API를 사용하기 위해선 먼저 인증을 통해 API 토큰을 받아와야 합니다.
API 레퍼런스는 GET /token에서 확인할 수 있습니다.
Authorization API는 다른 HTTP API와 주소가 다릅니다.
기본 엔드포인트: https://accounts.probit.com/token
아래는 Authorization API를 이용해 토큰을 가져오는 간단한 JavaScript 예시입니다.
const getToken = async () => {
const authHeader = 'Basic ' + Base64.encode(`${apiClientId}:${apiClientSecret}`);
const resp = await fetch('https://accounts.probit.com/token', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': authHeader
},
body: JSON.stringify({
grant_type: 'client_credentials'
})
});
if (!resp.ok) {
throw new Error(resp.statusText);
}
return resp.json();
};
아래는 위에서 정의한 getToken
함수를 이용하여 인증이 필요한 HTTP API를 호출하는 예시입니다.
const getBalance = async () => {
const token = (await getToken()).access_token;
const resp = await fetch('https://api.probit.com/api/exchange/v1/balance', {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + token
}
});
if (!resp.ok) {
throw new Error(resp.statusText);
}
return resp.json();
};
getBalance().then((balances) => console.log(balances));
Updated 4 months ago