-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpsychsignal.js
47 lines (35 loc) · 1.23 KB
/
psychsignal.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
var request = require('request'),
_ = require('underscore'),
_s = require('underscore.string');
module.exports = function get_sentiments(symbol, startDate, endDate, fn) {
console.log("load sentiments");
var url = _s.sprintf("https://psychsignal.com/api/sentiments?api_key=41910b4ec81feab42407b3270cb629d0&symbol=%s&from=%s&to=%s&period=d", symbol, startDate, endDate);
console.log(url);
request({
url: url,
json: true
}, function(error, response, contents) {
if (!error && response.statusCode == 200) {
var data = {
"symbol": contents.symbol,
"bullish": [],
"bearish": []
};
var bullish = contents.bullish;
bullish.forEach(function(signal) {
data.bullish.push({
date: new Date(signal[0]),
value: signal[1]
});
});
var bearish = contents.bearish;
bearish.forEach(function(signal) {
data.bearish.push({
date: new Date(signal[0]),
value: signal[1]
});
});
return fn(null, data);
}
});
};