UNPKG

4.08 kBJavaScriptView Raw
1throw 'This version is not up to date, download it on github instead!\n\nhttps://github.com/askmike/gekko'
2
3/*
4
5 Gekko is a Bitcoin trading bot for Mt. Gox written
6 in node, it features multiple trading methods using
7 technical analysis.
8
9 Disclaimer:
10
11 USE AT YOUR OWN RISK!
12
13 The authors of this project is NOT responsible for any damage or loss caused
14 by this software. There can be bugs and the bot may not perform as expected
15 or specified. Please consider testing it first without automatic buying /
16 selling in the provided advice. Also look at the code to see what how
17 it's working.
18
19*/
20
21// helpers
22var moment = require('moment');
23var _ = require('underscore');
24var util = require('./util.js');
25var log = require('./log.js');
26var async = require('async');
27var Manager = require('./portfolioManager');
28
29var config = util.getConfig();
30var Consultant = require('./methods/' + config.tradingMethod.toLowerCase().split(' ').join('-'));
31
32log.info('I\'m gonna make you rich, Bud Fox.');
33log.info('Let me show you some ' + config.tradingMethod + '.\n\n');
34
35if(config.backtest.enabled) {
36 log.info('Preparing backtester to test strategy against historical data.');
37
38 // implement a trading method to create a consultant.
39 var consultant = new Consultant();
40
41 // overwrite the watcher in case of normal setup
42 if(config.normal.enabled)
43 config.watch = config.normal;
44
45 var Logger = require('./logger');
46 var logger = new Logger(_.extend(config.profitCalculator, config.watch));
47 consultant.on('advice', logger.inform);
48 if(config.profitCalculator.enabled)
49 consultant.on('advice', logger.trackProfits);
50
51 consultant.on('finish', logger.finish);
52
53 consultant.emit('prepare');
54 return;
55}
56
57
58//
59// Normalize the configuration between normal & advanced
60//
61if(config.normal && config.normal.enabled) {
62 // if the normal settings are enabled we overwrite the
63 // watcher and traders set in the advanced zone
64 log.info('Using normal settings to monitor the live market');
65 config.watch = config.normal;
66 config.traders = [];
67
68 var checker = new Manager(config.normal, true);
69 var valid = checker.validCredentials();
70 if(config.normal.tradingEnabled && valid)
71 config.traders.push( config.normal );
72 else
73 log.info('NOT trading with real money');
74} else {
75 log.info('Using advanced settings');
76}
77
78//
79// create a public exchange object which can retrieve live trade information
80//
81var provider = config.watch.exchange.toLowerCase();
82if(provider === 'btce') {
83 // we can't fetch historical data from btce directly so we use bitcoincharts
84 // @link http://bitcoincharts.com/about/markets-api/
85 config.watch.market = provider;
86 provider = 'bitcoincharts';
87}
88var DataProvider = require('./exchanges/' + provider);
89var watcher = new DataProvider(config.watch);
90
91// implement a trading method to create a consultant, we pass it a config and a
92// public mtgox object which the method can use to get data on past trades
93var consultant = new Consultant(watcher);
94
95// log advice
96var Logger = require('./logger');
97var logger = new Logger(_.extend(config.profitCalculator, config.watch));
98consultant.on('advice', logger.inform);
99if(config.profitCalculator.enabled)
100 consultant.on('advice', logger.trackProfits);
101
102//
103// Configure automatic traders based on advice
104//
105var managers = _.filter(config.traders, function(t) { return t.enabled });
106var configureManagers = function(_next) {
107 var next = _.after(managers.length, _next);
108 _.each(managers, function(conf) {
109 conf.exchange = conf.exchange.toLowerCase();
110
111 var manager = new Manager(conf);
112 consultant.on('advice', manager.trade);
113 manager.on('ready', next);
114 });
115}
116
117
118//
119// Configure automatic email on advice
120//
121var configureMail = function(next) {
122 if(config.mail.enabled && config.mail.email) {
123 var mailer = require('./mailer');
124 mailer.init(function() {
125 consultant.on('advice', mailer.send);
126 next();
127 });
128 } else
129 next();
130}
131
132var start = function() {
133 consultant.emit('prepare');
134}
135
136async.series([configureMail, configureManagers], start);
\No newline at end of file