forked from askmike/gekko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremote.js
125 lines (118 loc) · 3.08 KB
/
remote.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
const http = require('http');
function callBacktestApi(strategiConfig) {
var body = JSON.stringify(strategiConfig);
var options = {
host: 'localhost',
port: 3000,
path: '/api/backtest',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(body)
}
};
return new Promise((resolve, reject) => {
const postRequest = http.request(options, (response) => {
let str = '';
response.on('data', chunk => str += chunk);
response.on('end', () => resolve(JSON.parse(str)));
});
postRequest.write(body);
postRequest.end();
});
}
function createMacdStragegy(params) {
return {
gekkoConfig: {
watch: {
exchange: params.exchange || 'poloniex',
currency: params.currency || 'USDT',
asset: params.asset || 'ETH',
},
paperTrader: {
fee: 0.25,
slippage: 0.05,
riskFreeReturn: 2,
simulationBalance: {
asset: 0,
currency: 3000
},
reportRoundtrips: true,
enabled: true
},
backtest: {
daterange: {
from: '2017-04-01 00:00:00',
to: '2017-07-01 00:00:00',
}
},
valid: true,
'MACD': {
short: params.short,
long: params.long,
signal: params.signal,
thresholds: {
down: params.down,
up: params.up,
persistence: params.persistence,
}
},
'tradingAdvisor': {
enabled: true,
method: 'MACD',
candleSize: params.candleSize,
historySize: params.historySize,
},
performanceAnalyzer: {
enabled: true,
riskFreeReturn: 5
}
},
data: {
candleProps: [ 'close', 'start' ],
indicatorResults: true,
report: true,
roundtrips: true,
trades: true
}
}
}
const backtestStrategy1 = createMacdStragegy({
long: 22,
short: 18,
signal: 12,
down: '-0.025',
up: '0.025',
persistence: 1,
candleSize: 60,
historySize: 10,
});
const backtestStrategy2 = createMacdStragegy({
long: 1122,
short: 1118,
signal: 1112,
down: '-0.025',
up: '0.025',
persistence: 1,
candleSize: 60,
historySize: 10,
});
const backtestStrategy3 = createMacdStragegy({
long: 2222,
short: 2218,
signal: 2212,
down: '-0.025',
up: '0.025',
persistence: 1,
candleSize: 60,
historySize: 10,
});
const test1Promise = callBacktestApi(backtestStrategy1);
const test2Promise = callBacktestApi(backtestStrategy2);
const test3Promise = callBacktestApi(backtestStrategy3);
Promise.all([test1Promise, test2Promise, test3Promise]).then((results) => {
console.log(results);
console.log(`test1: Trades: ${results[0].trades.length} Balance: ${results[0].report.balance}`);
console.log(`test2: Trades: ${results[1].trades.length} Balance: ${results[1].report.balance}`);
console.log(`test3: Trades: ${results[2].trades.length} Balance: ${results[2].report.balance}`);
});