-
Notifications
You must be signed in to change notification settings - Fork 35
/
robinbot.js
executable file
·83 lines (72 loc) · 2.74 KB
/
robinbot.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
#! /usr/local/bin/node
var series = require('run-series');
var n = require('numbro');
var dates = require('./isodate.js');
var ta = require('./technical.js');
var markets = require('./markets.js');
var quotes = require('./quotes.js');
var instruments = require('./instruments.js');
var earnings = require('./earnings.js');
var strategy = require('./strategy.js');
var positions = require('./positions.js');
var rsa = require('./rsa.js');
var account = require('./account.js');
var actions = require('./actions.js');
var orders = require('./orders.js');
var conf = require('./conf.js');
var opt = require('node-getopt').create([
['t' , 'trade' , 'trade mode (default = paper)'],
['s' , 'strategy=ARG' , 'macd, sar, k39, slow_stoch (default k39)'],
['h' , 'help' , 'display this help'],
]).bindHelp().parseSystem();
conf.trade = opt.options.trade;
conf.strategy = (opt.options.strategy) ? opt.options.strategy : 'default';
var clist = conf.list;
console.log("*** ROBINBOT ("+(conf.trade ? "trade" : "paper")+" mode) today: "+
dates.today+" "+(new Date).toLocaleTimeString());
global.quandl = new require('quandl')({ auth_token: conf.quandl_token });
global.Robinhood = require('robinhood')(conf.robinhood_credentials, function(){
if (global.Robinhood.auth_token() === undefined) {
console.error("Robinhood: authentication failed. Please check your credentials in conf.js");
process.exit();
}
var downloads = [
function(cb) {
instruments.download(clist, cb);
}, function(cb) {
positions.download(cb);
}, function(cb) {
account.download(cb);
},function(cb) {
orders.download(cb);
}, function(cb) {
quotes.download(clist, cb);
}, function(cb) {
markets.download(cb);
}, function(cb) {
earnings.download(clist, cb);
}
];
series(downloads, function(err, results) {
if (err) {
console.error("Error:");
console.error(err);
process.exit();
}
rsa.calculate(clist);
if (conf.market_breadth) {
markets.analyse();
}
strategy.run(clist.sort(rsa.sort));
actions.align();
console.log("CASH VALUE: "+account.cash);
console.log("ASSET VALUE: "+actions.asset_value);
actions.distribute_cash();
actions.allocate_stops();
let risk_val = n(actions.stop_risk).format('0.00')
let risk_percent = n(100 * (risk_val / actions.asset_value)).format("0.00");
console.log("RISK: "+risk_val+" ("+risk_percent+"%)");
orders.prepare(actions.sell, actions.buy, actions.stop);
orders.place();
});
});