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

Commit

Permalink
Merge pull request #1451 from askmike/develop
Browse files Browse the repository at this point in the history
0.5.11
  • Loading branch information
askmike committed Dec 11, 2017
2 parents c86ce48 + e0d944a commit a80879d
Show file tree
Hide file tree
Showing 48 changed files with 1,706 additions and 349 deletions.
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"trailingComma": "es5",
"singleQuote": true
}
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
language: node_js
node_js:
- "6.6.0"
- "8.0.0"
17 changes: 10 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:6.3
FROM node:8

ENV HOST localhost
ENV PORT 3000
Expand All @@ -7,12 +7,15 @@ ENV PORT 3000
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

# Install GYP dependencies globally, will be used to code build other dependencies
RUN npm install -g --production node-gyp && \
npm cache clean --force

# Install app dependencies
COPY package.json /usr/src/app/
RUN npm install -g node-gyp
RUN cd $(npm root -g)/npm && npm install fs-extra && sed -i -e s/graceful-fs/fs-extra/ -e s/fs.rename/fs.move/ ./lib/utils/rename.js
RUN npm install --production
RUN npm install redis@0.10.0 talib@1.0.2 pg@6.1.0
COPY package.json /usr/src/app
RUN npm install --production && \
npm install --production redis@0.10.0 talib@1.0.2 tulind@0.8.7 pg && \
npm cache clean --force

# Bundle app source
COPY . /usr/src/app
Expand All @@ -22,4 +25,4 @@ RUN chmod +x /usr/src/app/docker-entrypoint.sh
ENTRYPOINT ["/usr/src/app/docker-entrypoint.sh"]


CMD [ "npm", "start" ]
CMD [ "npm", "start" ]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

-Gordon Gekko

