-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathshapeshift.js
63 lines (60 loc) · 1.69 KB
/
shapeshift.js
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const request = require('superagent');
/**
* @path [rates, exchanges, assets]
* https://docs.shapeshift.io/
*/
function shapeshift(req, cb) {
// req = [shapeshift, method, arg1, arg2]
let url = '';
// POST
if (req[1] === 'shift' || req[1] === 'sendamount') {
url = `https://shapeshift.io/${req[1]}`;
let requestObject = {
withdrawal: req[2],
pair: req[3],
};
if (req[1] === 'sendamount') {
requestObject = Object.assign(requestObject, { depositAmount: req[4] });
}
// JWT token is hard coded. Should require login first to use these.
request
.post(url)
.send(requestObject)
.set({
Accept: 'application/json',
Authorization: 'Bearer 9uvGiMgjmCMPt9ZoL6jXw3mznHqYQ1dwYXhd5EoQbxnN',
})
.end((err, res) => {
if (err) {
console.log('RES', res);
console.log('ERR', err);
cb(err, res);
} else {
console.log('RES.BODY', res.body);
let message =
req[1] === 'shift'
? `Conduit created. Please send ${res.body.depositType} to ${
res.body.deposit
}`
: `Conduit created. Please send ${
res.body.success.depositAmount
} to ${res.body.success.deposit}`;
cb(null, message);
}
});
} else {
// GET
if (req[3]) {
url = `shapeshift.io/${req[1]}/${req[2]}/${req[3]}`;
} else if (req[2]) {
url = `shapeshift.io/${req[1]}/${req[2]}`;
} else if (req[1]) {
url = `shapeshift.io/${req[1]}`;
}
request
.get(url)
.set('Accept', 'application/json')
.end(cb);
}
}
module.exports = shapeshift;