Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions kraken.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,26 @@ const getMessageSignature = (path, request, secret, nonce) => {
};

// Send an API request
const rawRequest = async (url, headers, data, timeout) => {
const rawRequest = async (url, headers, data, timeout, isPublic) => {
// Set custom User-Agent string
headers['User-Agent'] = 'Kraken Javascript API Client';

const options = { headers, timeout };

Object.assign(options, {
method : 'POST',
body : qs.stringify(data),
});
const queryString = qs.stringify(data);

if (isPublic){
url = `${url}?${queryString}`;
Object.assign(options, {
method : 'GET'
});
}
else {
Object.assign(options, {
method : 'POST',
body : queryString
});
}
const { body } = await got(url, options);
const response = JSON.parse(body);

Expand Down Expand Up @@ -118,7 +127,7 @@ class KrakenClient {

const path = '/' + this.config.version + '/public/' + method;
const url = this.config.url + path;
const response = rawRequest(url, {}, params, this.config.timeout);
const response = rawRequest(url, {}, params, this.config.timeout, true);

if(typeof callback === 'function') {
response
Expand Down Expand Up @@ -168,7 +177,7 @@ class KrakenClient {
'API-Sign' : signature,
};

const response = rawRequest(url, headers, params, this.config.timeout);
const response = rawRequest(url, headers, params, this.config.timeout, false);

if(typeof callback === 'function') {
response
Expand Down