Skip to content

Commit

Permalink
Merge pull request #18 from hiyan/develop
Browse files Browse the repository at this point in the history
Merge
  • Loading branch information
hiyan authored Sep 3, 2018
2 parents 2a6fa21 + 53dfb45 commit fe092dc
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 17 deletions.
1 change: 1 addition & 0 deletions core/tools/dataStitcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ Stitcher.prototype.seedLocalData = function(from, to, next) {
});

this.batcher.write(rows);
this.batcher.flush();
this.reader.close();
next();

Expand Down
14 changes: 14 additions & 0 deletions core/tulind.js
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,20 @@ methods.sma = {
}
}

methods.stddev = {
requires: ['optInTimePeriod'],
create: (params) => {
verifyParams('stddev', params);

return (data, callback) => execute(callback, {
indicator: tulind.indicators.stddev,
inputs: [data.close],
options: [params.optInTimePeriod],
results: ['result'],
});
}
}

methods.stoch = {
requires: ['optInFastKPeriod', 'optInSlowKPeriod', 'optInSlowDPeriod'],
create: (params) => {
Expand Down
4 changes: 2 additions & 2 deletions docs/strategies/creating_a_strategy.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

Strategies are the core of Gekko's trading bot. They look at the market and decide what to do based on technical analysis indicators. A single strategy is limited to a single market on a single exchange.

Gekko currently comes with [a couple of strategies](./introduction.md) out of the box. Besides those you can also write your own strategy in javascript. The easiest way to do this is to customize the file `gekko/strategies/custom.js`.
Gekko currently comes with [a couple of strategies](./introduction.md) out of the box. Besides those you can also write your own strategy in javascript. If you want to understand how to create your own strategy you can watch this video or read the tech docs on this page.

## Creating a strategy
[![youtube video on how to create gekko strategies](https://gekko.wizb.it/_static/create-strat-vid.jpg)](https://www.youtube.com/watch?v=6-74ZhrG0BE)

A strategy is a module with a few functions that get market data in the form of candles ([OHLC](https://en.wikipedia.org/wiki/Open-high-low-close_chart), volume, and the average weighted price) and output trading advice.

Expand Down
6 changes: 5 additions & 1 deletion docs/strategies/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ Gekko uses [technical analysis indicators](http://www.investopedia.com/articles/

This investment advice is going to be either **long** or **short**. Long indicates that Gekko the asset should be bought and short indicates that it should be sold.

Below you can find simple and exemplary strategies that come with Gekko. These strategies come with Gekko and serve as examples, **for anything that involves real money we recommend you [write your own](./creating_a_strategy.md).**
If you are familiar with javascript you can easily create your own strategies. Here is a video explaining everything you need to know:

[![youtube video on how to create gekko strategies](https://gekko.wizb.it/_static/create-strat-vid.jpg)](https://www.youtube.com/watch?v=6-74ZhrG0BE)

Below you can find simple and exemplary strategies that come with Gekko. These strategies come with Gekko and serve as examples.

Gekko currently comes with the following example strategies:

Expand Down
24 changes: 16 additions & 8 deletions exchange/orders/sticky.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,21 +207,30 @@ class StickyOrder extends BaseOrder {
this.status = states.OPEN;
this.emitStatus();

this.scheduleNextCheck();
}

scheduleNextCheck() {

// remove lock
this.sticking = false;

// check whether we had an action pending
if(this.cancelling)
if(this.cancelling) {
return this.cancel();
}

if(this.movingLimit)
if(this.movingLimit) {
return this.moveLimit();
}

if(this.movingAmount)
if(this.movingAmount) {
return this.moveAmount();
}

// register check
this.timeout = setTimeout(this.checkOrder, this.checkInterval);

}

checkOrder() {
Expand All @@ -245,8 +254,7 @@ class StickyOrder extends BaseOrder {
// if we are already at limit we dont care where the top is
// note: might be string VS float
if(this.price == this.limit) {
this.timeout = setTimeout(this.checkOrder, this.checkInterval);
this.sticking = false;
this.scheduleNextCheck();
return;
}

Expand All @@ -264,8 +272,7 @@ class StickyOrder extends BaseOrder {
return this.move(this.calculatePrice(ticker));
}

this.timeout = setTimeout(this.checkOrder, this.checkInterval);
this.sticking = false;
this.scheduleNextCheck();
});

return;
Expand Down Expand Up @@ -409,7 +416,7 @@ class StickyOrder extends BaseOrder {
this.sticking = true;
this.move(this.limit);
} else {
this.timeout = setTimeout(this.checkOrder, this.checkInterval);
this.scheduleNextCheck();
}

return true;
Expand Down Expand Up @@ -492,6 +499,7 @@ class StickyOrder extends BaseOrder {

this.completing = true;
clearTimeout(this.timeout);

this.api.cancelOrder(this.id, (err, filled, data) => {
if(this.handleError(err)) {
return;
Expand Down
3 changes: 2 additions & 1 deletion exchange/wrappers/binance.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ const recoverableErrors = [
'ETIMEDOUT',
'EHOSTUNREACH',
// getaddrinfo EAI_AGAIN api.binance.com api.binance.com:443
'EAI_AGAIN'
'EAI_AGAIN',
'ENETUNREACH'
];

const includes = (str, list) => {
Expand Down
4 changes: 3 additions & 1 deletion exchange/wrappers/coinfalcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ const recoverableErrors = [
// https://github.com/askmike/gekko/issues/2407
'We are fixing a few issues, be back shortly.',
'Client network socket disconnected before secure TLS connection was established',
'socket hang up'
'socket hang up',
// getaddrinfo EAI_AGAIN coinfalcon.com coinfalcon.com:443
'EAI_AGAIN'
];

Trader.prototype.processResponse = function(method, args, next) {
Expand Down
4 changes: 3 additions & 1 deletion exchange/wrappers/gdax.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ const recoverableErrors = [
'HTTP 504 Error',
'HTTP 503 Error',
'socket hang up',
'EHOSTUNREACH'
'EHOSTUNREACH',
'EAI_AGAIN',
'ENETUNREACH'
];

const includes = (str, list) => {
Expand Down
5 changes: 4 additions & 1 deletion exchange/wrappers/poloniex.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ const recoverableErrors = [
'Please try again in a few minutes.',
'Nonce must be greater than',
'Internal error. Please try again.',
'Connection timed out. Please try again.'
'Connection timed out. Please try again.',
// getaddrinfo EAI_AGAIN poloniex.com poloniex.com:443
'EAI_AGAIN',
'ENETUNREACH'
];

// errors that might mean
Expand Down
22 changes: 22 additions & 0 deletions plugins/tradingAdvisor/baseTradingMethod.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,17 @@ Base.prototype.propogateTick = function(candle) {
}

Base.prototype.processTrade = function(trade) {
if(
this._pendingTriggerAdvice &&
trade.action === 'sell' &&
this._pendingTriggerAdvice === trade.adviceId
) {
// This trade came from a trigger of the previous advice,
// update stored direction
this._currentDirection = 'short';
this._pendingTriggerAdvice = null;
}

this.onTrade(trade);
}

Expand Down Expand Up @@ -224,6 +235,10 @@ Base.prototype.advice = function(newDirection) {
return;
}

if(newDirection.direction === this._currentDirection) {
return;
}

if(_.isObject(newDirection.trigger)) {
if(newDirection.direction !== 'long') {
log.warn(
Expand All @@ -249,6 +264,10 @@ Base.prototype.advice = function(newDirection) {
return;
}

if(newDirection === 'short' && this._pendingTriggerAdvice) {
this._pendingTriggerAdvice = null;
}

this._currentDirection = newDirection;

this.propogatedAdvices++;
Expand All @@ -260,6 +279,9 @@ Base.prototype.advice = function(newDirection) {

if(trigger) {
advice.trigger = trigger;
this._pendingTriggerAdvice = 'advice-' + this.propogatedAdvices;
} else {
this._pendingTriggerAdvice = null;
}

this.emit('advice', advice);
Expand Down
5 changes: 3 additions & 2 deletions plugins/tradingAdvisor/tradingAdvisor.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,15 @@ Actor.prototype.processCandle = function(candle, done) {
this.next = done;
} else {
done();
this.next = _.noop;
this.next = false;
}
this.batcher.flush();
}

// propogate a custom sized candle to the trading strategy
Actor.prototype.emitStratCandle = function(candle) {
this.strategy.tick(candle, this.next);
const next = this.next || _.noop;
this.strategy.tick(candle, next);
}

Actor.prototype.processTradeCompleted = function(trade) {
Expand Down

0 comments on commit fe092dc

Please sign in to comment.