forked from jesse-ai/jesse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
79 lines (66 loc) · 2.6 KB
/
index.ts
File metadata and controls
79 lines (66 loc) · 2.6 KB
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
// register donenv to load config values
require('dotenv').config();
import _ from 'lodash';
import readline from 'readline';
import config from './config';
import jesse from './core/models/Jesse';
import candleSet from './core/services/CandleLoader';
import Notifier from './core/services/Notifier';
import store, { actions } from './core/store';
import Dashboard from './core/services/Dashboard';
let executeExit = _.once(function() {
if (config.notifications.events.liveTradeStopped) {
Notifier.send(`liveTrade stopped`);
}
store.dispatch(actions.logWarning('Saving before exit...'));
jesse.strategy.end();
jesse.saveLogs().then(() => {
process.exit();
});
});
// setup Sentry
if (config.sentry.enable) {
const Sentry = require('@sentry/node');
Sentry.init({ dsn: config.sentry.DSN });
}
// run the main application
switch (config.app.tradingMode.toLowerCase()) {
case 'backtest':
jesse.backTest(candleSet);
break;
case 'fitness':
jesse.fitness(candleSet);
break;
case 'livetrade':
// TODO: make a check to see if there's been a session
// running (like if there are any active orders and
// stuff). if so, set the sessionID to resume.
readline.emitKeypressEvents(process.stdin);
process.stdin.setRawMode(true);
process.stdin.on('keypress', (str, key) => {
if (key.ctrl && key.name === 'c') {
executeExit();
} else if (key.name === 'h') {
config.dashboard.items.guide = !config.dashboard.items.guide;
} else if (key.name === 'i') {
config.dashboard.items.info = !config.dashboard.items.info;
} else if (key.name === 'p') {
config.dashboard.items.positions = !config.dashboard.items.positions;
} else if (key.name === 'c') {
config.dashboard.items.candles = !config.dashboard.items.candles;
} else if (key.name === 'w') {
config.dashboard.items.warnings = !config.dashboard.items.warnings;
} else if (key.name === 'e') {
config.dashboard.items.errors = !config.dashboard.items.errors;
} else if (key.name === 'o') {
config.dashboard.items.orders = !config.dashboard.items.orders;
} else if (key.name === 't') {
config.dashboard.items.trades = !config.dashboard.items.trades;
}
Dashboard.liveTrade();
});
jesse.liveTrade();
break;
default:
throw new Error('Selected mode is not supported.');
}