forked from hustcer/star
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstar.js
executable file
·144 lines (115 loc) · 5.37 KB
/
star.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#! /usr/bin/env node --harmony
/**
* @author hustcer
* @license MIT
* @copyright TraceInvest.com
* @create 05/18/2015
*/
"use strict";
let _ = require('lodash'),
colors = require('colors'),
Promise = require('bluebird'),
cmd = require('commander');
const pkg = require('./package.json');
let conf = require('./lib/conf.js').conf;
let action = null; // cmd action
/**
* Available colors are:
* bold, italic, underline, inverse, yellow, cyan, white,
* green, red, grey, blue, rainbow, zebra, random, magenta,
*/
const COLOR_THEME = {
error : 'red',
info : 'blue',
data : 'grey',
header : 'blue',
warn : 'yellow',
em : 'magenta'
};
colors.setTheme(COLOR_THEME);
cmd
.version(pkg.version)
.usage('[options]' + ' OR'.em + ' star code1,code2,code3...,codeN')
.description('Star is a command line tool for STock Analysis and Research.')
.option('-a, --all' , 'display all stocks.')
.option('-o, --hold' , 'display all held stocks.')
.option('-C, --cal' , 'display finance calendar of the future month.')
.option('-I, --ignore' , 'display all ignored stocks.')
.option('-i, --insider <c>' , 'display insider trading records of specified stocks.')
.option('-w, --watch [c1...]', 'watch specified stocks or watch all the stocks in watch list.')
.option('-r, --reverse' , 'sort stocks in ascending order according to designated field.')
.option('-l, --limit <n>' , 'set total display limit of current page.', parseInt)
.option('-p, --page <n>' , 'specify the page index to display.', parseInt)
.option('-d, --data <data>' , 'specify data provider, should be one of "sina" or "tencent".')
.option('-f, --file <file>' , 'specify the symbol file path.')
.option('--from <2014/06/01>', 'specify the beginning date of insider tradings.')
.option('--to <2015/07/09>' , 'specify the ending date of insider tradings.')
.option('--span <3m>' , 'specify the month span of insider tradings ahead of today, should be 1m~24m.')
.option('-L, --lte <pct> ' , 'filter the symbols whose upside potential is lower than or equal to the specified percentage.', parseInt)
.option('-G, --gte <pct> ' , 'filter the symbols whose upside potential is greater than or equal to the specified percentage.', parseInt)
.option('-U, --under <star>' , 'filter the symbols whose star is under or equal to the specified star value.', parseInt)
.option('-A, --above <star>' , 'filter the symbols whose star is above or equal to the specified star value.', parseInt)
.option('-g, --grep <kw> ' , 'specify the keyword to grep in name or comment, multiple keywords should be separated by ",".')
.option('-e, --exclude <pre>', 'exclude stocks whose code number begin with: 300,600,002 or 000, etc. multiple prefixs can be\n' + ' '.repeat(20) +
' used and should be separated by "," or ",". ')
.option('-c, --contain <pre>', 'display stocks whose code number begin with: 300,600,002 or 000, etc. multiple prefixs can be\n' + ' '.repeat(20) +
' used and should be separated by "," or ",". ')
.option('-s, --sort <sort>' , 'specify sorting field, could be sorted by: code/star/price/targetp/incp/capacity/pe/pb to sort\n' + ' '.repeat(20) +
' stocks by code, star, price, price to target percent, price increase percent, capacity, PE and\n' + ' '.repeat(20) +
' PB separately. and sort by capacity/pe/pb only works while using tencent data source.')
.parse(process.argv);
let actions = {
'WATCH' : function(){
let Watch = require('./lib/watch.js').Watch;
Watch.doWatch(cmd.watch);
},
'CAL' : function(){
let Cal = require('./lib/cal.js').Cal;
Cal.showCal();
},
'INSIDER': function(){
let async = require('async');
let Insider = require('./lib/insider.js').Insider;
let query = cmd.insider.replace(/,/g, ',');
let symbols = query.split(',');
if(symbols.length > 20){
console.error('The queried symbols should be no more than 20 one time.'.error);
return false;
}
async.eachSeries(symbols, function(c, callback){
Insider.queryInsider(c, callback);
}, function(){
console.log('ALL DONE!');
});
},
'QUERY' : function(){
let Query = require('./lib/query.js').Query;
Query.doQuery(cmd.args[0]);
},
'TRACE' : function(){
let Trace = require('./lib/trace.js').Trace;
let symbols = Trace.getFilteredSymbols();
let symList = _.chunk(symbols, conf.chunkSize);
Promise
.resolve(symList)
.each(syms => Trace.querySymbols(syms))
.then(() => Trace.printResults())
.then(() => Trace.printSummary());
}
};
let doCmd = function() {
// 'TRACE' is the default action
action = 'TRACE';
if(cmd.watch) { action = 'WATCH'; }
if(cmd.insider){ action = 'INSIDER'; }
if(cmd.cal) { action = 'CAL'; }
if(cmd.args.length === 1 ){
action = 'QUERY';
}else if (cmd.args.length > 1) {
console.error('Input error, please try again, or run "star -h" for more help.'.error);
return false;
}
actions[action]();
};
// Get the Job Done!
doCmd();