forked from askmike/gekko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exchangeChecker.js
68 lines (50 loc) · 1.96 KB
/
exchangeChecker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
var exchanges = require('./exchanges.js');
var _ = require('lodash');
var Checker = function() {
_.bindAll();
}
Checker.prototype.notValid = function(conf) {
if(conf.tradingEnabled)
return this.cantTrade(conf);
else
return this.cantMonitor(conf);
}
// check if the exchange is configured correctly for monitoring
Checker.prototype.cantMonitor = function(conf) {
var slug = conf.exchange.toLowerCase();
var exchange = _.find(exchanges, function(e) { return e.slug === slug });
if(!exchange)
return 'Gekko does not support the exchange ' + slug;
var name = exchange.name;
if('monitorError' in exchange)
return 'At this moment Gekko can\'t monitor ' + name + ', find out more info here:\n\n' + exchange.monitorError;
var name = exchange.name;
if(!_.contains(exchange.currencies, conf.currency))
return 'Gekko only supports the currencies [ ' + exchange.currencies.join(', ') + ' ] at ' + name;
if(!_.contains(exchange.assets, conf.asset))
return 'Gekko only supports the assets [ ' + exchange.assets.join(', ') + ' ] at ' + name;
// everyting okay
return false;
}
// check if the exchange if configured correctly for real trading
Checker.prototype.cantTrade = function(conf) {
var cantMonitor = this.cantMonitor(conf);
if(cantMonitor)
return cantMonitor;
var slug = conf.exchange.toLowerCase();
var exchange = _.find(exchanges, function(e) { return e.slug === slug });
var name = exchange.name;
if('tradeError' in exchange)
return 'At this moment Gekko can\'t trade at ' + name + ', find out more info here:\n\n' + exchange.tradeError;
if(conf.key === 'your-key')
throw '"your-key" is not a valid API key';
if(conf.secret === 'your-secret')
throw '"your-secret" is not a valid API secret';
var error = false;
_.each(exchange.requires, function(req) {
if(!conf[req])
error = name + ' requires "' + req + '" to be set in the config';
}, this);
return error;
}
module.exports = new Checker();