Skip to content

Commit

Permalink
all configurables are stored in config.js now
Browse files Browse the repository at this point in the history
  • Loading branch information
askmike committed May 19, 2013
1 parent 5bcebbf commit 5a7eab2
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 41 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,4 @@ dwsync.xml

# Folders to ignore

node_modules
config.js
node_modules
45 changes: 45 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
var config = {};

// Gekko currently only supports Exponential Moving Averages
config.tradingMethod = 'Exponential Moving Averages';

// Exponential Moving Averages settings:
config.tradeConfig = {
// timeframe per candle
interval: 60, // in minutes
// EMA weight (α)
// the higher the weight, the more smooth (and delayed) the line
shortEMA: 10,
longEMA: 21,
// amount of samples to remember and base initial EMAs on
candles: 100,
// max difference between first and last trade to base price calculation on
sampleSize: 10, // in seconds
// the difference between the EMAs (to act as triggers)
sellTreshold: -0.25,
buyTreshold: 0.25
};

config.debug = false // for additional logging

// DANGER ZONE
//
// enable real trading BTC for real USD
//
// fill in you public and private key from mtgox / btc-e and uncomment to enable
/*
config.traders = [
{
exchange: 'MtGox', // either 'BTCe' or 'MtGox'
key: '',
secret: ''
},
// {
// exchange: 'BTCe', // either 'BTCe' or 'MtGox'
// key: '',
// secret: ''
// }
];
*/

module.exports = config;
1 change: 0 additions & 1 deletion exchanges/btce.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ var trader = function(key, secret) {
_.bindAll(this);

this.btce = new BTCE(this.key, this.secret);
console.log(util.now(), 'initialized ' + this.name + ' trader');
}

trader.prototype.trade = function(what) {
Expand Down
1 change: 0 additions & 1 deletion exchanges/mtgox.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ var trader = function(key, secret) {
this.name = 'Mt. Gox';

this.mtgox = new MtGoxClient(this.key, this.secret);
console.log(util.now(), 'initialized ' + this.name + ' trader');
}

trader.prototype.trade = function(what) {
Expand Down
51 changes: 16 additions & 35 deletions gekko.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,8 @@
it's working.
*/
var tradingMethod = 'Exponential Moving Averages';
var tradeConfig = {
// timeframe per candle
interval: 1, // in minutes
// EMA weight (α)
// the higher the weight, the more smooth (and delayed) the line
shortEMA: 10,
longEMA: 21,
// amount of samples to remember and base initial EMAs on
candles: 100,
// max difference between first and last trade to base price calculation on
sampleSize: 10, // in seconds
// the difference between the EMAs (to act as triggers)
sellTreshold: -0.025,
buyTreshold: 0.025,
debug: true // for additional logging
};

var config = require('./config.js');

// helpers
var moment = require('moment');
Expand All @@ -40,7 +25,7 @@ var util = require('./util.js');

console.log('\nstart time: ', util.now());
console.log('\nI\'m gonna make you rich, Bud Fox.');
console.log('Let me show you some ' + tradingMethod + '.\n');
console.log('Let me show you some ' + config.tradingMethod + '.\n');

var MtGoxClient = require("mtgox-apiv2");
// create a public mtgox object which can retrieve
Expand All @@ -49,28 +34,24 @@ var publicMtgox = new MtGoxClient('~', '~');

// implement a trading method to create a consultant, we pass it a config and a
// public mtgox object which the method can use to get data on past trades
var consultant = require('./methods/' + tradingMethod.toLowerCase().split(' ').join('-') + '.js');
consultant.emit('init', tradeConfig, publicMtgox);
var consultant = require('./methods/' + config.tradingMethod.toLowerCase().split(' ').join('-') + '.js');
consultant.emit('init', config.tradeConfig, publicMtgox, config.debug);

// whenever the consultant advices to sell or buy we can act on the information

var logger = require('./logger.js');
consultant.on('advice', logger.inform);
consultant.on('advice', logger.trackProfits);

// DANGER ZONE
//
// enable real trading BTC for real USD
//
// fill in you public and private key from mtgox and uncomment to enable
var exchanges = ['MtGox', 'BTCe'];

_.each(config.traders, function(conf) {
if(_.indexOf(exchanges, conf.exchange) === -1)
throw 'unkown exchange';

console.log(util.now(), 'real trading at', conf.exchange, 'ACTIVE');
var Trader = require('./exchanges/' + conf.exchange.toLowerCase() + '.js');
var trader = new Trader(conf.key, conf.secret);
consultant.on('advice', trader.trade);
});

/*
console.log(util.now(), 'real trading ACTIVE');
var exchange = 'BTCe'; // either 'BTCe' or 'MtGox'
var key = 'your API key';
var secret = 'your API secret';
// implement a trader for an exchange which will act (buy or sell) on the advice
var Trader = require('./exchanges/' + exchange.toLowerCase() + '.js');
var trader = new Trader(key, secret);
consultant.on('advice', trader.trade);
*/
6 changes: 4 additions & 2 deletions methods/exponential-moving-averages.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ var mtgox, config, currentTrend;
// this array stores _all_ price data
var candles = [];

var debug;
var log = function(m) {
config.debug && console.log('(DEBUG) ', util.now(), m);
debug && console.log('(DEBUG) ', util.now(), m);
}

// fetch the price of all remaining candles and calculate
Expand Down Expand Up @@ -192,9 +193,10 @@ var refresh = function() {
getCandles(advice);
}

var init = function(c, m) {
var init = function(c, m, d) {
config = c;
mtgox = m;
debug = d;
util.set(c);

getCandles(advice);
Expand Down

0 comments on commit 5a7eab2

Please sign in to comment.