Skip to content

Commit

Permalink
Accidentally only included the launcher on previous commit (oops)
Browse files Browse the repository at this point in the history
1) Added several lines of code related to bugs with inconsistent
formatting / display / logging of information, and made the verbose
"debug" logging less... just less (much of information is now in
the default level without needing to enabled debug logging)... Also
changed the grammar on various things to prevent linewrapping
from too much words, or simple cleanups to make 8 decimal places be
usd correctly (in addition to fixing a few rounding errors)

2) Hardcoded a trading fee for cex.io platform, as it now has one (this
value doesn't seem to have a way to fetch via API, so I guess it can be
configurable in the future. The config parser needs an audit though, so
the workaround was to simply hardcode a non-zero fee)

3) Removed the "sell when price is high" logic. This fork of gekkobot is
for reinvestment of the income from cloud mining. Period. Full stop.
  • Loading branch information
Sarah White committed Jun 25, 2014
1 parent 50d8802 commit 514cc1e
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 114 deletions.
57 changes: 29 additions & 28 deletions config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Everything is explained here:
// https://github.com/askmike/gekko/blob/master/docs/Configuring_gekko.md
// Everything is explained here:
// https://github.com/kuzetsa/gekko/blob/master/docs/Configuring_gekko.md

var config = {};

Expand All @@ -13,7 +13,7 @@ config.history = {
// and load historical data from?
directory: './history/'
}
config.debug = true; // for additional logging / debugging
config.debug = false; // for additional logging / debugging

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// WATCHING A MARKET
Expand All @@ -22,9 +22,9 @@ config.debug = true; // for additional logging / debugging
// Monitor the live market
config.watch = {
enabled: true,
exchange: 'Bitstamp', // 'MtGox', 'BTCe', 'Bitstamp', 'cexio' or 'kraken'
currency: 'USD',
asset: 'BTC'
exchange: 'cexio', // 'MtGox', 'BTCe', 'Bitstamp', 'cexio' or 'kraken'
currency: 'BTC',
asset: 'GHS'
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -33,9 +33,9 @@ config.watch = {

config.tradingAdvisor = {
enabled: true,
method: 'DEMA',
candleSize: 60,
historySize: 50
method: 'MACD',
candleSize: 1,
historySize: 113
}

// Exponential Moving Averages settings:
Expand All @@ -56,13 +56,13 @@ config.DEMA = {
config.MACD = {
// EMA weight (α)
// the higher the weight, the more smooth (and delayed) the line
short: 10,
long: 21,
signal: 9,
short: 53,
long: 109,
signal: 41,
// the difference between the EMAs (to act as triggers)
thresholds: {
down: -0.025,
up: 0.025,
down: -9999,
up: 0.00000001,
// How many candle intervals should a trend persist
// before we consider it real?
persistence: 1
Expand All @@ -78,8 +78,8 @@ config.PPO = {
signal: 9,
// the difference between the EMAs (to act as triggers)
thresholds: {
down: -0.025,
up: 0.025,
down: -9999,
up: 0.00000001,
// How many candle intervals should a trend persist
// before we consider it real?
persistence: 2
Expand Down Expand Up @@ -112,9 +112,9 @@ config.custom = {
// watched by config.watch
config.trader = {
enabled: false,
key: '',
secret: '',
username: '' // your username, only fill in when using bitstamp or cexio
key: 'see next line',
secret: 'some sort of hash goes here',
username: 'fakename change this', // your username, as required by cexio
}

config.adviceLogger = {
Expand All @@ -123,7 +123,7 @@ config.adviceLogger = {

// do you want Gekko to calculate the profit of its own advice?
config.profitSimulator = {
enabled: true,
enabled: false,
// report the profit in the currency or the asset?
reportInCurrency: true,
// start balance, on what the current balance is compared with
Expand All @@ -133,11 +133,11 @@ config.profitSimulator = {
currency: 100,
},
// only want report after a sell? set to `false`.
verbose: false,
verbose: true,
// how much fee in % does each trade cost?
fee: 0.6,
fee: 1,
// how much slippage should Gekko assume per trade?
slippage: 0.05
slippage: 0.5
}

// want Gekko to send a mail on buy or sell advice?
Expand All @@ -150,7 +150,7 @@ config.mailer = {
// You don't have to set your password here, if you leave it blank we will ask it
// when Gekko's starts.
//
// NOTE: Gekko is an open source project < https://github.com/askmike/gekko >,
// NOTE: Gekko is an open source project < https://github.com/kuzetsa/gekko >,
// make sure you looked at the code or trust the maintainer of this bot when you
// fill in your email and password.
//
Expand Down Expand Up @@ -209,7 +209,8 @@ config.redisBeacon = {
]
}

// not in a working state
// the web interface not currently supported, maintainer of the plugin quit
// (not in a working state)
// read: https://github.com/askmike/gekko/issues/156
config.webserver = {
enabled: false,
Expand Down Expand Up @@ -238,7 +239,7 @@ config.backtest = {
// it doesn't advice on itself, only set to true if you truly
// understand this.
//
// Not sure? Read this first: https://github.com/askmike/gekko/issues/201
config['I understand that Gekko only automates MY OWN trading strategies'] = false;
config['I understand that Gekko only automates MY OWN trading
strategies'] = false;

module.exports = config;
module.exports = config;
7 changes: 4 additions & 3 deletions core/baseTradingMethod.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ var Base = function() {
else
log.warn('\t', 'Warning, trading method has no name');

if(!config.debug || !this.log)
this.log = function() {};
// if(!config.debug || !this.log)
// DO NOT nuke the log for MACD logging, let line-by-line tweaks happen
// this.log = function() {};

this.setup = true;
}
Expand Down Expand Up @@ -115,4 +116,4 @@ Base.prototype.advice = function(newPosition) {
});
}

module.exports = Base;
module.exports = Base;
2 changes: 1 addition & 1 deletion core/candleManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ Manager.prototype.processTrades = function(data) {
return this.emit('processed');
}

log.debug('processing', _.size(trades), 'trade(s)');
log.info('processing', _.size(trades), 'trade(s)');
log.debug(
'from',
moment.unix(_.first(trades).date).utc().format(),
Expand Down
62 changes: 44 additions & 18 deletions core/portfolioManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ var Manager = function(conf) {
var Exchange = require('../exchanges/' + this.exchangeSlug);
this.exchange = new Exchange(conf);

this.limiter = (new Date()).getTime();

this.conf = conf;
this.portfolio = {};
this.fee;
Expand Down Expand Up @@ -121,6 +123,16 @@ Manager.prototype.trade = function(what) {
if(what !== 'BUY' && what !== 'SELL')
return;


// is it time yet?
var rightnow = (new Date()).getTime();
if(rightnow <= this.limiter)
return;

// ok, so reset the limiter
this.limiter = (new Date()).getTime() + 9000;


this.action = what;

var act = function() {
Expand All @@ -131,8 +143,13 @@ Manager.prototype.trade = function(what) {
// do we need to specify the amount we want to buy?
if(this.infinityOrderExchange)
amount = 10000;
else
amount = this.getBalance(this.currency) / this.ticker.ask;
else {
amount = 1 - this.fee;
amount = (100000000 * amount * this.getBalance(this.currency)) - 2;
amount = Math.floor(Math.floor(amount) / this.ticker.ask) - 1;
amount = Math.max(0, amount);
amount /= 100000000;
}

// can we just create a MKT order?
if(this.directExchange)
Expand All @@ -142,6 +159,7 @@ Manager.prototype.trade = function(what) {

this.buy(amount, price);


} else if(what === 'SELL') {

// do we need to specify the amount we want to sell?
Expand All @@ -155,8 +173,10 @@ Manager.prototype.trade = function(what) {
price = false;
else
price = this.ticker.bid;

this.sell(amount, price);

// LIZARD!!!
// this.sell(amount, price);

}
};
async.series([
Expand All @@ -179,7 +199,7 @@ Manager.prototype.getMinimum = function(price) {
Manager.prototype.buy = function(amount, price) {
// sometimes cex.io specifies a price w/ > 8 decimals
price *= 100000000;
price = Math.floor(price);
price = Math.ceil(price);
price /= 100000000;

var currency = this.getFund(this.currency);
Expand All @@ -189,29 +209,29 @@ Manager.prototype.buy = function(amount, price) {
// if not suficient funds
if(amount > availabe) {
return log.info(
'Wanted to buy but insufficient',
'Insufficient',
this.currency,
'(' + availabe + ')',
'at',
'(' + availabe.toFixed(8) + ')',
'to BUY at',
this.exchange.name
);
}

// if order to small
if(amount < minimum) {
return log.info(
'Wanted to buy',
this.asset,
'but the amount is too small',
'(' + amount + ')',
'Ignore tiny',
'BUY order',
'(' + amount.toFixed(8) + ' ' + this.asset + ')',

'at',
this.exchange.name
);
}

log.info(
'Attempting too BUY',
amount,
'Placing BUY order for',
amount.toFixed(8),
this.asset,
'at',
this.exchange.name
Expand All @@ -225,7 +245,7 @@ Manager.prototype.buy = function(amount, price) {
Manager.prototype.sell = function(amount, price) {
// sometimes cex.io specifies a price w/ > 8 decimals
price *= 100000000;
price = Math.ceil(price);
price = Math.floor(price);
price /= 100000000;

var minimum = this.getMinimum(price);
Expand All @@ -236,7 +256,7 @@ Manager.prototype.sell = function(amount, price) {
return log.info(
'Wanted to buy but insufficient',
this.asset,
'(' + availabe + ')',
'(' + availabe.toFixed(8) + ')',
'at',
this.exchange.name
);
Expand All @@ -248,7 +268,7 @@ Manager.prototype.sell = function(amount, price) {
'Wanted to buy',
this.currency,
'but the amount is too small',
'(' + amount + ')',
'(' + amount.toFixed(8) + ')',
'at',
this.exchange.name
);
Expand Down Expand Up @@ -296,7 +316,7 @@ Manager.prototype.checkOrder = function() {
Manager.prototype.logPortfolio = function() {
log.info(this.exchange.name, 'portfolio:');
_.each(this.portfolio, function(fund) {
log.info('\t', fund.name + ':', fund.amount);
log.info('\t', fund.name + ':', fund.amount.toFixed(8));
});
}

Expand All @@ -312,6 +332,12 @@ Manager.prototype.recheckPortfolio = function() {
// the asset (GHS) as we are assuming the value
// of the asset will go up.
Manager.prototype.enforcePosition = function() {

log.info('refreshed', this.exchange.name, 'portfolio:');
_.each(this.portfolio, function(fund) {
log.info('\t', fund.name + ':', fund.amount.toFixed(8));
});

if(this.action !== 'BUY')
return;

Expand Down
4 changes: 3 additions & 1 deletion exchanges.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ var exchanges = [
assets: ['GHS'],
markets: [
{
pair: ['BTC', 'GHS'], minimalOrder: { amount: 0.000001, unit: 'currency' }
pair: ['BTC', 'GHS'], minimalOrder: { amount: 0.00161803,
unit:
'asset' }
}
],
requires: ['key', 'secret', 'username'],
Expand Down
2 changes: 1 addition & 1 deletion exchanges/cexio.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ Trader.prototype.getTicker = function(callback) {
Trader.prototype.getFee = function(callback) {
// cexio does currently don't take a fee on trades
// TODO: isn't there an API call for this?
callback(false, 0.0);
callback(false, 0.0075);
}

Trader.prototype.checkOrder = function(order, callback) {
Expand Down
Loading

1 comment on commit 514cc1e

@kuzetsa
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue #1 is closed as of this commit.

Please sign in to comment.