forked from askmike/gekko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cp.js
90 lines (81 loc) · 2.25 KB
/
cp.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
// functions that emit data to the parent process.
//
// noops if this gekko instance is not a child process!
var _ = require('lodash');
var util = require('./util');
var config = util.getConfig();
var dirs = util.dirs();
var moment = require('moment');
var ENV = util.gekkoEnv();
var message = (type, payload) => {
payload.type = type;
process.send(payload);
}
var cp = {
// string like: '2016-12-03T22:23:00.000Z'
update: latest => message('update', { latest }),
startAt: startAt => message('startAt', { startAt }),
// object like:
//
// {
// start: '2016-12-03T22:23:00.000Z',
// open: 765,
// high: 765,
// low: 765,
// close: 765,
// vwp: 765,
// volume: 0,
// trades: 0
// }
lastCandle: lastCandle => message('lastCandle', { lastCandle }),
firstCandle: firstCandle => message('firstCandle', { firstCandle }),
// object like:
//
// {
// action: 'buy',
// price: 942.80838846,
// portfolio: { asset: 1.07839516, currency: 0, balance: false },
// balance: 1016.7200029226638,
// date: <Moment>
// }
trade: trade => message('trade', { trade }),
// object like:
// {
// currency: 'USDT',
// asset: 'BTC',
// startTime: '2017-03-25 19:41:00',
// endTime: '2017-03-25 20:01:00',
// timespan: '20 minutes',
// market: -0.316304880517734,
// balance: 1016.7200029226638,
// profit: -26.789997197336106,
// relativeProfit: -2.5672966425099304,
// yearlyProfit: '-704041.12634599',
// relativeYearlyProfit: '-67468.55576516',
// startPrice: 945.80000002,
// endPrice: 942.80838846,
// trades: 10,
// startBalance: 1043.5100001199999,
// sharpe: -2.676305165560598
// }
report: report => message('report', { report }),
// object like:
// {
// entryAt: Moment<'2017-03-25 19:41:00'>,
// entryPrice: 10.21315498,
// entryBalance: 98.19707799420277,
// exitAt: Moment<'2017-03-25 19:41:00'>
// exitPrice: 10.22011632,
// exitBalance: 97.9692176,
// duration: 3600000,
// pnl: -0.2278603942027786,
// profit: -0.2320439659276161,
// }
roundtrip: roundtrip => message('roundtrip', { roundtrip }),
}
if(ENV !== 'child-process') {
_.each(cp, (val, key) => {
cp[key] = _.noop;
});
}
module.exports = cp;