-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
87 lines (65 loc) · 2.12 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
var fs = require('fs');
var Client = require('coinbase').Client;
// read api key and secret in from text file
var apiData = fs.readFileSync('api.txt').toString().split("\n");
var client = new Client({'apiKey': apiData[0], 'apiSecret': apiData[1]});
// PRICES
var btcPreviousPrice;
var btcCurPrice;
var ltcPreviousPrice;
var ltcCurPrice;
// TRENDS
var btcTrend; // keeps track of how many times in a row the price changes either positively or negatively
var ltcTrend;
var checkPrices = setInterval(function () {
client.getBuyPrice({'currencyPair': 'BTC-USD'}, function(err, obj) {
btcPreviousPrice = btcCurPrice;
btcCurPrice = obj.data.amount;
var change = 0;
// BTC PRICE INCREASE :D
if (btcPreviousPrice < btcCurPrice) {
change = btcCurPrice - btcPreviousPrice;
console.log("BTC Change +" + change);
if (btcTrend > 0) {
btcTrend++;
} else {
btcTrend = 1;
}
// BTC PRICE DECREASE :(
} else if (btcPreviousPrice > btcCurPrice) {
change = btcPreviousPrice - btcCurPrice;
console.log("BTC Change -" + change);
if (btcTrend < 0) {
btcTrend--;
} else {
btcTrend = -1;
}
}
console.log('BTC: $' + btcCurPrice);
});
client.getBuyPrice({'currencyPair': 'LTC-USD'}, function(err, obj) {
ltcPreviousPrice = ltcCurPrice;
ltcCurPrice = obj.data.amount;
var change = 0;
// LTC PRICE INCREASE :D
if (ltcPreviousPrice < ltcCurPrice) {
change = ltcCurPrice - ltcPreviousPrice;
console.log("LTC Change +" + change);
if (ltcTrend > 0) {
ltcTrend++;
} else {
ltcTrend = 1;
}
// LTC PRICE DECREASE :(
} else if (ltcPreviousPrice > ltcCurPrice) {
change = ltcPreviousPrice - ltcCurPrice;
console.log("LTC Change -" + change);
if (ltcTrend < 0) {
ltcTrend--;
} else {
ltcTrend = -1;
}
}
console.log('LTC: $' + ltcCurPrice);
});
}, 5000);