-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpublicApi.js
More file actions
30 lines (25 loc) · 885 Bytes
/
Copy pathpublicApi.js
File metadata and controls
30 lines (25 loc) · 885 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const request = require('request');
const ApiHelper = require('./apiHelper');
const create = (debug = false) => {
const PUBLIC_API_URL = 'https://poloniex.com/public';
const apiHelper = ApiHelper.create('', '');
function makeRequest(command, opts) {
const querystring = apiHelper.createQueryString(command, opts);
const req = `${PUBLIC_API_URL}?${querystring}`;
debug && console.log('requesting with options', req);
return new Promise((resolve, reject) => {
request.get(req, (err, res, body) => {
if (err) {
reject(err);
return;
}
resolve(res);
});
});
}
return {
returnTicker: () => makeRequest('returnTicker', {}),
returnChartData: ({ currencyPair, start, end, period }) => makeRequest('returnChartData', { currencyPair, start, end, period }),
};
};
module.exports.create = create;