Skip to content
This repository has been archived by the owner on Feb 16, 2020. It is now read-only.

Commit

Permalink
if talib >=1.0.3 use new callback, else old
Browse files Browse the repository at this point in the history
  • Loading branch information
metachris authored and askmike committed Aug 7, 2017
1 parent de44ca9 commit 23f9f1d
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions core/talib.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
var talib = require("talib");
var semver = require("semver");
var _ = require('lodash');

var talibError = 'Gekko was unable to configure talib indicator:\n\t';
var talibGTEv103 = semver.gte(talib.version, '1.0.3');

// Wrapper that executes a talib indicator
var execute = function(callback, params) {
return talib.execute(
params,
function(err, result) {
if(err)
return callback(err);

callback(null, result.result);
}
);
// talib callback style since talib-v1.0.3
var talibCallback = function(err, result) {
if(err) return callback(err);
callback(null, result.result);
};

// talib legacy callback style before talib-v1.0.3
var talibLegacyCallback = function(result) {
var error = result.error;
talibCallback.apply(this, [error, result]);
};

return talib.execute(params, talibGTEv103 ? talibCallback : talibLegacyCallback);
}

// Helper that makes sure all required parameters
Expand Down

0 comments on commit 23f9f1d

Please sign in to comment.