Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge #15

Merged
merged 28 commits into from
Aug 28, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0a47199
Updated Path to UIconfig.js file in setup instructions.
ACregan Jul 9, 2018
61a5cf9
Merge pull request #2346 from askmike/develop
askmike Jul 21, 2018
f936339
v0.6.5 (#2428)
askmike Aug 10, 2018
97a9b6d
Disconnect child processes, fix #2457
eusorov Aug 22, 2018
e12eea0
make sure the balance & exposure always gets reset after sync
askmike Aug 22, 2018
47f4a49
bundle current version ws dep, fix #2476
askmike Aug 24, 2018
1f0ee10
init trailing stop
askmike Aug 11, 2018
d238016
add tests for trailing stop
askmike Aug 11, 2018
41107a6
[TEST] also check spy pre trigger
askmike Aug 11, 2018
48a3ab9
[TEST] stop should only trigger once
askmike Aug 11, 2018
90a13a6
[TEST] check whether the trailing stop trails up
askmike Aug 11, 2018
0ba7ba1
init strategy stop API
askmike Aug 11, 2018
11fc34f
init paper trader stop implementation
askmike Aug 11, 2018
8de1c83
[DOCS] add trigger events
askmike Aug 13, 2018
cf495ff
add trigger event subscriptions
askmike Aug 13, 2018
e7da592
implement triggerCreated & triggerAborted in paper trader
askmike Aug 13, 2018
25698c8
implement triggerFired event
askmike Aug 13, 2018
1b8a707
rewire stop prop into trigger & init paper trader glue
askmike Aug 14, 2018
5484ebb
[TEST] price swings around trail
askmike Aug 14, 2018
2e0b4e2
[DOCS] cleanup tmp copy/paste
askmike Aug 14, 2018
a7038a7
mv triggers into gekko broker
askmike Aug 15, 2018
7a26284
[GB] init real trader trigger glue
askmike Aug 15, 2018
a63d927
only create trigger after init trade is completed
askmike Aug 16, 2018
331ceeb
[GB] rewire live trigger to init exec price
askmike Aug 17, 2018
a418c4a
make sure we only move the trail up
askmike Aug 27, 2018
5a798fb
when empty data returns, loader never finishes and never get killed
Aug 23, 2018
f27b3ce
v0.6.6
askmike Aug 27, 2018
95d1873
Merge branch 'stable' into develop
askmike Aug 27, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
v0.6.5 (askmike#2428)
* [docs] install indicator libs without updating package.json

* add tulip example strat configs, see askmike#2341

* uppercase default macd strat

* temp revert bfx dep to main repo (fixes importer)

* binance set default fee as percentage

* rename bitx to luno (askmike#2352)

* v0.6 support for bitx (aka Luno)

* v0.6 support for bitx (aka Luno)

* remove log

* move dependency to gb

* rename bitx to luno

* rename bitx to luno

* make sure we pass amount as positive value

* make sure we overlap when importing trades

* rm 500 as retryable error, see askmike#2354

* only try to set fee when live trading, see askmike#2358

* make gekko pic path relative

* make select arrow path relative

* Fix method name for stratNotification event

* make sure we parse both TS (backtest) & moment strings (live)

* make sure GB throws errors

* only render warmup warning when there is required history

* v0.6.4

* fix plugin event wire warning

* check portfolio data before calculating report (askmike#2369)

* Changed several log messages from debug to warn (askmike#2374)

Changed "Not creating order" message and "exchange did not provide fee info" from debug to warn messages so users can see these issues even when debug is set to false.

* make sure we pass on exchange error (askmike#2379)

* fix backtest result exporter in standalone mode (askmike#2382)

* make sure to pass order id in cancel edge flow, fix askmike#2386 (askmike#2387)

* Emit trade and trade errors via Telegram (askmike#2385)

* Emit trade and trade errors via Telegram

* Added semi-colons

Added missing semi-colons in processTradeCompleted and processTradeErrored methods.

* Register methods only if set to true in config

* catch undefined CPU cores on ARM (askmike#2391)

* export portfolio values as part of stratCandles (askmike#2402)

* rm space in backtest export file location

* [GB/Binance] retry on 403 (askmike#2404)

* completely disable broken limit order for now, fix askmike#2398

* rewire cancelfix cb, see askmike#2386

* remove slack dependency that is triggering warnings (askmike#2408)

* move slack plugin dep out of main repo

* remove twitter & pushbullet plugin dependencies from main repo (askmike#2409)

* move slack dependency out of main repo

* rm slack dep from main repo

* also remove pushbullet & twitter deps from main repo

* use forked bittrex dep with updated dependencies (askmike#2410)

* use bittrex fork with updated deps

* [GB] introduce optimizedConnection flag in binance

* [GB] catch strange networking error

* update binance market files, see askmike#2406

* [GB] point to supported_exchanges doc

* [GB] add example usage, fix askmike#2414

* assume CF maintainance to be recoverable, fix askmike#2407

* use npm version of of forked bittrex dep

* catch gb init errors

* [sqlite] wait for 10 seconds on busy

* throw errors, not strings

* [GB] update bfx & cf markets

* Update Luno (askmike#2417)

* v0.6 support for bitx (aka Luno)

* v0.6 support for bitx (aka Luno)

* remove log

* move dependency to gb

* rename bitx to luno

* rename bitx to luno

* temp fix simultaneous advice error

* - re-add logging
- Retry insufficient balance due to server update delay
- Enhanced getPorfolio
- getOrder now return fees

* update

* update

* update

* revert 4b5d09f

* v.0.6.5
  • Loading branch information
askmike committed Aug 10, 2018
commit f9363397b47b4932dab44cea786849f05f6a2216
2 changes: 1 addition & 1 deletion core/budfox/marketFetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const TradeBatcher = require(util.dirs().budfox + 'tradeBatcher');

const Fetcher = function(config) {
if(!_.isObject(config))
throw 'TradeFetcher expects a config';
throw new Error('TradeFetcher expects a config');

const exchangeName = config.watch.exchange.toLowerCase();
const DataProvider = require(util.dirs().gekko + 'exchange/wrappers/' + exchangeName);
Expand Down
4 changes: 2 additions & 2 deletions core/budfox/tradeBatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var log = require('../log');

var TradeBatcher = function(tid) {
if(!_.isString(tid))
throw 'tid is not a string';
throw new Error('tid is not a string');

_.bindAll(this);
this.tid = tid;
Expand All @@ -49,7 +49,7 @@ util.makeEventEmitter(TradeBatcher);
TradeBatcher.prototype.write = function(batch) {

if(!_.isArray(batch))
throw 'batch is not an array';
throw new Error('batch is not an array');

if(_.isEmpty(batch))
return log.debug('Trade fetch came back empty.');
Expand Down
7 changes: 4 additions & 3 deletions core/candleBatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var util = require(__dirname + '/util');

var CandleBatcher = function(candleSize) {
if(!_.isNumber(candleSize))
throw 'candleSize is not a number';
throw new Error('candleSize is not a number');

this.candleSize = candleSize;
this.smallCandles = [];
Expand All @@ -26,8 +26,9 @@ var CandleBatcher = function(candleSize) {
util.makeEventEmitter(CandleBatcher);

CandleBatcher.prototype.write = function(candles) {
if(!_.isArray(candles))
throw 'candles is not an array';
if(!_.isArray(candles)) {
throw new Error('candles is not an array');
}

this.emitted = 0;

Expand Down
26 changes: 19 additions & 7 deletions core/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ var pipeline = (settings) => {
_.each(
pluginSubscriptions.filter(s => _.isArray(s.emitter)),
subscription => {
// cache full list
subscription.emitters = subscription.emitter;
var singleEventEmitters = subscription.emitter
.filter(
s => _.size(plugins.filter(p => p.meta.slug === s))
Expand All @@ -110,18 +112,28 @@ var pipeline = (settings) => {
_.each(pluginSubscriptions, function(sub) {

if(plugin[sub.handler]) {

// if a plugin wants to listen
// to something disabled
if(!emitters[sub.emitter]) {
if(!plugin.meta.greedy) {
log.warn([

let emitterMessage;
if(sub.emitters) {
emitterMessage = 'all of the emitting plugins [ ';
emitterMessage += sub.emitters.join(', ');
emitterMessage += ' ] are disabled.';
} else {
emitterMessage += 'the emitting plugin (' + sub.emitter;
emitterMessage += ')is disabled.'
}

log.error([
plugin.meta.name,
'wanted to listen to the',
sub.emitter + ',',
'however the',
sub.emitter,
'is disabled.'
'wanted to listen to event',
sub.event + ',',
'however',
emitterMessage,
plugin.meta.name + ' might malfunction because of it.'
].join(' '));
}
return;
Expand Down
10 changes: 6 additions & 4 deletions core/talib.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ var verifyParams = (methodName, params) => {
var requiredParams = methods[methodName].requires;

_.each(requiredParams, paramName => {
if(!_.has(params, paramName))
throw talibError + methodName + ' requires ' + paramName + '.';
if(!_.has(params, paramName)) {
throw new Error(talibError + methodName + ' requires ' + paramName + '.');
}

var val = params[paramName];

if(!_.isNumber(val))
throw talibError + paramName + ' needs to be a number';
if(!_.isNumber(val)) {
throw new Error(talibError + paramName + ' needs to be a number');
}
});
}

Expand Down
4 changes: 4 additions & 0 deletions core/tools/dataStitcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ Stitcher.prototype.checkExchangeTrades = function(since, next) {

var watcher = new DataProvider(exchangeConfig);
watcher.getTrades(since, function(e, d) {
if(e) {
util.die(e.message);
}

if(_.isEmpty(d))
return util.die(
`Gekko tried to retrieve data since ${since.format('YYYY-MM-DD HH:mm:ss')}, however
Expand Down
10 changes: 6 additions & 4 deletions core/tulind.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ var verifyParams = (methodName, params) => {
var requiredParams = methods[methodName].requires;

_.each(requiredParams, paramName => {
if(!_.has(params, paramName))
throw tulindError + methodName + ' requires ' + paramName + '.';
if(!_.has(params, paramName)) {
throw new Error(tulindError + methodName + ' requires ' + paramName + '.');
}

var val = params[paramName];

if(!_.isNumber(val))
throw tulindError + paramName + ' needs to be a number';
if(!_.isNumber(val)) {
throw new Error(tulindError + paramName + ' needs to be a number');
}
});
}

Expand Down
7 changes: 5 additions & 2 deletions core/workers/datasetScan/parent.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ module.exports = function(config, done) {
if(err)
return done(err);

async.eachLimit(markets, os.cpus().length, (market, next) => {
let numCPUCores = os.cpus().length;
if(numCPUCores === undefined)
numCPUCores = 1;
async.eachLimit(markets, numCPUCores, (market, next) => {

let marketConfig = _.clone(config);
marketConfig.watch = market;
Expand Down Expand Up @@ -48,4 +51,4 @@ module.exports = function(config, done) {
done(err, resp);
})
});
}
}
86 changes: 73 additions & 13 deletions docs/gekko-broker/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,7 @@ This library allows you to:

## Status

Early WIP. All communication is via the REST APIs of exchanges. Not all exchanges are supported.

Currently fully supported exchanges:

- Binance
- GDAX
- Poloniex
- Coinfalcon
- Kraken

Currently exchanges with limited support:

- bittrex
Early WIP. All communication is via the REST APIs of exchanges. Not all exchanges are supported, see which ones are in [this doc](../introduction/supported_exchanges.md).

## Order types

Expand All @@ -62,6 +50,78 @@ TODO:
- Stop
- If Touched (stop but opposite direction)

### Example

Set up a Gekko Broker instance:

// from the gekko repo (make sure you have deps installed
// inside the exchange folder).
const Broker = require('../gekko/exchange/GekkoBroker');
// or from NPM
// const Broker = require('gekko-broker');

const binance = new Broker({
currency: 'USDT',
asset: 'BTC',
private: true,

exchange: 'binance',
key: 'x', // add your API key
secret: 'y' // add your API secret
});

Now we have an instance that can create a [sticky order](./sticky_order.md):

const type = 'sticky';
const side = 'buy';
const amount = 1;

const order = binance.createOrder(type, side, amount);

order.on('statusChange', s => console.log(now(), 'new status', s));
order.on('fill', s => console.log(now(), 'filled', s));
order.on('error', s => console.log(now(), 'error!', e));
order.on('completed', a => {
console.log(new Date, 'completed!');
order.createSummary((err, s) => {
console.log(new Date, 'summary:');
console.log(JSON.stringify(s, null, 2));
});
});

This one doesn't have an upper limit price for what it will buy at. It will stick it's bid offer at BBO until it's filled. If you have a limit in mind you can specify it when creating, do this instead:

const order = binance.createOrder(type, side, amount, { limit: 100 });

It will never offer to buy for more than 100, even if the BBO is above 100 (the bid will end up deep in the book).

At any point in time you can change the limit (or the amount), for example:

order.moveLimit(120);

Running the above example (without setting a limit and moving it) will yield:

root@foxtail:~/gb/nusadua# node b
2018-07-29 03:46:02 new status SUBMITTED
2018-07-29 03:46:02 new status OPEN
2018-07-29 03:46:04 filled 1
2018-07-29 03:46:04 new status FILLED
2018-07-29T03:46:04.127Z 'completed!'
2018-07-29T03:46:04.358Z 'summary:'
{
"price": 0.0017479,
"amount": 1,
"date": "2018-07-29T03:46:02.576Z",
"side": "buy",
"orders": 1,
"fees": {
"BNB": 0.00075
},
"feePercent": 0.075
}

NOTE: not all status changes are documented and more events are planned but not implemented.

### TODO

- finish all exchange integrations that gekko supports
Expand Down
2 changes: 1 addition & 1 deletion docs/internals/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ and will start signaling advice.

- What: An object describing new notification from your strategy
- When: when the strategy emit using `this.notify()` function
- Subscribe: You can subscribe to this event by registering the `stratNotification` method.
- Subscribe: You can subscribe to this event by registering the `processStratNotification` method.
- Example:
{
date: [moment object of the start time of the candle],
Expand Down
4 changes: 1 addition & 3 deletions docs/introduction/supported_exchanges.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Gekko is able to directly communicate with the APIs of a number of exchanges. Ho
| [Okcoin.cn][11]* | ✓ | ✓ | ✕ | China, see [#352][20] |
| [Cex.io][12]* | ✓ | ✕ | ✕ | |
| [BTC Markets][13]* | ✓ | ✓ | ✕ | |
| [bitX][14] | ✓ | ✓ | ✓ | aka Luno |
| [Luno][14] | ✓ | ✓ | ✓ | previously BitX |
| [lakeBTC][15]* | ✓ | ✕ | ✕ | |
| [meXBT][16]* | ✓ | ✕ | ✕ | see [here][21] |
| [zaif][17]* | ✓ | ✕ | ✕ | |
Expand Down Expand Up @@ -60,5 +60,3 @@ Gekko is able to directly communicate with the APIs of a number of exchanges. Ho
[24]: https://www.binance.com/?ref=11236330
[25]: https://coinfalcon.com/?ref=CFJSQBMXZZDS
[26]: https://github.com/askmike/gekko/pull/2310


2 changes: 1 addition & 1 deletion docs/strategies/talib_indicators.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Open your terminal. Then:

```
cd ~/gekko
npm install talib
npm install talib --no-save
```

## Example
Expand Down
2 changes: 1 addition & 1 deletion docs/strategies/tulip_indicators.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Open your terminal. Then:

```
cd ~/gekko
npm install tulind
npm install tulind --no-save
```

## Example
Expand Down
11 changes: 4 additions & 7 deletions exchange/gekkoBroker.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,14 @@ class Broker {

if(config.private) {
if(this.cantTrade()) {
throw this.cantTrade();
throw new Error(this.cantTrade());
}
} else {
if(this.cantMonitor()) {
throw this.cantMonitor();
throw new Error(this.cantMonitor());
}
}

if(config.private && this.cantTrade()) {
throw this.cantTrade();
}

this.orders = {
// contains current open orders
open: [],
Expand Down Expand Up @@ -81,8 +77,9 @@ class Broker {
return;
}

if(this.cantTrade())
if(this.cantTrade()) {
throw new errors.ExchangeError(this.cantTrade());
}

this.syncPrivateData();
}
Expand Down
4 changes: 1 addition & 3 deletions exchange/orders/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const sticky = require('./sticky');
const limit = require('./limit');

module.exports = {
sticky,
limit
sticky
}
5 changes: 5 additions & 0 deletions exchange/orders/limit.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// NOTE: this is currently broken, see
// @link https://github.com/askmike/gekko/issues/2398

throw ':(';

/*
The limit order is a simple order:
- It is created at the specified price
Expand Down
1 change: 1 addition & 0 deletions exchange/orders/sticky.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ class StickyOrder extends BaseOrder {
throw err;

this.ticker = ticker;
this.emit('ticker', ticker);

const bookSide = this.side === 'buy' ? 'bid' : 'ask';
// note: might be string VS float
Expand Down
Loading