-
Notifications
You must be signed in to change notification settings - Fork 1
/
set.ts
85 lines (77 loc) · 2.57 KB
/
set.ts
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
import { Command, flags } from '@oclif/command';
import * as TradeService from '../../services/trades.service';
import * as UsersService from '../../services/users.service';
enum BaseFlags {
HELP = 'help',
SYMBOL = 'symbol',
DATE = 'date',
VOLUME = 'volume',
OPEN = 'open',
HIGH = 'high',
LOW = 'low',
CLOSE = 'close',
ADJCLOSE = 'adj_close'
}
const PriceFlags = {
...BaseFlags
};
type PriceFlags = BaseFlags;
export default class Price extends Command {
static description = 'set the daily values of a single stock';
static flags = {
[PriceFlags.HELP]: flags.help({ char: 'h' }),
[PriceFlags.SYMBOL]: flags.string({
char: 's',
description: 'name/ticker/symbol of stock',
required: true
}),
[PriceFlags.DATE]: flags.string({
char: 'd',
description: `full date of interest in yyyy-mm-dd format.`,
required: true
}),
[PriceFlags.VOLUME]: flags.string({
char: 'v',
description: `volume of stocks on the day.`,
required: true
}),
[PriceFlags.OPEN]: flags.string({
char: 'o',
description: `opening value of the stock on the day.`,
required: true
}),
[PriceFlags.HIGH]: flags.string({
char: 'u',
description: `highest value of the stock on the day.`,
required: true
}),
[PriceFlags.LOW]: flags.string({
char: 'l',
description: `lowest value of the stock on the day.`,
required: true
}),
[PriceFlags.CLOSE]: flags.string({
char: 'c',
description: `closing value of the stock on the day.`,
required: true
}),
[PriceFlags.ADJCLOSE]: flags.string({
char: 'a',
description: `adjusted cloding value of the stock on the day.`,
required: true
}),
};
async run() {
const { args, flags } = this.parse(Price);
if(!await UsersService.checkUserLoggedIn()) {
this.error('please login using user command first', {suggestions: ['user -h']});
}
if(!await UsersService.getCurrentUserPriv()) {
this.error('Current user does not have write permissions on database');
}
const {results: rows, error: e} = await TradeService.addNewTickerHistoryEntry(flags[PriceFlags.SYMBOL],flags[PriceFlags.DATE],flags[PriceFlags.VOLUME],flags[PriceFlags.OPEN],flags[PriceFlags.CLOSE],flags[PriceFlags.HIGH],flags[PriceFlags.LOW],flags[PriceFlags.ADJCLOSE]);
if (e) {
this.error('Attempted to add new trade price for a stock that does not exist. If you are sure this stock name is not a typo then add the ipo information for this new stock', {suggestions: ['ipo:set -h']});
}
}
}