Skip to content

Commit 2197bfe

Browse files
cmrocheaskmike
authored andcommitted
Automated load of talib and tulind if available locally
1 parent fda257a commit 2197bfe

File tree

7 files changed

+25
-74
lines changed

7 files changed

+25
-74
lines changed

core/talib.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
var talib = require("talib");
21
var semver = require("semver");
32
var _ = require('lodash');
43

4+
// validate that talib is installed, if not we'll throw an excepion which will
5+
// prevent further loading or out outside this module
6+
try {
7+
var talib = require("talib");
8+
} catch (e) {
9+
module.exports = null;
10+
return;
11+
}
12+
513
var talibError = 'Gekko was unable to configure talib indicator:\n\t';
614
var talibGTEv103 = semver.gte(talib.version, '1.0.3');
715

core/tulind.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
var tulind = require("tulind");
21
var semver = require("semver");
32
var _ = require('lodash');
43

4+
// validate that talib is installed, if not we'll throw an excepion which will
5+
// prevent further loading or out outside this module
6+
try {
7+
var tulind = require("tulind");
8+
} catch (e) {
9+
module.exports = null;
10+
return;
11+
}
12+
513
var tulindError = 'Gekko was unable to configure Tulip Indicators:\n\t';
614

715
// Wrapper that executes a tulip indicator

plugins/tradingAdvisor/baseTradingMethod.js

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,44 +9,17 @@ var ENV = util.gekkoEnv();
99
var mode = util.gekkoMode();
1010
var startTime = util.getStartTime();
1111

12-
if(config.tradingAdvisor.talib.enabled) {
13-
// verify talib is installed properly
14-
var pluginHelper = require(dirs.core + 'pluginUtil');
15-
var pluginMock = {
16-
slug: 'tradingAdvisor',
17-
dependencies: [{
18-
module: 'talib',
19-
version: config.tradingAdvisor.talib.version
20-
}]
21-
};
22-
23-
var cannotLoad = pluginHelper.cannotLoad(pluginMock);
24-
if(cannotLoad)
25-
util.die(cannotLoad);
26-
27-
var talib = require(dirs.core + 'talib');
12+
var talib = require(dirs.core + 'talib');
13+
if(talib == null) {
14+
log.warn('TALIB indicators could not be loaded, they will be unavailable.');
2815
}
2916

30-
if(config.tradingAdvisor.tulind.enabled) {
31-
// verify talib is installed properly
32-
var pluginHelper = require(dirs.core + 'pluginUtil');
33-
var pluginMock = {
34-
slug: 'tradingAdvisor',
35-
dependencies: [{
36-
module: 'tulind',
37-
version: config.tradingAdvisor.tulind.version
38-
}]
39-
};
40-
41-
var cannotLoad = pluginHelper.cannotLoad(pluginMock);
42-
if(cannotLoad)
43-
util.die(cannotLoad);
44-
45-
var tulind = require(dirs.core + 'tulind');
17+
var tulind = require(dirs.core + 'tulind');
18+
if(tulind == null) {
19+
log.warn('TULIP indicators could not be loaded, they will be unavailable.');
4620
}
4721

4822
var indicatorsPath = dirs.methods + 'indicators/';
49-
5023
var indicatorFiles = fs.readdirSync(indicatorsPath);
5124
var Indicators = {};
5225

sample-config.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,7 @@ config.tradingAdvisor = {
3535
method: 'MACD',
3636
candleSize: 1,
3737
historySize: 3,
38-
adapter: 'sqlite',
39-
talib: {
40-
enabled: false,
41-
version: '1.0.2'
42-
},
43-
tulind: {
44-
enabled: false,
45-
version: '0.8.7'
46-
}
38+
adapter: 'sqlite'
4739
}
4840

4941
// Exponential Moving Averages settings:

web/routes/baseConfig.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@ config.debug = true;
1414
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1515

1616
config.tradingAdvisor = {
17-
talib: {
18-
enabled: require('../supportsTalib'),
19-
version: '1.0.2'
20-
},
21-
tulind: {
22-
enabled: require('../supportsTulip'),
23-
version: '0.8.7'
24-
}
2517
}
2618

2719
config.candleWriter = {

web/supportsTalib.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

web/supportsTulip.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)