Skip to content

Commit

Permalink
Merge pull request #20 from askmike/develop
Browse files Browse the repository at this point in the history
Merge
  • Loading branch information
hiyan authored Sep 6, 2018
2 parents 55e6c90 + 4fcfb45 commit aab894f
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 71 deletions.
4 changes: 3 additions & 1 deletion core/workers/loadCandles/parent.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ module.exports = (config, callback) => {

// else we are done and have candles!
done(null, m);
this.disconnect();
if (this.connected) {
this.disconnect();
}
});

child.on('exit', code => {
Expand Down
5 changes: 4 additions & 1 deletion exchange/wrappers/gdax.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,20 +414,23 @@ Trader.getCapabilities = function() {
name: 'GDAX',
slug: 'gdax',
currencies: ['USD', 'EUR', 'GBP', 'BTC'],
assets: ['BTC', 'LTC', 'ETH', 'BCH'],
assets: ['BTC', 'LTC', 'ETH', 'BCH', 'ETC'],
markets: [
{ pair: ['USD', 'BTC'], minimalOrder: { amount: 0.001, unit: 'asset' } },
{ pair: ['USD', 'LTC'], minimalOrder: { amount: 0.1, unit: 'asset' } },
{ pair: ['USD', 'ETH'], minimalOrder: { amount: 0.01, unit: 'asset' } },
{ pair: ['USD', 'BCH'], minimalOrder: { amount: 0.01, unit: 'asset' } },
{ pair: ['USD', 'ETC'], minimalOrder: { amount: 0.01, unit: 'asset' } },
{ pair: ['EUR', 'BTC'], minimalOrder: { amount: 0.001, unit: 'asset' } },
{ pair: ['EUR', 'ETH'], minimalOrder: { amount: 0.1, unit: 'asset' } },
{ pair: ['EUR', 'LTC'], minimalOrder: { amount: 0.01, unit: 'asset' } },
{ pair: ['EUR', 'BCH'], minimalOrder: { amount: 0.1, unit: 'asset' } },
{ pair: ['EUR', 'ETC'], minimalOrder: { amount: 0.1, unit: 'asset' } },
{ pair: ['GBP', 'BTC'], minimalOrder: { amount: 0.001, unit: 'asset' } },
{ pair: ['BTC', 'LTC'], minimalOrder: { amount: 0.1, unit: 'asset' } },
{ pair: ['BTC', 'ETH'], minimalOrder: { amount: 0.01, unit: 'asset' } },
{ pair: ['BTC', 'BCH'], minimalOrder: { amount: 0.01, unit: 'asset' } },
{ pair: ['BTC', 'ETC'], minimalOrder: { amount: 0.01, unit: 'asset' } },
],
requires: ['key', 'secret', 'passphrase'],
providesHistory: 'date',
Expand Down
142 changes: 73 additions & 69 deletions plugins/postgresql/writer.js
Original file line number Diff line number Diff line change
@@ -1,69 +1,73 @@
var _ = require('lodash');
const log = require('../../core/log');
var config = require('../../core/util.js').getConfig();

var handle = require('./handle');
var postgresUtil = require('./util');

var Store = function(done, pluginMeta) {
_.bindAll(this);
this.done = done;
this.db = handle;
this.cache = [];
done();
}

Store.prototype.writeCandles = function() {
if(_.isEmpty(this.cache)){
return;
}

//log.debug('Writing candles to DB!');
_.each(this.cache, candle => {
var stmt = `
BEGIN;
LOCK TABLE ${postgresUtil.table('candles')} IN SHARE ROW EXCLUSIVE MODE;
INSERT INTO ${postgresUtil.table('candles')}
(start, open, high,low, close, vwp, volume, trades)
VALUES
(${candle.start.unix()}, ${candle.open}, ${candle.high}, ${candle.low}, ${candle.close}, ${candle.vwp}, ${candle.volume}, ${candle.trades})
ON CONFLICT ON CONSTRAINT ${postgresUtil.startconstraint('candles')}
DO NOTHING;
COMMIT;
`;

this.db.connect((err,client,done) => {
client.query(stmt, (err, res) => {
done();
if (err) {
log.debug(err.stack)
} else {
//log.debug(res)
}
});
});
});

this.cache = [];
}

var processCandle = function(candle, done) {
this.cache.push(candle);
if (this.cache.length > 1)
this.writeCandles();

done();
};

var finalize = function(done) {
this.writeCandles();
this.db = null;
done();
}

if(config.candleWriter.enabled) {
Store.prototype.processCandle = processCandle;
Store.prototype.finalize = finalize;
}

module.exports = Store;
var _ = require('lodash');
const log = require('../../core/log');
const util = require('../../core/util');
const config = util.getConfig();

var handle = require('./handle');
var postgresUtil = require('./util');

var Store = function(done, pluginMeta) {
_.bindAll(this);
this.done = done;
this.db = handle;
this.cache = [];
done();
}

Store.prototype.writeCandles = function() {
if(_.isEmpty(this.cache)){
return;
}

//log.debug('Writing candles to DB!');
_.each(this.cache, candle => {
var stmt = `
BEGIN;
LOCK TABLE ${postgresUtil.table('candles')} IN SHARE ROW EXCLUSIVE MODE;
INSERT INTO ${postgresUtil.table('candles')}
(start, open, high,low, close, vwp, volume, trades)
VALUES
(${candle.start.unix()}, ${candle.open}, ${candle.high}, ${candle.low}, ${candle.close}, ${candle.vwp}, ${candle.volume}, ${candle.trades})
ON CONFLICT ON CONSTRAINT ${postgresUtil.startconstraint('candles')}
DO NOTHING;
COMMIT;
`;

this.db.connect((err,client,done) => {
if(err) {
util.die(err);
}
client.query(stmt, (err, res) => {
done();
if (err) {
log.debug(err.stack)
} else {
//log.debug(res)
}
});
});
});

this.cache = [];
}

var processCandle = function(candle, done) {
this.cache.push(candle);
if (this.cache.length > 1)
this.writeCandles();

done();
};

var finalize = function(done) {
this.writeCandles();
this.db = null;
done();
}

if(config.candleWriter.enabled) {
Store.prototype.processCandle = processCandle;
Store.prototype.finalize = finalize;
}

module.exports = Store;
12 changes: 12 additions & 0 deletions plugins/tradingAdvisor/baseTradingMethod.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,18 @@ Base.prototype.propogateTick = function(candle) {
_.each(this.indicators, (indicator, name) => {
indicators[name] = indicator.result;
});

_.each(this.tulipIndicators, (indicator, name) => {
indicators[name] = indicator.result.result
? indicator.result.result
: indicator.result;
});

_.each(this.talibIndicators, (indicator, name) => {
indicators[name] = indicator.result.outReal
? indicator.result.outReal
: indicator.result;
});

this.emit('stratUpdate', {
date: candle.start.clone(),
Expand Down

0 comments on commit aab894f

Please sign in to comment.