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

gekko v0.5.9 #1241

Merged
merged 16 commits into from
Oct 23, 2017
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ RUN npm install redis@0.10.0 talib@1.0.2 pg
# Bundle app source
COPY . /usr/src/app

EXPOSE 3000
RUN chmod +x /usr/src/app/docker-entrypoint.sh
ENTRYPOINT ["/usr/src/app/docker-entrypoint.sh"]


CMD [ "npm", "start" ]
12 changes: 8 additions & 4 deletions core/tools/dataStitcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,14 @@ Stitcher.prototype.checkExchangeTrades = function(since, next) {
var provider = config.watch.exchange.toLowerCase();
var DataProvider = require(util.dirs().gekko + 'exchanges/' + provider);

var exchangeChecker = require(util.dirs().core + 'exchangeChecker');
var exchangeSettings = exchangeChecker.settings(config.watch)

var watcher = new DataProvider(config.watch);
var exchangeConfig = config.watch;

// include trader config if trading is enabled
if (_.isObject(config.trader) && config.trader.enabled) {
exchangeConfig = _.extend(config.watch, config.trader);
}

var watcher = new DataProvider(exchangeConfig);

watcher.getTrades(since, function(e, d) {
if(_.isEmpty(d))
Expand Down
136 changes: 100 additions & 36 deletions exchanges/btc-markets.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ var Trader = function(config) {
}
this.name = 'BTC Markets';
this.priceDivider = 100000000; // one hundred million

this.btcmakets = new BTCMarkets(this.key, this.secret);
}

Expand Down Expand Up @@ -44,8 +43,8 @@ Trader.prototype.retry = function(method, args) {
Trader.prototype.getPortfolio = function(callback) {
var set = function(err, data) {

if(!_.isEmpty(data.error))
return callback('BTC-MARKET API ERROR: ' + data.error);
if(!_.isEmpty(data.errorMessage))
return callback('BTC-MARKET API ERROR: ' + data.errorMessage);

var portfolio = _.map(data, function(balance) {
return {
Expand Down Expand Up @@ -75,24 +74,37 @@ Trader.prototype.getTicker = function(callback) {
}

Trader.prototype.getFee = function(callback) {
// TODO, not 100% correct.
// However there is no API call to retrieve real fee
callback(false, 0.00085)
var args = _.toArray(arguments);
var set = function(err, data) {

if(!err && _.isEmpty(data))
err = 'no data';
else if(!err && !_.isEmpty(data.errorMessage))
err = data.errorMessage;
if(err){
log.error('unable to retrieve fee', err, ' retrying...');
return this.retry(this.getFee, args);
}
data.tradingFeeRate /= this.priceDivider;
callback(false, data.tradingFeeRate);
}.bind(this);
this.btcmakets.getTradingFee(this.asset, this.currency, set);
}

Trader.prototype.buy = function(amount, price, callback) {
var invFee = 0.9915;
price *= this.priceDivider;
amount = Math.floor(amount * this.priceDivider * invFee);
var id = Math.random() + '';

var set = function(err, result) {
if(err || result.error)
return log.error('unable to buy:', err, result);

callback(null, id);
price *= this.priceDivider;
amount = Math.floor(amount * this.priceDivider);
var id = Math.random() + '';
var set = function(err, data) {
if(!err && _.isEmpty(data))
err = 'no data';
else if(!err && !_.isEmpty(data.errorMessage))
err = data.errorMessage;
if(err)
return log.error('unable to buy', err);
callback(null, data.id);
}.bind(this);

this.btcmakets.createOrder(
this.asset,
this.currency,
Expand All @@ -108,15 +120,16 @@ Trader.prototype.buy = function(amount, price, callback) {
Trader.prototype.sell = function(amount, price, callback) {
price *= this.priceDivider;
amount = Math.floor(amount * this.priceDivider);
var id = Math.random() + '';

var set = function(err, result) {
if(err || result.error)
return log.error('unable to buy:', err, result);

callback(null, id);
var id = Math.random() + ''
var set = function(err, data) {
if(!err && _.isEmpty(data))
err = 'no data';
else if(!err && !_.isEmpty(data.errorMessage))
err = data.errorMessage;
if(err)
return log.error('unable to sell', err)
callback(null, data.id);
}.bind(this);

this.btcmakets.createOrder(
this.asset,
this.currency,
Expand All @@ -130,20 +143,65 @@ Trader.prototype.sell = function(amount, price, callback) {
}

Trader.prototype.checkOrder = function(order, callback) {
var check = function(err, result) {
callback(err, result && result.success);
var args = _.toArray(arguments);

if (order == null) {
return callback(null, true);
}

var check = function(err, data) {
if(!err && _.isEmpty(data.orders))
err = 'no data';
else if(!err && !_.isEmpty(data.errorMessage))
err = data.errorMessage;
if(err){
return log.error('unable to check order: ', order, '(', err ,'), retrying...');
this.retry(this.checkOrder, args);
}
var placed = !_.isEmpty(data.orders)
callback(err, !placed);
}.bind(this);

this.btcmakets.getOpenOrders(this.asset, this.currency, 10, null, check);
}

Trader.prototype.cancelOrder = function(order, callback) {
var cancel = function(err, result) {
if(err || !result)
log.error('unable to cancel order', order, '(', err, result, ')');
Trader.prototype.getOrder = function(order, callback) {
var args = _.toArray(arguments);
var get = function(err, data) {

if(!err && _.isEmpty(data.orders))
err = 'no data';
else if(!err && !_.isEmpty(data.errorMessage))
err = data.errorMessage;
if(err){
return log.error('unable to get order detail: ', order, '(', err ,'), retrying...');
this.retry(this.getOrder, args);
}
var price = parseFloat(data.orders[0].price);
var amount = parseFloat(data.orders[0].volumn);
var date = moment.unix(data.orders[0].creationDate);

callback(undefined, {price, amount, date});
}.bind(this);

this.btcmakets.cancelOrder([order], cancel);
this.btcmakets.getOrderDetail([order], callback);
}

Trader.prototype.cancelOrder = function(order, callback) {
var args = _.toArray(arguments);
var get = function(err, data) {

if(!err && _.isEmpty(data))
err = 'no data';
else if(!err && !_.isEmpty(data.errorMessage))
err = data.errorMessage;
if(err){
return log.error('unable to cancel order: ',order, '(', err, '), retrying...');
this.retry(this.cancelOrder, args);
}
callback();
};
this.btcmakets.cancelOrders([order], callback);
}

Trader.prototype.getTrades = function(since, callback, descending) {
Expand All @@ -165,20 +223,26 @@ Trader.getCapabilities = function () {
slug: 'btc-markets',
currencies: ['AUD', 'BTC'],
assets: [
'BTC', 'LTC', 'ETH', 'ETC'
'BTC', 'LTC', 'ETH', 'ETC', 'BCH', 'XRP'
],
markets: [
{ pair: ['AUD', 'BTC'], minimalOrder: { amount: 0.001, unit: 'asset' } },
{ pair: ['AUD', 'LTC'], minimalOrder: { amount: 0.001, unit: 'asset' } },
{ pair: ['AUD', 'ETH'], minimalOrder: { amount: 0.001, unit: 'asset' } },
{ pair: ['AUD', 'LTC'], minimalOrder: { amount: 0.001, unit: 'asset' } },
{ pair: ['AUD', 'ETC'], minimalOrder: { amount: 0.001, unit: 'asset' } },
{ pair: ['AUD', 'BCH'], minimalOrder: { amount: 0.001, unit: 'asset' } },
{ pair: ['AUD', 'XRP'], minimalOrder: { amount: 0.001, unit: 'asset' } },
{ pair: ['BTC', 'LTC'], minimalOrder: { amount: 0.001, unit: 'asset' } },
{ pair: ['BTC', 'ETH'], minimalOrder: { amount: 0.001, unit: 'asset' } },
{ pair: ['BTC', 'ETC'], minimalOrder: { amount: 0.001, unit: 'asset' } }
{ pair: ['BTC', 'ETC'], minimalOrder: { amount: 0.001, unit: 'asset' } },
{ pair: ['BTC', 'BCH'], minimalOrder: { amount: 0.001, unit: 'asset' } },
{ pair: ['BTC', 'XRP'], minimalOrder: { amount: 0.001, unit: 'asset' } }
],
requires: ['key', 'secret'],
providesHistory: false,
tid: 'tid'
tid: 'tid',
providesHistory: 'scan',
providesFullHistory: false,
tradable: true
};
}

Expand Down
Loading