-
Notifications
You must be signed in to change notification settings - Fork 7
/
sell.js
55 lines (48 loc) · 1.49 KB
/
sell.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
const kraken = require('./index')
const { MIN_QUANTITIES } = require('./consts');
module.exports = async (req, res, kraken) => {
/**
* Set up orders to be executed.
* Base - currency to be bought.
* Quote - currency to be used for buying.
* Volume - volume to be bought in quote currency i.e. 10 euros.
*/
const orders = [
{ base: "XMR", quote: "EUR", volume: 5 },
{ base: "BTC", quote: "EUR", volume: 5 },
{ base: "ETH", quote: "EUR", volume: 5 },
{ base: "XTZ", quote: "EUR", volume: 5 }
];
for (const order of orders) {
const { base, quote, volume } = order;
const pair = `${base}${quote}`;
const ticker = await kraken.api("Ticker", { pair });
/*
* Pair naming is inconsistent in Kraken and thus provided
* pair name may differ from that shown in resulting object.
*/
const tickerPair = Object.keys(ticker.result)[0];
const price = ticker.result[tickerPair].c[0];
/*
* Volume to be bought must be at the minimum the
* volume that Kraken allows to buy (differs based on currency).
*/
let finalVolume = volume / price;
if (finalVolume < MIN_QUANTITIES[base]) {
finalVolume = MIN_QUANTITIES[base];
}
console.log("AddOrder", {
pair: tickerPair,
type: "sell",
ordertype: "market",
volume: finalVolume
})
await kraken.api("AddOrder", {
pair: tickerPair,
type: "sell",
ordertype: "market",
volume: finalVolume
});
}
res.status(200);
}