Gekko is a Bitcoin TA trading and backtesting platform that connects to popular Bitcoin exchanges. It is written in javascript and runs on [nodejs](http://nodejs.org).
Gekko is a Bitcoin TA trading and backtesting platform that connects to popular Bitcoin exchanges. It is written in JavaScript and runs on [Node.js](http://nodejs.org).

*Use Gekko at your own risk.*

Expand Down
12 changes: 12 additions & 0 deletions config/strategies/tulip-multi-strat.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
optInTimePeriod = 2
optInFastPeriod = 4
optInSlowPeriod = 7
optInSignalPeriod = 23.707189677282354

candleSize = 1
historySize = 4

up = 24.52
down = 55.74
macd_up = 14.498233170768081
macd_down = -9.65220944122072
25 changes: 25 additions & 0 deletions core/error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const _ = require('lodash');

let RetryError = function(message) {
_.bindAll(this);

this.name = "RetryError";
this.message = message;
}

RetryError.prototype = new Error();

let AbortError = function(message) {
_.bindAll(this);

this.name = "AbortError";
this.message = message;
}

AbortError.prototype = new Error();

module.exports = {
'RetryError': RetryError,
'AbortError': AbortError
};

22 changes: 14 additions & 8 deletions core/gekkoStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

var Writable = require('stream').Writable;
var _ = require('lodash');
var async = require('async');

var util = require('./util');
var env = util.gekkoEnv();
Expand Down Expand Up @@ -39,13 +40,18 @@ Gekko.prototype.finalize = function() {
}

Gekko.prototype.shutdown = function() {
_.each(this.candleConsumers, function(c) {
if(c.finalize)
c.finalize();
});

if(env === 'child-process')
process.exit(0);
}
async.eachSeries(
this.candleConsumers,
function(c, callback) {
if (c.finalize) c.finalize(callback);
else callback();
},
function() {
// If we are a child process, we signal to the parent to kill the child once it is done
// so that is has time to process all remaining events (and send report data)
if (env === 'child-process') process.send('done');
}
);
};

module.exports = Gekko;
3 changes: 2 additions & 1 deletion core/markets/importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ Market.prototype.processTrades = function(trades) {

if(this.done) {
log.info('Done importing!');
process.exit(0);
this.emit('end');
return;
}

if(_.size(trades)) {
Expand Down
4 changes: 2 additions & 2 deletions core/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const lodash = require('lodash');
// @param rfreturn (number - risk free return)
//
stats.sharpe = (returns, rfreturn) => {
return stats.mean(returns) - rfreturn / stats.stdev(returns);
return (stats.mean(returns) - rfreturn) / stats.stdev(returns);
}

module.exports = stats;
module.exports = stats;
10 changes: 9 additions & 1 deletion core/talib.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
var talib = require("talib");
var semver = require("semver");
var _ = require('lodash');

// validate that talib is installed, if not we'll throw an excepion which will
// prevent further loading or out outside this module
try {
var talib = require("talib");
} catch (e) {
module.exports = null;
return;
}

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

Expand Down
12 changes: 10 additions & 2 deletions core/tulind.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
var tulind = require("tulind");
var semver = require("semver");
var _ = require('lodash');

// validate that talib is installed, if not we'll throw an excepion which will
// prevent further loading or out outside this module
try {
var tulind = require("tulind");
} catch (e) {
module.exports = null;
return;
}

var tulindError = 'Gekko was unable to configure Tulip Indicators:\n\t';

// Wrapper that executes a tulip indicator
Expand Down Expand Up @@ -137,7 +145,7 @@ methods.aroon = {
methods.aroonosc = {
requires: ['optInTimePeriod'],
create: (params) => {
verifyParams('arronosc', params);
verifyParams('aroonosc', params);

return (data, callback) => execute(callback, {
indicator: tulind.indicators.aroonosc,
Expand Down
33 changes: 21 additions & 12 deletions core/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var fs = require('fs');
var semver = require('semver');
var program = require('commander');
var retry = require('retry');
var Errors = require('./error');

var startTime = moment();

Expand All @@ -16,6 +17,19 @@ var _gekkoEnv = false;

var _args = false;

var retryHelper = function(fn, options, callback) {
var operation = retry.operation(options);
operation.attempt(function(currentAttempt) {
fn(function(err, result) {
if (!(err instanceof Errors.AbortError) && operation.retry(err)) {
return;
}

callback(err ? err.message : null, result);
});
});
}

// helper functions
var util = {
getConfig: function() {
Expand Down Expand Up @@ -163,23 +177,18 @@ var util = {
return startTime;
},
retry: function(fn, callback) {
var operation = retry.operation({
var operation = {
retries: 5,
factor: 1.2,
minTimeout: 1 * 1000,
maxTimeout: 3 * 1000
});
};

operation.attempt(function(currentAttempt) {
fn(function(err, result) {
if (operation.retry(err)) {
return;
}

callback(err ? operation.mainError() : null, result);
});
});
}
retryHelper(fn, options, callback);
},
retryCustom: function(options, fn, callback) {
retryHelper(fn, options, callback);
},
}

// NOTE: those options are only used
Expand Down
10 changes: 9 additions & 1 deletion core/workers/pipeline/child.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,12 @@ process.send('ready');
process.on('message', function(m) {
if(m.what === 'start')
start(m.mode, m.config);
});

if(m.what === 'exit')
process.exit(0);
});

process.on('disconnect', function() {
console.log("disconnect");
process.exit(-1);
})
3 changes: 3 additions & 0 deletions core/workers/pipeline/parent.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ module.exports = (mode, config, callback) => {
if(m === 'ready')
return child.send(message);

if(m === 'done')
return child.send({what: 'exit'});

handle.message(m);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,6 @@ cd gekko
npm install --only=production
```

## Edit the handle.js file (taken from [here](https://github.com/askmike/gekko/issues/708#issuecomment-296329300))

Navigate to gekko/plugins/sqlite:

`cd ~/gekko/plugins/sqlite`

Change line 53 in handle.js from

`db.run("PRAGMA journal_mode = WAL"); `

to

`db.run("PRAGMA journal_mode = DEL"); `

(I use nano for this --> `nano handle.js`)


## Restart Bash and install the correct version of TA-lib (taken from [here](https://github.com/askmike/gekko/issues/908#issuecomment-319657408))

Restart Bash by closing it and reopening it. Then:
Expand Down
2 changes: 1 addition & 1 deletion docs/introduction/about_gekko.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Gekko is a tool that makes it very easy to automate your own trading stragies.

![gist of gekko](https://gekko.wizb.it/_static/gekko-gist.png)

You can either create your own trading strategy or start with the build in example strategies. Once you have a strategy you can use Gekko to automatically run it in a few different ways:
You can either create your own trading strategy or start with the built-in example strategies. Once you have a strategy you can use Gekko to automatically run it in a few different ways:

- **Backtest**: You can start a simulation of the strategy over a historical data period and Gekko will tell you what would have happened (which trades would have been performed as well as overall performance and risk metrics).
- **Paper trader**: You can run the strategy in realtime simulate trading (trade with fake money) to see in realtime how profitable your strategy would have been.
Expand Down
6 changes: 5 additions & 1 deletion docs/introduction/supported_exchanges.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ Gekko is able to directly communicate with the APIs of a number of exchanges. Ho
| [zaif][17] |||| |
| [lakeBTC][18] |||| |
| [bx.in.th][19] |||| |
| [bitcoin.co.id][22] |||| | |
| [bitcoin.co.id][22] |||| |
| [Quadriga CX][23] |||| |
| [Binance][24] |||| | |

[1]: ../features/backtesting.md
[2]: https://poloniex.com
Expand All @@ -51,4 +53,6 @@ Gekko is able to directly communicate with the APIs of a number of exchanges. Ho
[20]: https://github.com/askmike/gekko/pull/352
[21]: https://github.com/askmike/gekko/issues/288#issuecomment-223810974
[22]: https://vip.bitcoin.co.id/
[23]: https://quadrigacx.com/
[24]: https://binance.com/

0 comments on commit a80879d

Please sign in to comment.