-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
53 lines (44 loc) · 1.13 KB
/
index.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
const kraken = require('./lib/kraken');
let sell = false;
let balance = 0;
let priceSell = 0;
const tradingPair = 'XXBTZEUR';
const lowPrice = 1117;
const highPrice = 1123;
const minimumBalance = 24;
function startTrade() {
kraken.balance()
.then(balanceData => {
console.log(balanceData.result.ZEUR);
balance = balanceData.result.ZEUR;
return kraken.ticker({ pair: tradingPair });
})
.then(tickerData => {
console.log(tickerData.result.XXBTZEUR.b[0]);
priceSell = tickerData.result.XXBTZEUR.b[0];
if (balance > minimumBalance && !sell && priceSell < lowPrice) {
return kraken.buy({
pair: tradingPair,
volume: 0.008,
});
} else {
return false;
}
})
.then(buyData => {
if(!buyData) return false;
console.log(buyData.result);
sell = true;
return sell({
pair: tradingPair,
price: highPrice,
volume: 0.008,
}).then(sellData => {
console.log(sellData.result);
sell = false;
});
})
.catch(console.error);
}
setTimeout(startTrade, 4000);
startTrade();